Skip to content

Commit

Permalink
ci: Refactor Docker release workflow and image metadata
Browse files Browse the repository at this point in the history
  • Loading branch information
owen-reorg committed Sep 27, 2023
1 parent 039e6fd commit b3ba480
Showing 1 changed file with 45 additions and 59 deletions.
104 changes: 45 additions & 59 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ name: DockerImage build and push

on:
push:
# Publish `v1.2.3` tags as releases.
tags:
- v*
branches:
pull_request:

jobs:
# Push image to GitHub Packages.
push-op-node:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v3
Expand All @@ -22,34 +21,29 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: ImageId
id: image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/op-node
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID">>$GITHUB_OUTPUT
echo "VERSION=$VERSION">>$GITHUB_OUTPUT
- name: image meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/op-node
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=sha
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./op-node/Dockerfile
push: true
tags: ${{ steps.image.outputs.IMAGE_ID }}:${{ steps.image.outputs.VERSION }},${{ steps.image.outputs.IMAGE_ID }}:latest
cache-from: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache
cache-to: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

push-op-batcher:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v3
Expand All @@ -61,33 +55,29 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: ImageId
id: image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/op-batcher
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID">>$GITHUB_OUTPUT
echo "VERSION=$VERSION">>$GITHUB_OUTPUT
- name: image meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/op-batcher
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=sha
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./op-batcher/Dockerfile
push: true
tags: ${{ steps.image.outputs.IMAGE_ID }}:${{ steps.image.outputs.VERSION }},${{ steps.image.outputs.IMAGE_ID }}:latest
cache-from: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache
cache-to: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache,mode=max
tags: ${{ steps.meta.outputs.tags }},${{ steps.meta0.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

push-op-proposer:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v3
Expand All @@ -99,27 +89,23 @@ jobs:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: ImageId
id: image
run: |
IMAGE_ID=ghcr.io/${{ github.repository_owner }}/op-proposer
# Change all uppercase to lowercase
IMAGE_ID=$(echo $IMAGE_ID | tr '[A-Z]' '[a-z]')
# Strip git ref prefix from version
VERSION=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\),\1,')
# Strip "v" prefix from tag name
[[ "${{ github.ref }}" == "refs/tags/"* ]] && VERSION=$(echo $VERSION | sed -e 's/^v//')
# Use Docker `latest` tag convention
[ "$VERSION" == "main" ] && VERSION=latest
echo "IMAGE_ID=$IMAGE_ID">>$GITHUB_OUTPUT
echo "VERSION=$VERSION">>$GITHUB_OUTPUT
- name: image meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository_owner }}/op-proposer
tags: |
type=ref,event=branch
type=ref,event=pr
type=ref,event=tag
type=semver,pattern={{version}}
type=sha
- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./op-proposer/Dockerfile
push: true
tags: ${{ steps.image.outputs.IMAGE_ID }}:${{ steps.image.outputs.VERSION }},${{ steps.image.outputs.IMAGE_ID }}:latest
cache-from: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache
cache-to: type=registry,ref=${{ steps.image.outputs.IMAGE_ID }}:buildcache,mode=max
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

0 comments on commit b3ba480

Please sign in to comment.