From ba4f794d19745ef35a4240d1c342940d95c22978 Mon Sep 17 00:00:00 2001 From: Marian Koreniuk Date: Thu, 25 Apr 2024 21:17:31 +0300 Subject: [PATCH] Draft CI and lint workflow --- .github/workflows/ci.yml | 80 +++++++++++++++++++++++++ .github/workflows/config/.yaml-lint.yml | 34 +++++++++++ .github/workflows/lint.yml | 44 ++++++++++++++ 3 files changed, 158 insertions(+) create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/config/.yaml-lint.yml create mode 100644 .github/workflows/lint.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 000000000..b801bfa29 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,80 @@ +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 }} + diff --git a/.github/workflows/config/.yaml-lint.yml b/.github/workflows/config/.yaml-lint.yml new file mode 100644 index 000000000..9575e86f5 --- /dev/null +++ b/.github/workflows/config/.yaml-lint.yml @@ -0,0 +1,34 @@ + +yaml-files: +- '*.yaml' +- '*.yml' +- '.yamllint' + +rules: + anchors: enable + braces: enable + brackets: enable + colons: enable + commas: enable + comments: + level: warning + comments-indentation: + level: warning + document-end: disable + document-start: + level: warning + empty-lines: enable + empty-values: disable + float-values: disable + hyphens: enable + indentation: enable + key-duplicates: enable + key-ordering: disable + line-length: enable + new-line-at-end-of-file: enable + new-lines: enable + octal-values: disable + quoted-strings: disable + trailing-spaces: enable + truthy: + level: warning diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 000000000..3d00d606c --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,44 @@ +name: Lint + +on: # yamllint disable-line rule:truthy + push: null + pull_request: null + +permissions: {} + +env: + GIT_DISCOVERY_ACROSS_FILESYSTEM: 1 + FILTER_REGEX_EXCLUDE: \.git/.* + +jobs: + build: + name: Lint + runs-on: ubuntu-latest + + permissions: + contents: read + packages: read + # To report GitHub Actions status checks + statuses: write + + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + # super-linter needs the full git history to get the + # list of files that changed across commits + fetch-depth: 0 + + - name: Super-linter + uses: super-linter/super-linter/slim@latest # x-release-please-version + env: + LINTER_RULES_PATH: '.' + VALIDATE_ALL_CODEBASE: true + VALIDATE_JAVASCRIPT_ES: false + VALIDATE_PYTHON_BLACK: false + VALIDATE_HTML: false + VALIDATE_GO: false + VALIDATE_XML: false + VALIDATE_JAVA: false + # To report GitHub Actions status checks + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}