Build Docker Image #13873
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: Build Docker Image | |
on: | |
schedule: | |
# Every 1 hour | |
- cron: "0 * * * *" | |
workflow_dispatch: | |
inputs: | |
git_tag: | |
description: Git Tag To Release From. Last Git Tag Is Used If Omitted | |
required: false | |
force: | |
type: boolean | |
description: Force Build Image | |
required: false | |
default: false | |
jobs: | |
build: | |
name: Build Client Push | |
runs-on: ubuntu-latest | |
strategy: | |
matrix: | |
include: | |
- registry: docker.io | |
image: docker.io/miles170/notify_push | |
username: DOCKERHUB_USERNAME | |
password: DOCKERHUB_TOKEN | |
- registry: ghcr.io | |
image: ghcr.io/miles170/notify_push | |
username: GHCR_USERNAME | |
password: GHCR_TOKEN | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
with: | |
repository: nextcloud/notify_push | |
fetch-depth: 0 | |
- name: Get git info | |
id: git-info | |
run: | | |
tag='${{ github.event.inputs.git_tag }}' | |
if [[ -z "${tag}" ]]; then | |
tag=$(git describe --tags $(git rev-list --tags --max-count=1)) | |
fi | |
echo "tag=${tag}" >> $GITHUB_OUTPUT | |
git checkout $tag | |
echo "hash=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT | |
- name: Check Docker image | |
id: inspect | |
run: | | |
if [[ '${{ github.event.inputs.force }}' == 'true' ]]; then | |
echo 'Skip hash verification' | |
echo 'build=true' >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
image=${{ matrix.image }}:latest | |
if ! docker pull $image; then | |
echo 'build=true' >> $GITHUB_OUTPUT | |
exit 0 | |
fi | |
hash=$(docker inspect --format '{{ index .Config.Labels "org.opencontainers.image.revision" }}' $image) | |
if [[ "${hash}" != '${{ steps.git-info.outputs.hash }}' ]]; then | |
echo "${hash} != ${{ steps.git-info.outputs.hash }}" | |
echo 'build=true' >> $GITHUB_OUTPUT | |
fi | |
- name: Docker metadata | |
if: ${{ steps.inspect.outputs.build == 'true' }} | |
id: metadata | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ matrix.image }} | |
labels: | | |
org.opencontainers.image.title=notify_push | |
org.opencontainers.image.description=Update notifications for nextcloud clients | |
org.opencontainers.image.source=https://github.com/nextcloud/notify_push | |
org.opencontainers.image.version=${{ steps.git-info.outputs.tag }} | |
org.opencontainers.image.revision=${{ steps.git-info.outputs.hash }} | |
- name: Set up Docker Buildx | |
if: ${{ steps.inspect.outputs.build == 'true' }} | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to Container Registry | |
if: ${{ steps.inspect.outputs.build == 'true' }} | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ matrix.registry }} | |
username: ${{ secrets[matrix.username] }} | |
password: ${{ secrets[matrix.password] }} | |
- name: Build and push | |
if: ${{ steps.inspect.outputs.build == 'true' }} | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
push: true | |
tags: ${{ matrix.image }}:latest, ${{ matrix.image }}:${{ steps.git-info.outputs.tag }} | |
labels: ${{ steps.metadata.outputs.labels }} | |
cache-from: type=registry,ref=${{ matrix.image }}:latest | |
cache-to: type=inline |