-
Notifications
You must be signed in to change notification settings - Fork 0
202 lines (176 loc) · 7.33 KB
/
build-and-publish.yaml
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Build and push
on:
workflow_dispatch:
schedule:
- cron: "49 5 * * *"
push:
branches: ["main"]
# Publish semver tags as releases.
tags: ["v*.*.*"]
pull_request:
branches: ["main"]
env:
# github.repository as <account>/<repo>
IMAGE_NAME: cyberchef
IMAGES: |
docker.io/obeoneorg/cyberchef
ghcr.io/obeone/cyberchef
GIST_ID: 876a9aed55cffad6054360c99ecf4093
jobs:
build:
runs-on: ubuntu-latest
services:
registry:
image: registry:2
ports:
- 5000:5000
permissions:
contents: write
packages: write
# This is used to complete the identity challenge
# with sigstore/fulcio when running outside of PRs.
id-token: write
steps:
- name: Install Cosign
uses: sigstore/cosign-installer@main
- name: Checkout repository
uses: actions/checkout@v3
# Workaround: https://github.com/docker/build-push-action/issues/461
- name: Setup Docker buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
# Login against a Docker registry except on PR
# https://github.com/docker/login-action
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
registry: docker.io
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 }}
# Find latest tag of repository gchoi/cyberchef
- name: Fetch latest release (if not run by a tag push)
uses: gregziegan/fetch-latest-release@v2.0.0
with:
github_token: ${{ github.token }}
repo_path: gchq/CyberChef
id: version
# If not from a tag push
if: github.event_name != 'push' || (github.event_name == 'push' && !startsWith(github.ref, 'refs/tags/'))
- name: Use tag name as version if run on a tag push
run: |
TAG_NAME=$(basename ${GITHUB_REF##*/})
echo ::set-output name=tag_name::${TAG_NAME}
if: github.event_name == 'push' || startsWith(github.ref, 'refs/tags/')
- name: Parse semver string
id: semver_parser
uses: booxmedialtd/ws-action-parse-semver@v1
with:
input_string: "${{ steps.version.outputs.tag_name }}"
- name: Docker metadata
id: meta
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: ${{ env.IMAGES }}
tags: |
type=raw,value=latest,enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
type=ref,event=branch
type=ref,event=pr
type=raw,value=${{ steps.semver_parser.outputs.major }},enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
type=raw,value=${{ steps.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }},enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
type=raw,value=${{ steps.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }}.${{ steps.semver_parser.outputs.patch }},enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
type=raw,value=v${{ steps.semver_parser.outputs.major }},enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
type=raw,value=v${{ steps.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }},enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
type=raw,value=v${{ steps.semver_parser.outputs.major }}.${{ steps.semver_parser.outputs.minor }}.${{ steps.semver_parser.outputs.patch }},enable=${{ github.event_name != 'pull_request' && github.ref == 'refs/heads/main' }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build CyberChef
id: build-base
uses: docker/build-push-action@v6
with:
context: .
file: Dockerfile.build
build-args: |
GIT_TAG=${{ steps.version.outputs.tag_name }}
tags: |
localhost:5000/${{ env.IMAGE_NAME }}:build
labels: ${{ steps.meta.outputs.labels }}
push: true
cache-to: type=gha,mode=max
cache-from: type=gha
# Now we build multiarch packages with Dockerfile.build
- name: Build and push Docker image
id: build-and-push
uses: docker/build-push-action@v6
with:
context: .
push: ${{ github.event_name != 'pull_request' }}
platforms: |
linux/amd64
linux/arm64
linux/i386
linux/armhf
linux/armel
build-args: |
BASE_IMAGE=localhost:5000/${{ env.IMAGE_NAME }}:build
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=gha
- name: Sign the images with GitHub OIDC Token
run: |
set -e
# In variables, "%%*( )" trim whitespace at beggining and end of variable
for image in ${IMAGES}; do
yes | cosign sign "${image%%*( )}@${DIGEST%%*( )}"
done
env:
TAGS: ${{ steps.meta.outputs.tags }}
DIGEST: ${{ steps.build-and-push.outputs.digest }}
COSIGN_EXPERIMENTAL: true
if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
- name: Find last tag
uses: oprypin/find-latest-tag@v1
with:
repository: ${{ github.repository }}
id: latest_tag
- name: Check if tag already exists
uses: mukunku/tag-exists-action@v1.0.0
id: checkTag
with:
tag: ${{ steps.version.outputs.tag_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- if: steps.checkTag.outputs.exists == 'false' && github.event_name != 'pull_request'
name: Create/update tag ${{ steps.version.outputs.tag_name }}
uses: rickstaa/action-create-tag@v1
with:
tag: ${{ steps.version.outputs.tag_name }}
message: Version ${{ steps.version.outputs.tag_name }}
- if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
name: Getting current date
id: date
run: echo "current_date=$(date +%Y-%m-%d)" >> $GITHUB_OUTPUT
- if: github.event_name != 'pull_request' && github.ref == 'refs/heads/main'
name: Create date badge
uses: schneegans/dynamic-badges-action@v1.7.0
with:
auth: ${{ secrets.GIST_SECRET }}
gistID: ${{ env.GIST_ID }}
filename: date.json
label: build date
message: ${{ steps.date.outputs.current_date }}
color: green
- if: ${{ github.event_name != 'pull_request' }}
name: Update Docker Hub description
uses: peter-evans/dockerhub-description@v4
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
repository: ${{ secrets.DOCKERHUB_USERNAME }}/cyberchef