Docker Publish #574
This file contains hidden or 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: Remove .git directory | |
run: | | |
echo "Remove .git directory" | |
rm -rf .git | |
- name: Configure Docker data-root | |
run: | | |
sudo systemctl stop docker | |
sudo systemctl stop docker.socket | |
sudo mkdir -p /mnt/docker | |
echo '{ "data-root": "/mnt/docker" }' | sudo tee /etc/docker/daemon.json | |
if [ -d /var/lib/docker ]; then | |
sudo mv /var/lib/docker /mnt/docker || true | |
fi | |
sudo systemctl start docker.socket | |
sudo systemctl start docker | |
docker info | grep "Docker Root Dir" | |
- name: Download branch name file | |
uses: actions/download-artifact@v4 | |
with: | |
name: branch_name | |
run-id: ${{ github.event.workflow_run.id }} | |
github-token: ${{ secrets.GH_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.GH_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.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 | |
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: 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 docker/rocky9 && rm -f dingofs.tar.gz | |
- 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=${{ env.BRANCH_NAME == 'main' && env.EVENT != 'tag'}} | |
type=sha,prefix=,format=short,enable=${{ env.EVENT != 'tag' && env.BRANCH_NAME == 'main' }} | |
type=raw,prefix=${{ env.BRANCH_NAME }}-,value=${{ env.COMMIT_ID }},enable=${{ env.EVENT != 'tag' && env.BRANCH_NAME != 'main' }} | |
- name: Build and push | |
if: steps.check-event.outputs.continue == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker/rocky9 | |
file: ./docker/rocky9/Dockerfile | |
push: true | |
tags: ${{ steps.meta.outputs.tags }} | |
- name: Docker meta mdsv2 | |
if: steps.check-event.outputs.continue == 'true' | |
id: meta-v2 | |
uses: docker/metadata-action@v5 | |
with: | |
images: dingodatabase/dingofs | |
tags: | | |
type=raw,enable=${{ env.EVENT == 'tag' }},value=${{ env.TAG_NAME }} | |
type=sha,prefix=mdsv2-,format=short,enable=${{ env.EVENT != 'tag' && env.BRANCH_NAME == 'main' }} | |
- name: Build and push mdsv2 | |
if: steps.check-event.outputs.continue == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
context: ./docker/rocky9 | |
file: ./docker/rocky9/Dockerfile-v2 | |
push: true | |
tags: ${{ steps.meta-v2.outputs.tags }} |