-
Notifications
You must be signed in to change notification settings - Fork 0
156 lines (130 loc) · 5.49 KB
/
docker.yml
File metadata and controls
156 lines (130 loc) · 5.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
name: Docker
on:
# Only run on tag updates or manually
#
push:
# Publish semver tags as releases.
tags: [ 'v*.*.*' ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
env:
# Use docker.io for Docker Hub if empty
REGISTRY: ghcr.io
# github.repository as <account>/<repo>
IMAGE_NAME: ${{ github.repository }}
# shared description labels
#
LABEL_TITLE: "WebDyne"
LABEL_DESCRIPTION: "WebDyne is a Perl based dynamic HTML engine"
LABEL_LICENSE: "Artistic-1.0-Perl"
jobs:
build-variants:
runs-on: ubuntu-22.04
permissions:
contents: read
packages: write # Required to push to GHCR
id-token: write
strategy:
matrix:
variant: [fedora, alpine, debian]
steps:
# Checkout repo to start build
#
- name: Checkout repository
uses: actions/checkout@v4
# Install the cosign tool except on PR
# https://github.com/sigstore/cosign-installer
- name: Install cosign
if: github.event_name != 'pull_request'
uses: sigstore/cosign-installer@59acb6260d9c0ba8f4a2f9d9b48431a222b68e20 # v3.5.0
with:
cosign-release: 'v2.2.4'
# Apparently need QEMU for some reason even though using Buildx
#
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
# Setup BuildX
#
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Log in to GitHub Container Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ github.token }}
# Get branch we are on
#
- name: Determine branch that created tag
id: branch
run: |
git fetch --all --quiet
BRANCH=$(git branch -r --contains "$GITHUB_SHA" | grep -v '\->' | head -n1 | sed 's|origin/||' | xargs)
echo "branch: $BRANCH"
echo "branch=$BRANCH" >> "$GITHUB_OUTPUT"
echo "created=$(date -u +%Y-%m-%dT%H:%M:%SZ)" >> $GITHUB_OUTPUT
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@96383f45573cb7f253c731d3b3ab81c87ef81934 # v5.0.0
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
flavor: |
latest=false
tags: |
type=raw,value=latest,enable=${{ matrix.variant == 'debian' && steps.branch.outputs.branch == 'main' }}
type=raw,value=${{ matrix.variant }}
type=raw,prefix=${{ matrix.variant }}-,value=${{ steps.branch.outputs.branch }}
type=raw,prefix=${{ matrix.variant }}-,value=latest
type=sha,prefix=${{ matrix.variant }}-
type=semver,prefix=${{ matrix.variant }}-,pattern={{version}}
labels: |
org.opencontainers.image.title=${{ env.LABEL_TITLE }}
org.opencontainers.image.description=${{ env.LABEL_DESCRIPTION }}
org.opencontainers.image.license=${{ env.LABEL_LICENSE }}
org.opencontainers.image.created=${{ steps.branch.outputs.created }}
# Debug
#
- name: Debug
run: |
echo "branch:${{ github.ref }}"
echo "branch (calculated):${{ steps.branch.outputs.branch }}"
echo "tags: ${{ steps.meta.outputs.tags }}"
echo "labels: ${{ steps.meta.outputs.labels }}"
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
file: docker/Dockerfile.${{ matrix.variant }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
outputs: type=image,name=target,annotation-index.org.opencontainers.image.description=${{ env.LABEL_DESCRIPTION }}
#annotations: |
# ${{ steps.meta.outputs.labels }}
#annotations: |
# org.opencontainers.image.description=Simple self-contained WebDyne demonstration application
cache-to: type=gha,mode=max
platforms: linux/arm64,linux/amd64
# Sign the resulting Docker image digest except on PRs.
# This will only write to the public Rekor transparency log when the Docker
# repository is public to avoid leaking data. If you would like to publish
# transparency data even for private images, pass --force to cosign below.
# https://github.com/sigstore/cosign
- name: Sign the published Docker image (${{ matrix.variant }})
if: ${{ github.event_name != 'pull_request' }}
env:
# https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
# This step uses the identity token to provision an ephemeral certificate
# against the sigstore community Fulcio instance.
run: echo "${TAGS}" | xargs -I {} cosign sign --yes {}@${DIGEST}