-
Notifications
You must be signed in to change notification settings - Fork 10
186 lines (145 loc) · 5.47 KB
/
build.yml
File metadata and controls
186 lines (145 loc) · 5.47 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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
# SPDX-FileCopyrightText: © Vegard IT GmbH (https://vegardit.com)
# SPDX-FileContributor: Sebastian Thomschke
# SPDX-License-Identifier: Apache-2.0
# SPDX-ArtifactOfProjectHomePage: https://github.com/vegardit/docker-softhsm2-pkcs11-proxy
#
# https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions
name: Build
on: # https://docs.github.com/en/actions/reference/events-that-trigger-workflows
schedule:
# https://docs.github.com/en/actions/reference/choosing-when-your-workflow-runs/events-that-trigger-workflows
- cron: '0 17 * * 3'
push:
branches-ignore: # build all branches except:
- 'dependabot/**' # prevent GHA triggered twice (once for commit to the branch and once for opening/syncing the PR)
tags-ignore: # don't build tags
- '**'
paths-ignore:
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- '.github/workflows/stale.yml'
pull_request:
paths-ignore:
- '**/*.md'
- '.editorconfig'
- '.git*'
- '.github/*.yml'
- '.github/workflows/stale.yml'
workflow_dispatch:
# https://docs.github.com/en/actions/reference/events-that-trigger-workflows#workflow_dispatch
defaults:
run:
shell: bash
env:
DOCKER_REPO_NAME: softhsm2-pkcs11-proxy
TRIVY_CACHE_DIR: ~/.trivy/cache
jobs:
###########################################################
build:
###########################################################
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
timeout-minutes: 60
permissions:
packages: write
strategy:
matrix:
SOFTHSM_VERSION: [ "latest", "develop" ]
DOCKER_BASE_IMAGE: [ alpine:3, "debian:stable-slim" ]
steps:
- name: "Show: GitHub context"
env:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: printf '%s' "$GITHUB_CONTEXT" | python -m json.tool
- name: "Show: environment variables"
run: env | sort
- name: Git Checkout
uses: actions/checkout@v6 # https://github.com/actions/checkout
- name: Run the sh-checker
uses: luizm/action-sh-checker@master # https://github.com/marketplace/actions/sh-checker
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SHFMT_OPTS: --simplify --keep-padding
with:
sh_checker_comment: true
sh_checker_checkbashisms_enable: true
sh_checker_shfmt_disable: true
- name: Check Alpine Dockerfile
uses: hadolint/hadolint-action@v3.3.0
if: ${{ contains(matrix.DOCKER_BASE_IMAGE, 'alpine') }}
with:
dockerfile: image/alpine.Dockerfile
- name: Check Debian Dockerfile
uses: hadolint/hadolint-action@v3.3.0
if: ${{ contains(matrix.DOCKER_BASE_IMAGE, 'debian') }}
with:
dockerfile: image/debian.Dockerfile
- name: Cache trivy cache
uses: actions/cache@v5
with:
path: ${{ env.TRIVY_CACHE_DIR }}
# https://github.com/actions/cache/issues/342#issuecomment-673371329
key: ${{ runner.os }}-trivy-${{ github.run_id }}
restore-keys: |
${{ runner.os }}-trivy-
- name: Configure fast APT repository mirror
uses: vegardit/fast-apt-mirror.sh@v1
- name: Install dos2unix
run: sudo apt-get install --no-install-recommends -y dos2unix
- name: "Determine if docker images shall be published"
id: docker_push_actions
run: |
# ACT -> https://nektosact.com/usage/index.html#skipping-steps
set -x
if [[ $GITHUB_REF_NAME == 'main' && $GITHUB_EVENT_NAME != 'pull_request' && -z "$ACT" ]]; then
echo "DOCKER_PUSH_GHCR=true" >> "$GITHUB_ENV"
echo "DOCKER_PUSH_GHCR=true" >> $GITHUB_OUTPUT
if [[ -n "${{ secrets.DOCKER_HUB_USERNAME }}" ]]; then
echo "DOCKER_PUSH=true" >> "$GITHUB_ENV"
fi
fi
- name: Login to docker.io
if: ${{ env.DOCKER_PUSH }}
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKER_HUB_USERNAME }}
password: ${{ secrets.DOCKER_HUB_TOKEN }}
- name: Login to ghcr.io
if: ${{ env.DOCKER_PUSH_GHCR }}
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build ${{ env.DOCKER_REPO_NAME }}:${{ matrix.SOFTHSM_VERSION }}
env:
DOCKER_BASE_IMAGE: ghcr.io/dockerhub-mirror/${{ matrix.DOCKER_BASE_IMAGE }}
DOCKER_IMAGE_REPO: ${{ github.repository_owner }}/${{ env.DOCKER_REPO_NAME }}
SOFTHSM_VERSION: ${{ matrix.SOFTHSM_VERSION }}
TRIVY_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: bash build-image.sh
outputs:
DOCKER_PUSH_GHCR: ${{ steps.docker_push_actions.outputs.DOCKER_PUSH_GHCR }}
###########################################################
delete-untagged-images:
###########################################################
runs-on: ubuntu-latest # https://github.com/actions/runner-images#available-images
timeout-minutes: 5
needs: [build]
if: ${{ needs.build.outputs.DOCKER_PUSH_GHCR }}
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false
permissions:
packages: write
steps:
- name: Delete untagged images
uses: dataaxiom/ghcr-cleanup-action@v1
with:
package: ${{ env.DOCKER_REPO_NAME }}
delete-untagged: true
delete-partial-images: true
delete-ghost-images: true
delete-orphaned-images: true
validate: true