Docker Publish #869
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Docker Publish | |
on: | |
workflow_dispatch: ## on button click | |
schedule: | |
- cron: '0 1/11 * * *' | |
push: | |
paths: | |
- 'docker/*' | |
- '!docker/*.md' | |
- '.github/workflows/docker*' | |
branches: | |
- main | |
- stable | |
tags: | |
- v[0-9]* | |
env: | |
APP_VERSION_LATEST: "5.1.4" | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- | |
name: Checkout | |
uses: actions/checkout@v3 | |
- | |
name: Set up QEMU | |
uses: docker/setup-qemu-action@v3 | |
- | |
name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- | |
name: Set outputs | |
id: vars | |
env: | |
DOCKERHUB_TOKEN: "${{ secrets.DOCKERHUB_TOKEN }}" | |
run: | | |
set -x | |
sha_short=$(git rev-parse --short HEAD) | |
echo "sha_short=$sha_short" >> $GITHUB_OUTPUT | |
echo "[env] GITHUB_REF_NAME: $GITHUB_REF_NAME" | |
if echo "$GITHUB_REF_NAME" | grep -E 'v[0-9.]+(-.*)?'; then | |
app_version=$(echo "$GITHUB_REF_NAME" | cut -d "-" -f1 | sed 's/^v//') | |
dl_url="https://dist.apache.org/repos/dist/release/rocketmq/${app_version}/rocketmq-all-${app_version}-bin-release.zip" | |
curl -sI "$dl_url" | grep '200 OK' | |
if [[ $? == "0" ]]; then | |
echo "is_release=true" >> $GITHUB_OUTPUT | |
echo "app_version=${app_version}" >> $GITHUB_OUTPUT | |
echo "app_version_short=$(echo $app_version | sed -E 's/.[0-9]+$//')" >> $GITHUB_OUTPUT | |
sha_tag="v${app_version}-${sha_short}" | |
echo "sha_tag=$sha_tag" >> $GITHUB_OUTPUT | |
if [[ "$app_version" == "$APP_VERSION_LATEST" ]]; then | |
echo "latest_or_sha=latest" >> $GITHUB_OUTPUT | |
else | |
echo "latest_or_sha=$sha_tag" >> $GITHUB_OUTPUT | |
fi | |
fi | |
fi | |
if echo "$DOCKERHUB_TOKEN" | grep -Eo '^[a-zA-Z]' > /dev/null ; then | |
echo "dockerhub_token_ok=true" >> $GITHUB_OUTPUT | |
else | |
exit "500" | |
fi | |
- | |
name: Login to Docker Hub | |
uses: docker/login-action@v3 | |
if: steps.vars.outputs.dockerhub_token_ok == 'true' | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- | |
name: Docker build testing | |
uses: docker/build-push-action@v5 | |
if: github.ref_name == 'main' | |
with: | |
context: docker/ | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
${{ vars.CR_REPO }}:snapshot | |
- | |
name: Docker build pre | |
uses: docker/build-push-action@v5 | |
if: github.ref_name == 'stable' | |
with: | |
context: docker/ | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
tags: | | |
${{ vars.CR_REPO }}:pre-${{ steps.vars.outputs.sha_short }} | |
- | |
name: Build and push | |
uses: docker/build-push-action@v5 | |
if: steps.vars.outputs.is_release == 'true' | |
with: | |
context: docker/ | |
platforms: linux/amd64,linux/arm64 | |
push: true | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
build-args: | | |
app_version=${{ steps.vars.outputs.app_version }} | |
tags: | | |
${{ vars.CR_REPO }}:${{ steps.vars.outputs.sha_tag }} | |
${{ vars.CR_REPO }}:${{ steps.vars.outputs.latest_or_sha }} | |
${{ vars.CR_REPO }}:v${{ steps.vars.outputs.app_version_short }} | |
${{ vars.CR_REPO }}:v${{ steps.vars.outputs.app_version }} |