From d390a8603c7e7c35d78eb9f58ed2559ad6da4c1f Mon Sep 17 00:00:00 2001 From: welkin22 <136572398+welkin22@users.noreply.github.com> Date: Tue, 20 Jun 2023 20:29:12 +0800 Subject: [PATCH] ci: add docker release workflow to build and release docker image (#3) * ci: add docker release workflow to build and release docker image (#1) Co-authored-by: Welkin * try to use cache for docker build (#2) Co-authored-by: Welkin --------- Co-authored-by: Welkin --- .github/workflows/docker-release.yml | 49 ++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 .github/workflows/docker-release.yml diff --git a/.github/workflows/docker-release.yml b/.github/workflows/docker-release.yml new file mode 100644 index 0000000000..ef55ecb8e8 --- /dev/null +++ b/.github/workflows/docker-release.yml @@ -0,0 +1,49 @@ +name: DockerImage build and push + +on: + push: + # Publish `v1.2.3` tags as releases. + tags: + - v* + +jobs: + # Push image to GitHub Packages. + push-op-geth: + 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-geth + + # 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: ./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 +