docker-build #1544
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: docker-build | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}-${{ github.head_ref || github.ref_name }} | |
cancel-in-progress: true | |
on: | |
schedule: | |
- cron: "0 10 * * *" | |
create: | |
tags: | |
- "v*.*.*" | |
push: | |
branches: | |
- "**" | |
tags: | |
- "v*.*.*" | |
release: | |
types: [published] | |
pull_request: | |
branches: | |
- "main" | |
env: | |
TEST_TAG: horaceworblehat/borg-server:test | |
jobs: | |
docker: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout | |
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4 | |
- name: Install cosign | |
uses: sigstore/cosign-installer@dc72c7d5c4d10cd6bcb8cf6e3fd625a9e5e537da # v3.7.0 | |
- name: Docker meta | |
id: meta | |
uses: docker/metadata-action@369eb591f429131d6889c46b94e711f089e6ca96 # v5 | |
with: | |
# list of Docker images to use as base name for tags | |
images: | | |
horaceworblehat/borg-server | |
ghcr.io/AnotherStranger/borg-server | |
# generate Docker tags based on the following events/attributes | |
tags: | | |
type=schedule,value=latest | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=semver,pattern={{major}} | |
type=sha,format=long | |
type=raw,value=latest,enable={{is_default_branch}} | |
- name: Set up QEMU | |
uses: docker/setup-qemu-action@53851d14592bedcffcf25ea515637cff71ef929a # v3 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@6524bf65af31da8d45b59e8c27de4bd072b392f5 # v3 | |
- name: Login to Docker Hub | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 | |
if: github.event_name != 'pull_request' | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3 | |
if: github.event_name != 'pull_request' | |
with: | |
registry: ghcr.io | |
username: ${{ github.repository_owner }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Get Git commit timestamps | |
run: echo "TIMESTAMP=$(git log -1 --pretty=%ct)" >> $GITHUB_ENV | |
- name: Build Testimage | |
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6 | |
env: | |
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} | |
with: | |
load: true | |
tags: ${{ env.TEST_TAG }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Run small selftest on build container image | |
run: docker run -v "./tests/selftest.sh:/selftest.sh" "${{ env.TEST_TAG }}" ./selftest.sh | |
- name: Build and push | |
uses: docker/build-push-action@67a2d409c0a876cbe6b11854e3e25193efe4e62d # v6 | |
id: docker-build | |
env: | |
SOURCE_DATE_EPOCH: ${{ env.TIMESTAMP }} | |
with: | |
context: . | |
push: ${{ github.event_name != 'pull_request' }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
platforms: linux/386,linux/amd64,linux/arm/v7,linux/arm64/v8,linux/ppc64le,linux/s390x | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Sign image with a key | |
run: | | |
images="" | |
for tag in ${TAGS}; do | |
images+="${tag}@${DIGEST} " | |
done | |
cosign sign --yes --key env://COSIGN_PRIVATE_KEY ${images} | |
if: ${{ github.event_name != 'pull_request' }} | |
env: | |
DIGEST: ${{ steps.docker-build.outputs.digest }} | |
TAGS: ${{ steps.meta.outputs.tags }} | |
COSIGN_PRIVATE_KEY: ${{ secrets.COSIGN_PRIVATE_KEY }} | |
COSIGN_PASSWORD: ${{ secrets.COSIGN_PASSWORD }} | |
- name: Run Trivy vulnerability scanner | |
uses: aquasecurity/trivy-action@master | |
if: ${{ github.event_name != 'pull_request' }} | |
with: | |
image-ref: "ghcr.io/anotherstranger/borg-server:sha-${{ github.sha }}" | |
format: 'sarif' | |
output: "trivy-results.sarif" | |
severity: "CRITICAL,HIGH" | |
- name: Upload Trivy scan results to GitHub Security tab | |
uses: github/codeql-action/upload-sarif@b6a472f63d85b9c78a3ac5e89422239fc15e9b3c # v3 | |
if: ${{ github.event_name != 'pull_request' }} | |
with: | |
sarif_file: "trivy-results.sarif" |