Draft CI and lint workflow #1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD Workflow | |
on: | |
push: | |
branches: | |
- main | |
paths: | |
- '**.yaml' | |
- '**/Dockerfile' | |
- '**/charts/**' | |
tags: | |
- 'v*' | |
pull_request: {} | |
env: | |
IMAGE_NGINX_CACHE: nginx-cache | |
#REGISTRY: ghcr.io/${{ github.repository_owner }} | |
PUSH: 1 | |
LOAD: 1 | |
NGINX_CACHE_TAG: v0.1.0 | |
TAG: v0.3.1 | |
PLATFORM_ARCH: linux/amd64 | |
jobs: | |
build-and-push: | |
name: Build Cozystack | |
runs-on: ubuntu-latest | |
services: | |
registry: | |
image: registry:2 | |
ports: | |
- 5000:5000 | |
steps: | |
- name: Set up Docker Registry | |
run: | | |
if [ "$GITHUB_ACTIONS" = "true" ]; then | |
echo "REGISTRY=ghcr.io/${{ github.repository_owner }}" >> $GITHUB_ENV | |
else | |
echo "REGISTRY=localhost:5000/cozystack_local" >> $GITHUB_ENV | |
fi | |
- uses: actions/checkout@v3 | |
- name: Build Docker image | |
run: | | |
cd packages/apps/http-cache | |
docker buildx build --platform ${PLATFORM_ARCH} --build-arg ARCH=amd64 images/${IMAGE_NGINX_CACHE} --provenance false \ | |
--tag ${REGISTRY}/${IMAGE_NGINX_CACHE}:${NGINX_CACHE_TAG} \ | |
--tag ${REGISTRY}/${IMAGE_NGINX_CACHE}:${NGINX_CACHE_TAG}-${TAG} \ | |
--cache-from type=registry,ref=${REGISTRY}/${IMAGE_NGINX_CACHE}:${NGINX_CACHE_TAG} \ | |
--cache-to type=inline --metadata-file images/nginx-cache.json --push=${PUSH} --load=${LOAD} | |
echo "${REGISTRY}/${IMAGE_NGINX_CACHE}:${NGINX_CACHE_TAG}" > images/nginx-cache.tag | |
docker tag $REGISTRY/${IMAGE_NGINX_CACHE}:${{ github.sha }} $REGISTRY/$IMAGE_NAME:latest | |
- name: Log in to Docker Registry | |
run: echo ${{ secrets.REGISTRY_PASSWORD }} | docker login $DOCKER_REGISTRY --username ${{ secrets.REGISTRY_USERNAME }} --password-stdin | |
- name: Push Docker images | |
run: | | |
docker push $REGISTRY/${IMAGE_NGINX_CACHE}:${{ github.sha }} | |
docker push $REGISTRY/${IMAGE_NGINX_CACHE}:latest | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
deploy: | |
needs: build-and-push | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/v') | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Configure kubectl | |
uses: azure/setup-kubectl@v2 | |
- name: Set up Helm | |
uses: azure/setup-helm@v2 | |
- name: Add Helm repo | |
run: helm repo add myrepo https://example.com/helm | |
- name: Deploy Helm chart | |
run: | | |
helm upgrade --install myrelease myrepo/mychart --namespace default --set image.tag=${{ github.sha }} | |