Docker Publish #14
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_run: | |
workflows: ["CI Build"] | |
types: | |
- completed | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Download event type file | |
uses: actions/download-artifact@v4 | |
with: | |
name: event | |
run-id: ${{ github.event.workflow_run.id }} | |
github-token: ${{ secrets.GH_TOKEN }} | |
path: ./ | |
- name: Download dingofs artifact | |
uses: actions/download-artifact@v4 | |
with: | |
name: dingofs | |
run-id: ${{ github.event.workflow_run.id }} | |
github-token: ${{ secrets.GH_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.GH_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 | |
- name: List directory contents after download | |
if: steps.check-event.outputs.continue == 'true' | |
run: ls -la | |
- name: Extract artifact | |
if: steps.check-event.outputs.continue == 'true' | |
run: tar -xzvf dingofs.tar.gz -C dingofs/docker/rocky9 | |
- name: Set up Docker Buildx | |
if: steps.check-event.outputs.continue == 'true' | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Docker Hub | |
if: steps.check-event.outputs.continue == 'true' | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Docker meta | |
if: steps.check-event.outputs.continue == 'true' | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: dingodatabase/dingofs | |
tags: | | |
type=raw,enable=${{ env.EVENT == 'tag' }},value=${{ env.TAG_NAME }} | |
type=raw,value=latest,enable={{is_default_branch}} | |
type=sha,prefix=,format=long | |
- name: Build and push | |
if: steps.check-event.outputs.continue == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./dingofs/docker/rocky9 | |
file: ./dingofs/docker/rocky9/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} |