From 8ae1b3fd2da88605e1e0bb18855a82beb67f48c5 Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 19:43:48 +0200 Subject: [PATCH 1/7] temporarily comment merge condition --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b5d26ae04a..892e5525fe 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -27,7 +27,7 @@ permissions: jobs: build-and-push: - if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build') + # if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build') runs-on: ubuntu:22.04 steps: From a500839144fd46f9fc41f40648cfe86d11c10bbf Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 19:46:36 +0200 Subject: [PATCH 2/7] fix ubuntu runner label --- .github/workflows/build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 892e5525fe..dcc2c6e938 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -28,7 +28,7 @@ permissions: jobs: build-and-push: # if: github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build') - runs-on: ubuntu:22.04 + runs-on: ubuntu-22.04 steps: - name: Checkout Code From c040759a162c6224ec50e08d0c4efa540ad386b7 Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 19:50:46 +0200 Subject: [PATCH 3/7] add GH_TOKEN env var --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dcc2c6e938..541d2dc53e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -19,6 +19,7 @@ env: AWS_REGION: "eu-central-1" ECR_REPO_NAME: "limechain-devops-task/go-ethereum" IAM_OIDC_ROLE_NAME: "go-ethereum-github-actions-role" + GH_TOKEN: ${{ github.token }} permissions: id-token: write From 62820feae53f5601a9e9c082b4c879d2b9362a05 Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 20:16:51 +0200 Subject: [PATCH 4/7] add build step to the workflow --- .github/workflows/build.yml | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 541d2dc53e..f1a9432a3f 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -66,17 +66,24 @@ jobs: fi echo "new-tag=${NEW_TAG}" >> $GITHUB_OUTPUT - # - name: Build and push Docker Image - # run: | - # FULL_ECR_URL="${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPO_NAME }}" - # NEW_TAG="${{ steps.get-latest-tag.outputs.new-tag }}" + - name: Build and push Docker Image + run: | + FULL_ECR_URL="${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPO_NAME }}" + NEW_TAG="${{ steps.get-latest-tag.outputs.new-tag }}" - # docker build \ - # --build-arg VAR="VALUE" \ - # -t "${FULL_ECR_URL}:${NEW_TAG}" \ - # -f Dockerfile . + # define build args for the image + COMMIT=${{ github.sha }} + VERSION=$NEW_TAG + BUILDNUM=$(git rev-list --count HEAD) - # docker push "${FULL_ECR_URL}:${NEW_TAG}" + docker build \ + --build-arg COMMIT="${COMMIT}" \ + --build-arg VERSION="${VERSION}" \ + --build-arg BUILDNUM="${BUILDNUM}" \ + -t "${FULL_ECR_URL}:${NEW_TAG}" \ + -f Dockerfile . + + docker push "${FULL_ECR_URL}:${NEW_TAG}" - name: Notify PR of New Tag if: ${{ inputs.create_tag }} == 'true' From 4cba330a7121beaff1bb08452ea5c611f7f618e2 Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 20:45:53 +0200 Subject: [PATCH 5/7] add docker-login shortcut to Makefile --- Makefile | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index f4932165a4..7f079b3359 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ # with Go source code. If you know what GOPATH is then you probably # don't need to bother with make. -.PHONY: geth all test lint fmt clean devtools help +.PHONY: geth all test lint fmt clean devtools docker-login help GOBIN = ./build/bin GO ?= latest @@ -47,6 +47,10 @@ devtools: @type "solc" 2> /dev/null || echo 'Please install solc' @type "protoc" 2> /dev/null || echo 'Please install protoc' +#? docker-login: Login to the ECR repo containing the go-ethereum image. +docker-login: + aws ecr get-login-password --region eu-central-1 | docker login --username AWS --password-stdin 861276097334.dkr.ecr.eu-central-1.amazonaws.com + #? help: Get more info on make commands. help: Makefile @echo '' From ee95932f7a4e5432c14c423048d367a74766e9b8 Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 20:55:53 +0200 Subject: [PATCH 6/7] add short commit hash for COMMIT build arg --- .github/workflows/build.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f1a9432a3f..962cc2c571 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -67,12 +67,14 @@ jobs: echo "new-tag=${NEW_TAG}" >> $GITHUB_OUTPUT - name: Build and push Docker Image + env: + COMMIT: ${{ github.sha }} run: | FULL_ECR_URL="${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com/${{ env.ECR_REPO_NAME }}" NEW_TAG="${{ steps.get-latest-tag.outputs.new-tag }}" # define build args for the image - COMMIT=${{ github.sha }} + COMMIT=${COMMIT:0:7} VERSION=$NEW_TAG BUILDNUM=$(git rev-list --count HEAD) From 98725d330c63ca678c7ecb9a43fbe832a1fba4dd Mon Sep 17 00:00:00 2001 From: teddy931130 Date: Wed, 15 Jan 2025 21:30:54 +0200 Subject: [PATCH 7/7] proper boolean condition for tag creation --- .github/workflows/build.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 962cc2c571..e4d70ddaa8 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -8,7 +8,6 @@ on: description: "Create and push a new tag?" required: false type: boolean - default: false pull_request: branches: [master] types: @@ -38,6 +37,12 @@ jobs: fetch-depth: 0 ref: ${{ github.ref_name }} + ### NOT using dependency caches, since using GitHub-hosted runners. More info at the URL below: + ### https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/caching-dependencies-to-speed-up-workflows#about-caching-workflow-dependencies + # - uses: actions/setup-go@v5 + # with: + # go-version-file: "go.mod" + - name: Configure AWS Credentials uses: aws-actions/configure-aws-credentials@v4 with: @@ -87,8 +92,8 @@ jobs: docker push "${FULL_ECR_URL}:${NEW_TAG}" - - name: Notify PR of New Tag - if: ${{ inputs.create_tag }} == 'true' + - name: Create new tag and notify PR + if: ${{ inputs.create_tag }} run: | git config user.name "github-actions[bot]" git config user.email "github-actions[bot]@users.noreply.github.com"