Skip to content

chore(deps): bump docker/build-push-action from 5 to 6 #66

chore(deps): bump docker/build-push-action from 5 to 6

chore(deps): bump docker/build-push-action from 5 to 6 #66

name: Docker
on:
push:
paths-ignore:
- '*.md'
- '**/*.md'
# Publish `main` as Docker `edge` image.
branches:
- main
- 'release/*'
# Publish `v1.2.3` tags as releases.
tags:
- 'v*.*.*'
# Run tests for any PRs.
pull_request:
env:
IMAGE_NAME: nut
IMAGE_TITLE: NUT
IMAGE_DESCRIPTION: Docker container for NUT, a network server for Tinfoil
APP_VERSION: "5cf47cd"
COMMIT_REF: "5cf47cd73704fd89c27c5fdafbbb0ad5e5053915"
COMMIT_REF_SHORT: "5cf47cd"
jobs:
# Run tests.
# See also https://docs.docker.com/docker-hub/builds/automated-testing/
test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up Docker Buildx
id: buildx_test
uses: docker/setup-buildx-action@v3
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.test-buildx-cache
key: ${{ runner.os }}-test-buildx-${{ env.COMMIT_REF_SHORT }}
restore-keys: |
${{ runner.os }}-test-buildx-${{ env.COMMIT_REF_SHORT }}
${{ runner.os }}-test-buildx-
- name: Test build
id: docker_build_test
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx_test.outputs.name }}
context: .
platforms: linux/amd64
push: false
cache-from: type=local,src=/tmp/.test-buildx-cache
cache-to: type=local,dest=/tmp/.test-buildx-cache-new
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.test-buildx-cache
mv /tmp/.test-buildx-cache-new /tmp/.test-buildx-cache
# Build images.
build:
if: github.event_name != 'pull_request'
runs-on: ubuntu-latest
needs: test
steps:
- name: Checkout
uses: actions/checkout@v4
with:
ref: ${{ github.ref }}
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
with:
platforms: all
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Prepare
id: prep
run: |
DOCKERIO_IMAGE=docker.io/${{ github.repository_owner }}/$IMAGE_NAME
GHCRIO_IMAGE=ghcr.io/${{ github.repository_owner }}/$IMAGE_NAME
# Strip git ref prefix from version
VERSION_FULL=$(echo "${{ github.ref }}" | sed -e 's,.*/\(.*\)$,\1,')
VERSION_MINOR=$(echo "$VERSION_FULL" | sed 's,\.[^.]*$,,')
VERSION_MAJOR=$(echo "$VERSION_MINOR" | sed 's,\.[^.]*$,,')
# Use Docker `edge` tag convention and pr-<number> for pull requests
[ "$VERSION_FULL" == "main" ] && VERSION_FULL=edge
[ ${{ github.ref }} == refs/pull/* ] && VERSION_FULL=pr-${{ github.event.number }}
# Build all tags
DOCKERIO_TAGS="${DOCKERIO_IMAGE}:${VERSION_FULL}"
[ "$VERSION_FULL" != "edge" ] && DOCKERIO_TAGS="$DOCKERIO_TAGS,${DOCKERIO_IMAGE}:${VERSION_MINOR},${DOCKERIO_IMAGE}:${VERSION_MAJOR},${DOCKERIO_IMAGE}:latest"
[ "$VERSION_FULL" == "edge" ] && DOCKERIO_TAGS="$TAGS,${DOCKERIO_IMAGE}:${VERSION_FULL}-${COMMIT_REF_SHORT},${DOCKERIO_IMAGE}:${VERSION_FULL}-${COMMIT_REF}"
GHCRIO_TAGS="${GHCRIO_IMAGE}:${VERSION_FULL}"
[ "$VERSION_FULL" != "edge" ] && GHCRIO_TAGS="$GHCRIO_TAGS,${GHCRIO_IMAGE}:${VERSION_MINOR},${GHCRIO_IMAGE}:${VERSION_MAJOR},${GHCRIO_IMAGE}:latest"
[ "$VERSION_FULL" == "edge" ] && GHCRIO_TAGS="$GHCRIO_TAGS,${GHCRIO_IMAGE}:${VERSION_FULL}-${COMMIT_REF_SHORT},${GHCRIO_IMAGE}:${VERSION_FULL}-${COMMIT_REF}"
# Build tags for README.md
[ "$VERSION_FULL" != "edge" ] && README_TAGS="\`latest\`, \`${VERSION_MAJOR}\`, \`${VERSION_MINOR}\`, \`${VERSION_FULL}\`"
[ "$VERSION_FULL" == "edge" ] && README_TAGS="\`${VERSION_FULL}\`, \`${VERSION_FULL}-${COMMIT_REF_SHORT}\`, \`${VERSION_FULL}-${COMMIT_REF}\`"
# Replace supported latest tags in README.md
if [ "$VERSION_FULL" != "edge" ]; then
sed -i '/- `latest`.*<!-- latest tag -->/c- '"${README_TAGS}"' <!-- latest tag -->' README.md
fi
# Replace supported edge tags in README.md
if [ "$VERSION_FULL" == "edge" ]; then
sed -i '/- `edge`.*<!-- edge tag -->/c- '"${README_TAGS}"' <!-- edge tag -->' README.md
fi
# Use Docker `edge` tag convention and pr-<number> for pull requests
[ "$VERSION_FULL" == "main" ] && VERSION_FULL=edge
[ ${{ github.ref }} == refs/pull/* ] && VERSION_FULL=pr-${{ github.event.number }}
# Build tags for README.md
[ "$VERSION_FULL" != "edge" ] && README_TAGS="\`latest\`, \`${VERSION_MAJOR}\`, \`${VERSION_MINOR}\`, \`${VERSION_FULL}\`"
[ "$VERSION_FULL" == "edge" ] && README_TAGS="\`${VERSION_FULL}\`, \`${VERSION_FULL}-${COMMIT_REF_SHORT}\`, \`${VERSION_FULL}-${COMMIT_REF}\`"
echo "version=${VERSION_FULL}" >> $GITHUB_OUTPUT
echo "tags=${DOCKERIO_TAGS},${GHCRIO_TAGS}" >> $GITHUB_OUTPUT
echo "created=$(date -u +'%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT
echo "readme_tags=${README_TAGS}" >> $GITHUB_OUTPUT
echo "release=${{ github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags') }}" >> $GITHUB_OUTPUT
- name: Cache Docker layers
uses: actions/cache@v4
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ env.COMMIT_REF_SHORT }}
restore-keys: |
${{ runner.os }}-buildx-${{ env.COMMIT_REF_SHORT }}
${{ runner.os }}-buildx-
- name: Build and push
id: docker_build
uses: docker/build-push-action@v6
with:
builder: ${{ steps.buildx.outputs.name }}
context: .
platforms: linux/amd64,linux/386,linux/arm64,linux/arm/v7,linux/arm/v6
push: ${{ steps.prep.outputs.release == 'true' }}
tags: ${{ steps.prep.outputs.tags }}
labels: |
org.opencontainers.image.title=$IMAGE_TITLE
org.opencontainers.image.description=$IMAGE_DESCRIPTION
org.opencontainers.image.vendor=${{ github.repository_owner }}
org.opencontainers.image.url=${{ github.event.repository.html_url }}
org.opencontainers.image.source=${{ github.event.repository.html_url }}
org.opencontainers.image.created=${{ steps.prep.outputs.created }}
org.opencontainers.image.revision=${{ github.sha }}
org.opencontainers.image.version=$APP_VERSION
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache-new
- name: Checkout main
if: steps.prep.outputs.release == 'true'
uses: actions/checkout@v4
with:
ref: main
- name: Update README.md
if: steps.prep.outputs.release == 'true'
id: update-readme
run: |
# Replace supported latest tags in README.md
if [ "${{ steps.prep.outputs.version }}" != "edge" ]; then
sed -i '/- `latest`.*<!-- latest tag -->/c- ${{ steps.prep.outputs.readme_tags }} <!-- latest tag -->' README.md
fi
# Replace supported edge tags in README.md
if [ "${{ steps.prep.outputs.version }}" == "edge" ]; then
sed -i '/- `edge`.*<!-- edge tag -->/c- ${{ steps.prep.outputs.readme_tags }} <!-- edge tag -->' README.md
fi
- name: Check for modified files
if: steps.prep.outputs.release == 'true'
id: git-check
run: echo modified=$([ -z "`git status --porcelain`" ] && echo "false" || echo "true") >> $GITHUB_OUTPUT
- name: Commit updated README.md
if: steps.git-check.outputs.modified == 'true' && steps.prep.outputs.release == 'true'
run: |
git config user.name 'github-actions[bot]'
git config user.email 'github-actions[bot]@users.noreply.github.com'
git add README.md
git commit -m "docs(README): update supported tags"
git push
# Temp fix
# https://github.com/docker/build-push-action/issues/252
# https://github.com/moby/buildkit/issues/1896
- name: Move cache
run: |
rm -rf /tmp/.buildx-cache
mv /tmp/.buildx-cache-new /tmp/.buildx-cache