-
Notifications
You must be signed in to change notification settings - Fork 7
160 lines (142 loc) · 5.72 KB
/
publish-prerelease-docker.yaml
File metadata and controls
160 lines (142 loc) · 5.72 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
name: Publish Docker
on:
workflow_dispatch:
push:
tags:
- 'v*.*.*'
jobs:
check-build-steps:
name: Check if build and push should be performed
runs-on: ubuntu-latest
timeout-minutes: 5
outputs:
dockerhub-enable: ${{ steps.dockerhub.outputs.dockerhub-publish }}
ghcr-enable: ${{ steps.check-ghcr.outputs.enable }}
build-and-push-enable: ${{ steps.check-build-and-push.outputs.enable }}
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Determine if images should be published to DockerHub
id: dockerhub
run: |
# check if a release branch, or main, or a tag
if [[ "${{ github.ref }}" =~ ^refs/heads/release([0-9]+)$ || "${{ github.ref }}" == "refs/heads/main" || "${{ github.ref }}" == refs/tags/* ]]
then
DOCKERHUB_PUBLISH="1"
else
DOCKERHUB_PUBLISH="0"
fi
# debug output
echo "dockerhub-publish $DOCKERHUB_PUBLISH"
echo "dockerhub-publish=$DOCKERHUB_PUBLISH" >> $GITHUB_OUTPUT
- name: Check if push to GHCR is enabled
id: check-ghcr
env:
GHCR_ENABLED: ${{ secrets.GHCR_ENABLED }}
run: |
echo "Enable push to GHCR: ${{ env.GHCR_ENABLED != '' }}"
echo "enable=${{ env.GHCR_ENABLED != '' }}" >> $GITHUB_OUTPUT
- name: Check if there is access to repo secrets (needed for build and push)
if: steps.dockerhub.outputs.dockerhub-publish == '1' || steps.check-ghcr.outputs.enable == 'true'
id: check-build-and-push
env:
SECRET_ACCESS: ${{ secrets.DOCKERHUB_USERNAME }}
run: |
echo "Enable build and push: ${{ env.SECRET_ACCESS != '' }}"
echo "enable=${{ env.SECRET_ACCESS != '' }}" >> $GITHUB_OUTPUT
build:
name: Build and publish docker image for ${{ matrix.repo }}
runs-on: ubuntu-latest
timeout-minutes: 15
needs:
- check-build-steps
strategy:
matrix:
repo: [package-manager, workforce, http-server, quantel-http-transformer-proxy, worker]
steps:
- uses: actions/checkout@v5
with:
persist-credentials: false
- name: Get the docker tag for GHCR
id: ghcr-tag
if: needs.check-build-steps.outputs.build-and-push-enable == 'true'
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/${{ github.repository }}-${{ matrix.repo}}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=nightly,enable={{is_default_branch}}
- name: Get the docker tag for DockerHub
id: dockerhub-tag
if: needs.check-build-steps.outputs.build-and-push-enable == 'true'
uses: docker/metadata-action@v5
with:
images: |
sofietv/package-manager-${{ matrix.repo}}
tags: |
type=schedule
type=ref,event=branch
type=ref,event=tag
type=raw,value=latest,enable={{is_default_branch}}
type=raw,value=nightly,enable={{is_default_branch}}
- name: Set up Docker Buildx
if: needs.check-build-steps.outputs.build-and-push-enable == 'true'
uses: docker/setup-buildx-action@v3
- name: Login to DockerHub
if: needs.check-build-steps.outputs.build-and-push-enable == 'true' && needs.check-build-steps.outputs.dockerhub-enable == '1'
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Login to GitHub Container Registry
if: needs.check-build-steps.outputs.build-and-push-enable == 'true' && needs.check-build-steps.outputs.ghcr-enable == 'true'
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Build and push to GHCR
if: needs.check-build-steps.outputs.build-and-push-enable == 'true' && needs.check-build-steps.outputs.ghcr-enable == 'true'
uses: docker/build-push-action@v6
with:
context: .
file: apps/${{ matrix.repo}}/app/Dockerfile
push: true
provenance: false
labels: ${{ steps.ghcr-tag.outputs.labels }}
tags: '${{ steps.ghcr-tag.outputs.tags }}'
- name: Build and push to DockerHub
if: needs.check-build-steps.outputs.build-and-push-enable == 'true' && needs.check-build-steps.outputs.dockerhub-enable == '1'
uses: docker/build-push-action@v6
with:
context: .
file: apps/${{ matrix.repo}}/app/Dockerfile
push: true
provenance: false
labels: ${{ steps.dockerhub-tag.outputs.labels }}
tags: '${{ steps.dockerhub-tag.outputs.tags }}'
trivy-scanning:
name: Run Trivy scan for ${{ matrix.repo }}
uses: nrkno/github-workflow-docker-build-push/.github/workflows/workflow.yaml@v4.5.0
strategy:
matrix:
repo: [package-manager, workforce, http-server, quantel-http-transformer-proxy]
with:
runs-on: "['ubuntu-latest']"
registry-url: ghcr.io
name: sofie-automation/sofie-package-manager
# Don't actually push any images, this is just for trivy scanning for now
push: false
trivy-severity: 'CRITICAL'
trivy-summary-enabled: true
trivy-sbom-enabled: true
dockerfile: apps/${{ matrix.repo }}/app/Dockerfile
secrets:
registry-username: ${{ github.repository_owner }}
registry-password: ${{ secrets.GITHUB_TOKEN }}
token: ${{ secrets.GITHUB_TOKEN }}