Skip to content

Merge pull request #10 from onyphe/dependabot/github_actions/actions/… #10

Merge pull request #10 from onyphe/dependabot/github_actions/actions/…

Merge pull request #10 from onyphe/dependabot/github_actions/actions/… #10

Workflow file for this run

name: Docker
on:
push:
# The upstream repository's default branch is master; the fork uses main.
branches: [main, master]
tags: ["v*"]
pull_request:
workflow_dispatch:
concurrency:
group: docker-${{ github.ref }}
cancel-in-progress: true
permissions:
contents: read
jobs:
image:
name: Build, test and publish the image
runs-on: ubuntu-latest
permissions:
contents: read
packages: write # push to GHCR
steps:
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false
- name: Set up QEMU
uses: docker/setup-qemu-action@c7c53464625b32c7a7e944ae62b3e17d2b600130 # v3.7.0
- name: Set up Buildx
uses: docker/setup-buildx-action@8d2750c68a42422c14e847fe6c8ac0403b4cbd6f # v3.12.0
# Single-arch build loaded into the local daemon, so the image can be
# exercised before anything is published. Buildx cannot --load a
# multi-arch manifest, hence the separate step; the multi-arch build
# below reuses this layer cache, so it costs little.
- name: Build for testing
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
platforms: linux/amd64
load: true
push: false
tags: pyonyphe:test
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Smoke-test the image
run: |
docker run --rm pyonyphe:test --version
docker run --rm pyonyphe:test search --help
# The CLI must fail cleanly with exit code 2, not crash, when no key
# is configured. `|| status=$?` is required: the step runs under
# `set -e`, so a bare non-zero command would abort the script here.
status=0
docker run --rm pyonyphe:test user || status=$?
test "$status" -eq 2
# And it must not run as root.
test "$(docker run --rm --entrypoint id pyonyphe:test -u)" = "1000"
# Pull requests stop here: they build and test, they never publish.
- name: Log in to GHCR
if: github.event_name != 'pull_request'
uses: docker/login-action@c94ce9fb468520275223c153574b00df6fe4bcc9 # v3.7.0
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Compute tags and labels
if: github.event_name != 'pull_request'
id: meta
uses: docker/metadata-action@c299e40c65443455700f0fdfc63efafe5b349051 # v5.10.0
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=ref,event=branch
type=sha,format=short
type=semver,pattern={{version}}
type=semver,pattern={{major}}.{{minor}}
type=semver,pattern={{major}}
type=raw,value=latest,enable=${{ startsWith(github.ref, 'refs/tags/v') }}
- name: Build and push
if: github.event_name != 'pull_request'
uses: docker/build-push-action@10e90e3645eae34f1e60eeb005ba3a3d33f178e8 # v6.19.2
with:
context: .
platforms: linux/amd64,linux/arm64
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
cache-to: type=gha,mode=max