diff --git a/.github/workflows/cicd-prd.yml b/.github/workflows/cicd-prd.yml new file mode 100644 index 000000000..106c21f32 --- /dev/null +++ b/.github/workflows/cicd-prd.yml @@ -0,0 +1,77 @@ +name: "CICD" + +on: + # Test run before merging + pull_request: + branches: + - main + # On merged + push: + branches: + - main + # On released + release: + types: [created] + +jobs: + build-docker: + permissions: + id-token: write + contents: write + runs-on: ubuntu-22.04 + if: ${{ github.actor != 'dependabot[bot]' }} + name: "Build and push images" + strategy: + fail-fast: false + matrix: + application: [eth-spout] + include: + - application: eth-spout + docker_domain: asia-docker.pkg.dev + registry_prd: asia-docker.pkg.dev/prj-d-devops-services-4dgwlsse/zilliqa-public + image_name: eth-spout + path: products/eth-spout + env: + DEFAULT_BRANCH: main + steps: + - name: Checkout code + uses: actions/checkout@v3 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{ github.event.pull_request.head.repo.full_name }} + fetch-depth: 0 + + - name: "Authenticate to Google Cloud - prod" + if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release' + id: google-auth + uses: "google-github-actions/auth@v1" + with: + token_format: "access_token" + workload_identity_provider: "${{ secrets.GCP_PRD_GITHUB_WIF }}" + service_account: "${{ secrets.GCP_PRD_GITHUB_SA_DOCKER_REGISTRY }}" + create_credentials_file: true + + - name: Login to the registry - prod + if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release' + uses: docker/login-action@v2 + with: + registry: ${{ matrix.docker_domain }} + username: "oauth2accesstoken" + password: "${{ steps.google-auth.outputs.access_token }}" + + - name: Get tag version - prod + if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release' + id: set-tag + uses: Zilliqa/gh-actions-workflows/actions/generate-tag@v1 + with: + tag: ${{ matrix.registry_prd }}/${{ matrix.image_name }} + length: 8 + + - name: "Build and push ${{ matrix.application }} - prod" + if: github.ref_name == env.DEFAULT_BRANCH && github.event_name != 'release' + env: + ENVIRONMENT: stg + IMAGE_TAG: ${{ steps.set-tag.outputs.tags }} + run: | + cd ${{ matrix.path }} + make image/build-and-push diff --git a/.github/workflows/eth-spout.yaml b/.github/workflows/eth-spout.yaml deleted file mode 100644 index 365172e71..000000000 --- a/.github/workflows/eth-spout.yaml +++ /dev/null @@ -1,71 +0,0 @@ -name: Publish Docker image for eth-spout - -on: - push: - branches: - - "main" - paths: - - "products/eth-spout/**" - tags: - - "*" - workflow_dispatch: - -jobs: - push_to_registry: - name: Push Docker image to Docker Hub - runs-on: ubuntu-latest - permissions: - contents: read - packages: write - - steps: - - name: Checkout - uses: actions/checkout@v3 - with: - submodules: recursive - - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- - - - name: Docker Setup Buildx - uses: docker/setup-buildx-action@v2 - with: - driver: docker-container - driver-opts: | - image=moby/buildkit:master - - - name: Docker Login - uses: docker/login-action@v2 - with: - username: ${{ secrets.DOCKERHUB_USERNAME }} - password: ${{ secrets.DOCKERHUB_PASSWORD }} - - - name: Docker Metadata action - id: meta - uses: docker/metadata-action@v4 - with: - images: | - zilliqa/eth-spout - - - name: Build and push Docker images - uses: docker/build-push-action@v3 - with: - context: products/eth-spout - push: true - tags: ${{ steps.meta.outputs.tags }} - labels: ${{ steps.meta.outputs.labels }} - cache-from: type=local,src=/tmp/.buildx-cache - cache-to: type=local,dest=/tmp/.buildx-cache-new - - # Temp fix - # https://github.com/docker/build-push-action/issues/252 - # https://github.com/moby/buildkit/issues/1896 - - name: Move cache - run: | - rm -rf /tmp/.buildx-cache - mv /tmp/.buildx-cache-new /tmp/.buildx-cache diff --git a/products/eth-spout/Makefile b/products/eth-spout/Makefile new file mode 100644 index 000000000..0652d21f9 --- /dev/null +++ b/products/eth-spout/Makefile @@ -0,0 +1,13 @@ +.PHONY: all +all: image/build-and-push + +.ONESHELL: +SHELL := /bin/bash +.SHELLFLAGS = -ec + +IMAGE_TAG ?= localhost:5001/eth-spout:latest + +## Build and push the Docker image +image/build-and-push: + docker build -t "${IMAGE_TAG}" . + docker push "${IMAGE_TAG}"