Build and Release Docker Image #41
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build and Release Docker Image | |
env: | |
DOCKER_REGISTRY: nethermind.jfrog.io | |
REPO_DEV: angkor-docker-local-dev | |
REPO_STAGING: angkor-docker-local-staging | |
REPO_PROD: angkor-docker-local-prod | |
on: | |
push: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
version: | |
type: choice | |
description: 'Environment to release to' | |
required: false | |
default: 'prod' | |
options: | |
- dev | |
- staging | |
- prod | |
permissions: | |
contents: write | |
id-token: write | |
jobs: | |
define_tag: | |
name: Define new Tag | |
runs-on: ubuntu-latest | |
outputs: | |
tag: ${{ steps.bump_version.outputs.new_version }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Get latest tag | |
id: get_latest_tag | |
run: | | |
latest_tag=$(git describe --tags --abbrev=0 2>/dev/null || echo "v1.0.0") | |
echo "latest_tag=${latest_tag}" >> $GITHUB_OUTPUT | |
- name: Validate semver | |
run: | | |
if ! [[ ${{ steps.get_latest_tag.outputs.latest_tag }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
echo "Latest tag does not follow semver standard" | |
exit 1 | |
fi | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install commitizen | |
run: pip install --upgrade commitizen | |
# For the first time, you have to run cz bump manually | |
- name: Bump version | |
id: bump_version | |
run: | | |
new_version=$(cz bump --dry-run --yes | grep 'tag to create:' | awk '{print $4}') | |
echo "new_version=${new_version}" >> $GITHUB_OUTPUT | |
- name: Print new version | |
run: | | |
echo "New version: ${{ steps.bump_version.outputs.new_version }}" | |
build_docker_image: | |
name: Build and push Docker Image | |
runs-on: ubuntu-latest | |
needs: define_tag | |
env: | |
VERSION: ${{ needs.define_tag.outputs.tag }} | |
APP_NAME: ${{ github.event.repository.name }} | |
steps: | |
- name: Set REPO environment variable | |
run: | | |
if [[ "${{ github.event.inputs.version }}" == "dev" ]]; then | |
echo "REPO=${{ env.REPO_DEV }}" >> $GITHUB_ENV | |
elif [[ "${{ github.event.inputs.version }}" == "staging" ]]; then | |
echo "REPO=${{ env.REPO_STAGING }}" >> $GITHUB_ENV | |
else | |
echo "REPO=${{ env.REPO_PROD }}" >> $GITHUB_ENV | |
fi | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version: "1.23" | |
- name: Install abigen | |
run: make install-abigen | |
- name: Generate contract bindings | |
run: make generate | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to registry | |
run: | | |
docker login ${{ env.DOCKER_REGISTRY }} -u ${{ secrets.ARTIFACTORY_ANGKOR_USERNAME }} -p ${{ secrets.ARTIFACTORY_ANGKOR_TOKEN_DEVELOPER }} | |
- name: Build and Push | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
platforms: "linux/amd64" | |
push: true | |
file: Dockerfile | |
tags: | | |
${{ env.DOCKER_REGISTRY }}/${{ env.REPO }}/${{ env.APP_NAME }}:${{ env.VERSION }} | |
${{ env.DOCKER_REGISTRY }}/${{ env.REPO }}/${{ env.APP_NAME }}:latest | |
build-args: | | |
APP_NAME=${{ env.APP_NAME }} | |
VERSION=${{ env.VERSION }} | |
release: | |
runs-on: ubuntu-latest | |
name: "Bump version and create changelog with commitizen" | |
needs: define_tag | |
steps: | |
- name: Check out | |
uses: actions/checkout@v4 | |
with: | |
token: "${{ secrets.GITHUB_TOKEN }}" | |
fetch-depth: 0 | |
fetch-tags: true | |
- name: Import GPG key | |
uses: crazy-max/ghaction-import-gpg@v6 | |
with: | |
gpg_private_key: ${{ secrets.GPG_PRIVATE_KEY }} | |
passphrase: ${{ secrets.PASSPHRASE }} | |
git_config_global: true | |
git_user_signingkey: true | |
git_commit_gpgsign: true | |
git_tag_gpgsign: true | |
git_push_gpgsign: true | |
trust_level: 5 | |
- name: Set up Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.x' | |
- name: Install commitizen | |
run: pip install --upgrade commitizen | |
- name: Bump Version and Create Changelog | |
id: cz | |
run: | | |
echo "Configure Git..." | |
git config --local user.name "github-actions[bot]" | |
git config --local user.email "github-actions[bot]@users.noreply.github.com" | |
git config --local pull.rebase true | |
git config --local commit.gpgsign true | |
git config --local tag.gpgsign true | |
export GPG_TTY=$(tty) | |
export GIT_EDITOR=true | |
echo "Bump version..." | |
cz --no-raise 21 bump --yes --changelog | |
# Get the new version from commitizen | |
new_version="$(cz version --project)" | |
# Get the current branch name | |
current_branch="$(git branch --show-current)" | |
# Remote repository URL with authentication | |
remote_repo="https://${GITHUB_ACTOR}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" | |
# Pull the latest changes from the remote | |
git pull "$remote_repo" "$current_branch" | |
# Create the new tag with a message | |
git tag -a "v${new_version}" -m "Release version ${new_version}" | |
# Push changes and the new tag to the remote repository | |
git push "$remote_repo" "HEAD:${current_branch}" --tags | |
# Output version number for next steps | |
echo "version=${new_version}" >> $GITHUB_OUTPUT | |
- name: Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
body_path: "CHANGELOG.md" | |
tag_name: v${{ steps.cz.outputs.version }} | |
draft: false | |
prerelease: true | |
generate_release_notes: true | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |