From 501c8c14a1bfe35fc69cff3cb1562dc029e7efba Mon Sep 17 00:00:00 2001 From: Charlie C <9079356+charliecys@users.noreply.github.com> Date: Tue, 15 Nov 2022 16:51:24 +0800 Subject: [PATCH] ci: push image to ecr (#7) * feat: push image to ECR * fix: removed cache * ci: updated deprecated github actions output * ci: generate image tag with metadata action * ci: remove test branch in workflow * ci: remove unused output steps * ci: added missing id for step * ci: updated step names * ci: added cache * ci: added test branch for github actions * ci: added builder into github actions * ci: local cache for gh actions * ci: github workspace as cache * ci: removed _build cache * ci: run #2 * ci: removed translation key check * ci: removed test branch from gh actions Co-authored-by: charliecys --- .github/workflows/config.yml | 26 ----- .github/workflows/publish-docker-image.yml | 111 ++++++++++++++------- 2 files changed, 77 insertions(+), 60 deletions(-) diff --git a/.github/workflows/config.yml b/.github/workflows/config.yml index 5e1777e57d2e..ee2559a1cfae 100644 --- a/.github/workflows/config.yml +++ b/.github/workflows/config.yml @@ -166,32 +166,6 @@ jobs: - name: Run Dialyzer run: mix dialyzer --halt-exit-status - gettext: - name: Missing translation keys check - runs-on: ubuntu-18.04 - needs: build-and-cache - steps: - - uses: actions/checkout@v2 - - uses: erlef/setup-beam@v1 - with: - otp-version: ${{ env.OTP_VERSION }} - elixir-version: ${{ env.ELIXIR_VERSION }} - - - name: Restore Mix Deps Cache - uses: actions/cache@v2 - id: deps-cache - with: - path: | - deps - _build - key: ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-mixlockhash_12-${{ hashFiles('mix.lock') }} - restore-keys: | - ${{ runner.os }}-${{ env.ELIXIR_VERSION }}-${{ env.OTP_VERSION }}-${{ env.MIX_ENV }}-deps-" - - - run: | - mix gettext.extract --merge | tee stdout.txt - ! grep "Wrote " stdout.txt - working-directory: "apps/block_scout_web" sobelow: name: Sobelow security analysis runs-on: ubuntu-18.04 diff --git a/.github/workflows/publish-docker-image.yml b/.github/workflows/publish-docker-image.yml index d6591a66f246..aa12146ed986 100644 --- a/.github/workflows/publish-docker-image.yml +++ b/.github/workflows/publish-docker-image.yml @@ -3,48 +3,91 @@ # separate terms of service, privacy policy, and support # documentation. -name: Publish Docker image +name: Build and push to registry on: push: - branches: [master] + branches: + - master env: - REGISTRY_NAME: altregistry OTP_VERSION: '24.3.4.1' ELIXIR_VERSION: '1.13.4' + ECR_REGISTRY: 305587085711.dkr.ecr.us-west-2.amazonaws.com + ECR_REPOSITORY: blockscout jobs: - push_to_registry: - name: Push Docker image to Azure Container Registry + build-and-push-to-registry: + name: Push docker image to registry runs-on: ubuntu-latest - env: - RELEASE_VERSION: 4.1.5 + steps: - - name: Check out the repo - uses: actions/checkout@v3 - - - name: Set up QEMU - uses: docker/setup-qemu-action@v2 - - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 - - - name: Log in to Azure Container Registry - uses: docker/login-action@v2 - with: - registry: ${{ env.REGISTRY_NAME }}.azurecr.io - username: ${{ secrets.ALTREGISTRY_USERNAME }} - password: ${{ secrets.ALTREGISTRY_PASSWORD }} - - - name: Get short hash - run: echo "SHORT_SHA=`echo ${GITHUB_SHA} | cut -c 1-8`" >> $GITHUB_ENV - - - name: Extract metadata (tags, labels) for Docker - id: meta - uses: docker/metadata-action@v4 - with: - images: ${{ env.REGISTRY_NAME }}.azurecr.io/blockscout - - - name: Build & Push Docker image - run: docker buildx build -t ${{ env.REGISTRY_NAME }}.azurecr.io/blockscout:latest -t ${{ env.REGISTRY_NAME }}.azurecr.io/blockscout:${{ env.SHORT_SHA }} -f ./docker/Dockerfile --push --platform=linux/amd64 . \ No newline at end of file + - name: Check out the repo + uses: actions/checkout@v3 + + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + + - name: Set up Docker Buildx + id: docker-builder + uses: docker/setup-buildx-action@v2 + + - name: Log in to ECR + uses: docker/login-action@v2 + with: + registry: ${{ env.ECR_REGISTRY }} + username: ${{ secrets.ECR_ACCESS_KEY_ID }} + password: ${{ secrets.ECR_ACCESS_KEY }} + + - name: Cache Buildx + uses: actions/cache@v3 + id: buildx-cache + with: + # https://github.com/actions/cache/blob/main/examples.md#elixir---mix + path: | + ${{ github.workspace }}/deps + key: ${{ runner.os }}-mix-${{ hashFiles('**/mix.lock') }} + restore-keys: | + ${{ runner.os }}-mix- + + - name: Extract metadata (tags, labels) for Docker + id: meta + uses: docker/metadata-action@v4 + with: + images: | + ${{ env.ECR_REGISTRY }}/${{ env.ECR_REPOSITORY }} + tags: | + type=raw,value={{sha}} + type=raw,value={{branch}}-{{sha}} + type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'master') }} + + - name: Build and push Docker image + uses: docker/build-push-action@v3 + id: docker_build + with: + context: . + file: ./docker/Dockerfile + push: true + builder: ${{ steps.docker-builder.outputs.name }} + cache-from: | + type=local,src=${{ github.workspace }}/deps + cache-to: | + type=local,dest=${{ github.workspace }}/deps + tags: ${{ steps.meta.outputs.tags }} + build-args: | + CACHE_EXCHANGE_RATES_PERIOD= + DISABLE_READ_API=false + API_PATH= + NETWORK_PATH= + DISABLE_WEBAPP=false + DISABLE_WRITE_API=false + CACHE_ENABLE_TOTAL_GAS_USAGE_COUNTER= + WOBSERVER_ENABLED=false + ADMIN_PANEL_ENABLED=false + CACHE_ADDRESS_WITH_BALANCES_UPDATE_INTERVAL= + DISABLE_BRIDGE_MARKET_CAP_UPDATER=false + CACHE_BRIDGE_MARKET_CAP_UPDATE_INTERVAL= + SOCKET_ROOT= + + - name: Image digest + run: echo ${{ steps.docker_build.outputs.digest }}