Skip to content

Release-Dockerhub #3435

Release-Dockerhub

Release-Dockerhub #3435

# This is a basic workflow to help you get started with Actions
name: Release-Dockerhub
# Controls when the workflow will run
on:
# Triggers the workflow on push or pull request events but only for the main branch
workflow_run:
workflows: ["CMake_rocky8"]
types:
- completed
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
release:
# The type of runner that the job will run on
if: github.event.pull_request.merged == false
runs-on: ubuntu-latest
permissions:
packages: write
contents: read
steps:
- uses: actions/checkout@v4
- name: Download branch name file
uses: actions/download-artifact@v4
with:
name: branch_name
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config trigger branch env
run: |
if [ -f branch_name.txt ]; then
echo "BRANCH_NAME=$(cat branch_name.txt)" >> $GITHUB_ENV
fi
- name: Download commit id file
uses: actions/download-artifact@v4
with:
name: commit_id
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config commit id env
run: |
if [ -f commit_id.txt ]; then
echo "COMMIT_ID=$(cat commit_id.txt)" >> $GITHUB_ENV
fi
- name: Download event type file
uses: actions/download-artifact@v4
with:
name: event
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config trigger event env
run: |
if [ -f event.txt ]; then
echo "EVENT=$(cat event.txt)" >> $GITHUB_ENV
fi
- name: Download tag name file
if: ${{ env.EVENT == 'tag' }}
uses: actions/download-artifact@v4
with:
name: tag_name
run-id: ${{ github.event.workflow_run.id }}
github-token: ${{ secrets.GITHUB_TOKEN }}
path: ./
- name: Config push tag env
if: ${{ env.EVENT == 'tag' }}
run: |
if [ -f tag_name.txt ]; then
echo "TAG_NAME=$(cat tag_name.txt)" >> $GITHUB_ENV
fi
- name: Print env info
id: check-event
run: |
echo "trigger event type is ${{ env.EVENT }}"
echo "continue=true" >> $GITHUB_OUTPUT
if [ "${{ env.EVENT }}" == "pull_request" ]; then
echo "pull request haven't merged, not need to publish image."
echo "continue=false" >> $GITHUB_OUTPUT
fi
if [ -n "${{ env.TAG_NAME }}" ]; then
echo "tag name is ${{ env.TAG_NAME }}, need to publish image."
fi
if [ -n "${{ env.BRANCH_NAME }}" ]; then
echo "branch name is ${{ env.BRANCH_NAME }}"
fi
if [ -n "${{ env.COMMIT_ID }}" ]; then
echo "commit id is ${{ env.COMMIT_ID }}"
fi
- name: Download artifact
if: steps.check-event.outputs.continue == 'true'
uses: dawidd6/action-download-artifact@v2
with:
github_token: ${{secrets.GITHUB_TOKEN}}
workflow: ci_rocky8.yml
name: dingo-store.tar.gz
- name: rename artifactory name
if: steps.check-event.outputs.continue == 'true'
run: |
cp dingo-store.tar.gz ./docker
# setup Docker buld action
- name: Set up Docker Buildx
if: steps.check-event.outputs.continue == 'true'
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to Github Packages
if: steps.check-event.outputs.continue == 'true'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Docker meta info
if: steps.check-event.outputs.continue == 'true'
id: store-meta
uses: docker/metadata-action@v5
with:
images: dingodatabase/dingo-store
tags: |
type=raw,enable=${{ env.EVENT == 'tag' }},value=${{ env.TAG_NAME }}
type=raw,value=latest,enable=${{ env.BRANCH_NAME == 'main' && env.EVENT != 'tag'}}
type=sha,prefix=,format=short,enable=${{ env.BRANCH_NAME == 'main' && env.EVENT != 'tag' }}
type=raw,prefix=${{ env.BRANCH_NAME }}-,value=${{ env.COMMIT_ID }},enable=${{ env.EVENT != 'tag' && env.BRANCH_NAME != 'main' }}
- name: Build image and push to Docker Hub and GitHub Container Registry
if: steps.check-event.outputs.continue == 'true'
uses: docker/build-push-action@v6
with:
# relative path to the place where source code with Dockerfile is located
context: ./docker
#tags: dingodatabase/dingo-store:latest
tags: ${{ steps.store-meta.outputs.tags }}
# push: ${{ github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/main' }}
push: true
- name: Image digest
if: steps.check-event.outputs.continue == 'true'
run: echo ${{ steps.docker_build.outputs.digest }}