Skip to content

Build and Release Docker Image #11

Build and Release Docker Image

Build and Release Docker Image #11

Workflow file for this run

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 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"
steps:
- name: Check out
uses: actions/checkout@v4
with:
token: "${{ secrets.GITHUB_TOKEN }}"
fetch-depth: 0
- name: Show git tags
run: git tag
- name: Create bump and changelog
uses: commitizen-tools/commitizen-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
changelog_increment_filename: CHANGELOG.md
- name: Release
uses: softprops/action-gh-release@v1
with:
body_path: "CHANGELOG.md"
tag_name: ${{ env.REVISION }}
draft: false
prerelease: true
generate_release_notes: true
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}