10BC0 Fixed Alt-Svc header to conform to current documentation. · nginx/nginx-quic-qns@e74a9c5 · GitHub
[go: up one dir, main page]

Skip to content

Docker Build and Push #208

Docker Build and Push

Docker Build and Push #208

name: Docker Build and Push
on:
schedule:
- cron: '13 13 * * *'
push:
branches: [ "master" ]
pull_request:
branches: [ "master" ]
workflow_dispatch:
env:
push_build: false
trigger_build: false
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
steps:
- name: Checkout repository
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
- 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: Install Skopeo
run: |
sudo apt-get update
sudo apt-get install -y skopeo
- name: Get the commit ID tag of the latest image with Skopeo
run: |
LATEST_IMAGE_COMMIT=$(skopeo inspect docker://${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest | jq -r '.Labels.commit_id' || 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
elif [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "Running under workflow_dispatch. 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: Decide if we want to push the container
if: github.ref == 'refs/heads/master' && github.event_name != 'pull_request'
run: |
echo "push_build=true" >> $GITHUB_ENV
- name: Login to GitHub Container Registry
if: env.push_build == 'true'
uses: docker/login-action@184bdaa0721073962dff0199f1fb9940f07167d1 # v3.5.0
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and Push Docker Image
if: env.trigger_build == 'true'
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6.18.0
with:
context: .
file: Dockerfile
push: ${{ env.push_build }}
tags: |
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ env.commit_id }}
labels: |
commit_id=${{ env.commit_id }}
0