-
Notifications
You must be signed in to change notification settings - Fork 8
199 lines (191 loc) · 5.92 KB
/
cd-bepinex.yml
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
# =================================================================================================
name: "BepInEx"
# =================================================================================================
on:
workflow_dispatch: {}
workflow_run:
workflows: [ "Server" ]
types:
- completed
branches:
- develop
- stable
paths:
- .github/workflows/cd-bepinex.yml
- images/bepinex/**/*
- images/bepinex/*
pull_request:
paths:
- .github/workflows/cd-bepinex.yml
- images/bepinex/**/*
- images/bepinex/*
# =================================================================================================
env:
image_name: "adaliszk/valheim-server"
# =================================================================================================
jobs:
#
# STAGE: LINT
#
lint:
strategy:
fail-fast: false
matrix:
tag: [ "bepinex" ]
runs-on: ubuntu-latest
name: "Lint"
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
name: "Shellcheck"
uses: ludeeus/action-shellcheck@master
with:
scandir: "./images/${{ matrix.tag }}"
-
name: "Hadolint"
uses: brpaz/[email protected]
with:
dockerfile: "./images/${{ matrix.tag }}/Dockerfile"
#
# STAGE: BUILD
#
build:
name: "Build"
runs-on: ubuntu-latest
needs: [ "lint" ]
strategy:
matrix:
tag: [ "bepinex" ]
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
name: "Get the tag from Dockertag"
run: |
cat ./images/${{ matrix.tag }}/Dockertag > ${{ matrix.tag }}.tags
-
name: "Resolve Cache Hash"
env:
hash_path: "./images/${{ matrix.tag }}"
run: |
IMAGE_TAG=${{ hashFiles( env.hash_path ) }}
echo "${IMAGE_TAG}" > ${{ matrix.tag }}.hash
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_ENV
-
id: docker-cache
name: "Use Docker Cache"
uses: actions/cache@v2
with:
key: cd-modded-${{ matrix.tag }}-${{ env.image_tag }}
path: |
${{ matrix.tag }}.*
-
if: steps.docker-cache.outputs.cache-hit == 'true'
name: "Load the saved Image"
run: |
docker load < ${{ matrix.tag }}.tar.gz
-
if: steps.docker-cache.outputs.cache-hit != 'true'
name: "Build :${{ matrix.tag }}"
run: |
docker build -t ${{ env.image_name }}:${{ env.image_tag }} ./images/${{ matrix.tag }}
docker save ${{ env.image_name }}:${{ env.image_tag }} > ${{ matrix.tag }}.tar.gz
-
name: "Tag for the Security Scan"
run: |
docker tag ${{ env.image_name }}:${{ env.image_tag }} ${{ env.image_name }}:${{ matrix.tag }}
-
name: "Run Trivy vulnerability scanner"
uses: aquasecurity/trivy-action@master
env:
source_image: "${{ env.image_name }}:${{ matrix.tag }}"
with:
image-ref: '${{ env.source_image }}'
format: 'template'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif'
severity: 'CRITICAL,HIGH'
-
name: "Upload Trivy scan results to GitHub Security tab"
uses: github/codeql-action/upload-sarif@v1
with:
sarif_file: 'trivy-results.sarif'
#
# PUSH STAGE
#
push:
name: "Push"
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/develop' || github.ref == 'refs/heads/stable'
needs: [ "build" ]
strategy:
fail-fast: false
matrix:
registry: [ "docker.io", "quay.io", "ghcr.io" ]
tag: [ "bepinex" ]
include:
-
registry: "docker.io"
registry_username: "DOCKERHUB_USERNAME"
registry_password: "DOCKERHUB_TOKEN"
registry_url: ""
image_prefix: ""
image_suffix: ""
-
registry: "quay.io"
registry_username: "QUAY_USERNAME"
registry_password: "QUAY_TOKEN"
registry_url: "quay.io"
image_prefix: "quay.io/"
image_suffix: ""
-
registry: "ghcr.io"
registry_username: "GHCR_USERNAME"
registry_password: "GHCR_PASSWORD"
registry_url: "ghcr.io"
image_prefix: "ghcr.io/"
image_suffix: ""
steps:
-
name: "Checkout"
uses: actions/checkout@v2
-
name: "Resolve Cache Hash"
env:
hash_path: "./images/${{ matrix.tag }}"
run: |
IMAGE_TAG=${{ hashFiles( env.hash_path ) }}
echo "image_tag=${IMAGE_TAG}" >> $GITHUB_ENV
-
id: docker-cache
name: "Use Docker Cache"
uses: actions/cache@v2
env:
hash_path: "./images/${{ matrix.tag }}"
with:
key: cd-modded-${{ matrix.tag }}-${{ env.image_tag }}
path: |
${{ matrix.tag }}.*
-
name: "Load the saved Image"
run: |
docker load < ${{ matrix.tag }}.tar.gz
-
name: "Login to ${{ matrix.registry }}"
uses: docker/login-action@v1
with:
registry: ${{ matrix.registry_url }}
username: ${{ secrets[matrix.registry_username] }}
password: ${{ secrets[matrix.registry_password] }}
-
name: "Push ${{ matrix.registry_name }} :${{ matrix.tag }}"
continue-on-error: true
env:
source_image: "${{ env.image_name }}:${{ env.image_tag }}"
target_image: "${{ matrix.image_prefix }}${{ env.image_name }}${{ matrix.image_suffix }}"
run: |
cat ${{ matrix.tag }}.tags | tr \\n \\0 | xargs -0 -I '###' -n1 docker tag ${{ env.source_image }} ${{ env.target_image }}:###
cat ${{ matrix.tag }}.tags | tr \\n \\0 | xargs -0 -I '###' -n1 docker push ${{ env.target_image }}:###