Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
7ce6819
add backend resources
teddy931130 Jan 15, 2025
6ff11ff
move state of backend resources to s3
teddy931130 Jan 15, 2025
8426b94
add infra dir layout + backend configs
teddy931130 Jan 15, 2025
0314b20
add OIDC provider
teddy931130 Jan 15, 2025
7076b61
create ECR repo + GHA IAM resources
teddy931130 Jan 15, 2025
8836ba2
add initial build workflow
teddy931130 Jan 15, 2025
c65dbb5
add condition for label 'CI:Build'
teddy931130 Jan 15, 2025
3247222
comment out CI check + refer to 'master'
teddy931130 Jan 15, 2025
c0b9aef
Merge pull request #1 from teddy931130/devops_task
teddy931130 Jan 15, 2025
8ae1b3f
temporarily comment merge condition
teddy931130 Jan 15, 2025
a500839
fix ubuntu runner label
teddy931130 Jan 15, 2025
c040759
add GH_TOKEN env var
teddy931130 Jan 15, 2025
62820fe
add build step to the workflow
teddy931130 Jan 15, 2025
4cba330
add docker-login shortcut to Makefile
teddy931130 Jan 15, 2025
ee95932
add short commit hash for COMMIT build arg
teddy931130 Jan 15, 2025
98725d3
proper boolean condition for tag creation
teddy931130 Jan 15, 2025
576caa3
Merge pull request #2 from teddy931130/devops_task
teddy931130 Jan 15, 2025
103d450
add docker-compose for local devnet
teddy931130 Jan 15, 2025
8ecf574
Markdown linting changes for README.md
teddy931130 Jan 15, 2025
a342d3c
remove managed volume + mount datadir for geth data
teddy931130 Jan 15, 2025
7850828
add a healthcheck and resource limits
teddy931130 Jan 15, 2025
ab3f41a
Merge pull request #3 from teddy931130/devops_task
teddy931130 Jan 15, 2025
a108674
Test PR with 'CI: Build' label (#4)
teddy931130 Jan 16, 2025
63b1c98
check only merged PRs (#5)
teddy931130 Jan 16, 2025
171ef6e
Use github-script for PR message (#6)
teddy931130 Jan 16, 2025
e1b2eba
fix github-script (#7)
teddy931130 Jan 16, 2025
565309f
cleanup (#8)
teddy931130 Jan 16, 2025
7a68d83
add sample hardhat project
teddy931130 Jan 16, 2025
e12100a
add initial build-deploy workflow
teddy931130 Jan 16, 2025
e435aa3
implement go packages cache
teddy931130 Jan 18, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions .github/workflows/build-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
name: Builds and pushes go-ethereum:hardhat Docker image to ECR

on:
# keep for manual trigger if needed
workflow_dispatch:
inputs:
create_tag:
description: "Create and push a new tag?"
required: false
type: boolean
pull_request:
branches: [master]
types:
- closed

env:
AWS_ACCOUNT_ID: "861276097334"
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
contents: write
pull-requests: write

jobs:
build-and-push:
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Deploy'))
runs-on: ubuntu-22.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name }}

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.IAM_OIDC_ROLE_NAME }}
role-session-name: go-ethereum-github-actions

- name: Login to Amazon ECR
id: login-ecr
run: |
FULL_ECR_URL=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
aws ecr get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin ${FULL_ECR_URL}

- name: Get latest image tag
id: get-latest-tag
run: |
LATEST_TAG=$(aws ecr describe-images \
--repository-name ${{ env.ECR_REPO_NAME }} \
--region ${{ env.AWS_REGION }} \
--query "sort_by(imageDetails[?contains(imageTags[0], 'hardhat')], &imagePushedAt)[-1].imageTags[0]" \
--output text)
if [[ "$LATEST_TAG" == "None" ]]; then
NEW_TAG=hardhat-1
else
# Get only the number part from the latest hardhat tag
LAST_NUMBER=$(echo "$LATEST_TAG" | grep -oE '[0-9]+$')

# Increment the number and build the new tag
NEW_NUMBER=$((LAST_NUMBER + 1))
NEW_TAG="hardhat-${NEW_NUMBER}"
fi
fi
echo "new-tag=${NEW_TAG}" >> $GITHUB_OUTPUT
122 changes: 122 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
name: Build and Push go-ethereum Docker image to ECR

on:
# keep for manual trigger if needed
workflow_dispatch:
inputs:
create_tag:
description: "Create and push a new tag?"
required: false
type: boolean
pull_request:
branches: [master]
types:
- closed

env:
AWS_ACCOUNT_ID: "861276097334"
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
contents: write
pull-requests: write

jobs:
build-and-push:
if: >
github.event_name == 'workflow_dispatch' ||
(github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build'))
runs-on: ubuntu-22.04
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
ref: ${{ github.ref_name }}

### Need to be careful with 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
- name: Cache go.mod packages
uses: actions/setup-go@v5
with:
go-version-file: "go.mod"

- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ env.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ env.AWS_ACCOUNT_ID }}:role/${{ env.IAM_OIDC_ROLE_NAME }}
role-session-name: go-ethereum-github-actions

- name: Login to Amazon ECR
id: login-ecr
run: |
FULL_ECR_URL=${{ env.AWS_ACCOUNT_ID }}.dkr.ecr.${{ env.AWS_REGION }}.amazonaws.com
aws ecr get-login-password --region ${{ env.AWS_REGION }} | docker login --username AWS --password-stdin ${FULL_ECR_URL}

- name: Get latest image tag
id: get-latest-tag
run: |
LATEST_TAG=$(aws ecr describe-images \
--repository-name ${{ env.ECR_REPO_NAME }} \
--region ${{ env.AWS_REGION }} \
--query 'sort_by(imageDetails,&imagePushedAt)[-1].imageTags[0]' \
--output text)
if [[ "$LATEST_TAG" == "None" ]]; then
NEW_TAG=1
else
NEW_TAG=$((LATEST_TAG + 1))
fi
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=${COMMIT:0:7}
VERSION=$NEW_TAG
BUILDNUM=$(git rev-list --count HEAD)

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: Create a new tag
if: >
inputs.create_tag == true ||
(github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build'))
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"

NEW_TAG=v${{ steps.get-latest-tag.outputs.new-tag }}
git tag -a $NEW_TAG -m "New tag: $NEW_TAG"
git push origin $NEW_TAG

- name: Add a release comment in PR
if: >
inputs.create_tag == true ||
(github.event.pull_request.merged == true && contains(github.event.pull_request.labels.*.name, 'CI:Build'))
uses: actions/github-script@v7
id: my-script
with:
script: |
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: ':rocket: A new tag v${{ steps.get-latest-tag.outputs.new-tag }} has been created and pushed!'
})
8 changes: 4 additions & 4 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
name: i386 linux tests

on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
# push:
# branches: [ master ]
# pull_request:
# branches: [ master ]
workflow_dispatch:

jobs:
Expand Down
7 changes: 7 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,10 @@ profile.cov
.vscode

tests/spec-tests/

.terraform
terraform.tfstate*
.terraform.tfstate.lock.info

.env
geth-data/
6 changes: 5 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ''
Expand Down
Loading