Skip to content

Commit

Permalink
ci: update release pipeline
Browse files Browse the repository at this point in the history
Updates:
- Push docker image to JFrog targeting prod env by default
- Use commitizen to define automatic new tag
  • Loading branch information
AntiD2ta committed Oct 7, 2024
1 parent 33120ee commit 4b691f5
Showing 1 changed file with 100 additions and 31 deletions.
131 changes: 100 additions & 31 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,55 +1,124 @@
name: Build and Release Docker Image

env:
DOCKER_REGISTRY: nethermind.jfrog.io

REPO_DEV: angkor-oci-local-dev
REPO_STAGING: angkor-oci-local-staging
REPO_PROD: angkor-oci-local-prod

on:
push:
tags:
- 'v*.*.*'
branches:
- main
workflow_dispatch:
inputs:
version:
type: string
description: 'Environment to release to'
required: true
default: 'prod'
options:
- dev
- staging
- prod

permissions:
contents: write
id-token: write

jobs:
build:
name: Create and Push Docker Image
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

- name: Bump version
id: bump_version
run: |
new_version=$(cz bump --dry-run | grep -oP '(?<=tag: v).*')
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
env:
VERSION: ${{ github.ref_name }}
VERSION: ${{ steps.define_tag.outputs.tag }}
APP_NAME: ${{ github.event.repository.name }}
REPO: ${{
(github.event.inputs.version == 'dev' && env.REPO_DEV) ||
(github.event.inputs.version == 'staging' && env.REPO_STAGING) ||
env.REPO_PROD
}}
steps:
- name: Set up QEMU
uses: docker/setup-qemu-action@v3

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_ACCESS_TOKEN }}

- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
push: true
tags: |
nethermindeth/${{env.APP_NAME}}:${{env.VERSION}}
nethermindeth/${{env.APP_NAME}}:latest
build-args: |
APP_NAME=${{ env.APP_NAME }}
VERSION=${{ env.VERSION }}
- name: Log out of Docker Hub
run: docker logout
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- 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_CONTRIBUTOR }}
- 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_DEV }}/${{ env.APP_NAME }}:${{ env.VERSION }}
${{ env.DOCKER_REGISTRY }}/${{ env.REPO_DEV }}/${{ env.APP_NAME }}:latest
build-args: |
APP_NAME=${{ env.APP_NAME }}
VERSION=${{ env.VERSION }}
create-release:
name: Create GitHub Release
runs-on: ubuntu-latest
env:
VERSION: ${{ github.ref_name }}
VERSION: ${{ steps.define_tag.outputs.tag }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Create Release
uses: ncipollo/release-action@v1
Expand Down

0 comments on commit 4b691f5

Please sign in to comment.