Skip to content

Commit

Permalink
ci: add the ci code used to package and release docker images (ethere…
Browse files Browse the repository at this point in the history
…um-optimism#11)

* ci: add the ci code used to package and release docker images (#7)

* ci: add the ci code used to package and release docker images

Co-authored-by: Welkin <[email protected]>

* fix: add latest tag for docker image (ethereum-optimism#9)

Co-authored-by: Welkin <[email protected]>

* try to use cache for docker build (ethereum-optimism#10)

Co-authored-by: Welkin <[email protected]>

---------

Co-authored-by: Welkin <[email protected]>
  • Loading branch information
2 people authored and bnoieh committed Sep 20, 2023
1 parent a1f92fd commit 6790411
Showing 1 changed file with 125 additions and 0 deletions.
125 changes: 125 additions & 0 deletions .github/workflows/docker-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
name: DockerImage build and push

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

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

steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GHCR
uses: docker/login-action@v2
with:
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: 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

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

steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GHCR
uses: docker/login-action@v2
with:
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: 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
push-op-proposer:
runs-on: ubuntu-latest
if: github.event_name == 'push'

steps:
- uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Login to GHCR
uses: docker/login-action@v2
with:
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: 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

0 comments on commit 6790411

Please sign in to comment.