Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ISSUE #116] add workflow for multi-ach Docker image #117

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 56 additions & 2 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: docker-publish

on:
workflow_dispatch:
schedule:
- cron: '0 * * * *'
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]

env:
REGISTRY: docker.io
Expand All @@ -18,10 +23,59 @@ jobs:
packages: write

steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get the latest release version with GitHub Script
id: get_release
uses: actions/github-script@v6
with:
script: |
const { data: latestRelease } = await github.rest.repos.getLatestRelease({
owner: 'apache',
repo: 'rocketmq'
});
core.setOutput('version_on_github', latestRelease.tag_name.replaceAll("rocketmq-all-", ""));

- name: Output the latest release version
run: echo "The latest release version is ${{ steps.get_release.outputs.version_on_github }}"

- name: Check if Docker image exists
id: check_image
run: |
TAG="${{ steps.get_release.outputs.version_on_github }}"
EXISTS=$(curl -s -o /dev/null -w "%{http_code}" "https://hub.docker.com/v2/repositories/${{ env.IMAGE_NAME }}/tags/$TAG/")
if [ "$EXISTS" -eq "200" ]; then
echo "exists=true" >> $GITHUB_ENV
else
echo "exists=false" >> $GITHUB_ENV
fi

- name: Set up Docker Buildx
if: env.exists == 'false'
uses: docker/setup-buildx-action@f95db51fddba0c2d1ec667646a06c2ce06100226 # v3.0.0

- name: Log into registry ${{ env.REGISTRY }}
#if: env.exists == 'false' && github.event_name != 'pull_request'
if: env.exists == 'false' && github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ secrets.DOCKERHUB_USER }}
password: ${{ secrets.DOCKERHUB_TOKEN }}

- name: Build and push Docker image
id: build-and-push
if: env.exists == 'false'
uses: docker/build-push-action@v6
with:
context: "{{defaultContext}}:image-build"
file: Dockerfile-ubuntu
platforms: linux/amd64,linux/arm64
pull: true
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.IMAGE_NAME }}:latest
${{ env.IMAGE_NAME }}:${{ steps.get_release.outputs.version_on_github }}
build-args: version=${{ steps.get_release.outputs.version_on_github }}
cache-from: type=gha
cache-to: type=gha,mode=max
Loading