Skip to content

Commit

Permalink
Add Docker publish workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
route443 committed Jan 24, 2024
1 parent 3fabb85 commit df86f6f
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions .github/workflows/docker-publish.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
name: Docker Build and Push

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

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Get latest commit ID from nginx/nginx
run: |
LATEST_COMMIT=$(curl -s https://api.github.com/repos/nginx/nginx/commits/master | jq -r '.sha')
echo "commit_id=$LATEST_COMMIT" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Pull the latest image for comparison
run: |
docker pull ghcr.io/nginx/nginx-quic-qns:latest || true
- name: Get the commit ID tag of the latest image
run: |
LATEST_IMAGE_COMMIT=$(docker inspect ghcr.io/nginx/nginx-quic-qns:latest --format '{{ index .Config.Labels "commit_id" }}' 2> /dev/null || echo "none")
echo "latest_image_commit=$LATEST_IMAGE_COMMIT" >> $GITHUB_ENV
- name: Compare commit IDs
run: |
if [ "${{ env.commit_id }}" != "${{ env.latest_image_commit }}" ]; then
echo "Commit IDs are different. Triggering build."
echo "trigger_build=true" >> $GITHUB_ENV
else
echo "Commit IDs are the same. No build needed."
echo "trigger_build=false" >> $GITHUB_ENV
fi
- name: Build and Push Docker Image
if: env.trigger_build == 'true'
uses: docker/build-push-action@v5
with:
context: .
file: Dockerfile
push: true
tags: |
ghcr.io/nginx/nginx-quic-qns:latest
ghcr.io/nginx/nginx-quic-qns:${{ env.commit_id }}
labels: |
commit_id=${{ env.commit_id }}

0 comments on commit df86f6f

Please sign in to comment.