-
Notifications
You must be signed in to change notification settings - Fork 6
187 lines (153 loc) · 5.8 KB
/
ci.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
name: CI
on:
push:
branches:
- 'release/**'
pull_request:
jobs:
build-amd64:
name: Build PHP Image amd64
runs-on: ubuntu-latest
continue-on-error: false
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.0.0
with:
dockerfile: "Dockerfile"
format: "tty"
no-color: "true"
output-file: "/dev/stdout"
- name: "Build Alpine"
run: >
./build_images.sh temporary-build-image linux/amd64
- name: "Export image"
run: mv dockercache amdcache
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: amdcache
path: amdcache
retention-days: 1
build-arm64:
name: Build PHP Image arm64
runs-on: ARM64
continue-on-error: false
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: Lint Dockerfile
uses: hadolint/hadolint-action@v3.0.0
with:
dockerfile: "Dockerfile"
format: "tty"
no-color: "true"
output-file: "/dev/stdout"
- name: "Build Alpine"
run: >
./build_images.sh temporary-build-image linux/arm64/v8
- name: "Export image"
run: mv dockercache armcache
- name: 'Upload Artifact'
uses: actions/upload-artifact@v3
with:
name: armcache
path: armcache
retention-days: 1
upload:
name: Upload PHP Image
runs-on: ubuntu-latest
needs:
- build-arm64
- build-amd64
continue-on-error: false
steps:
- name: "Checkout code"
uses: actions/checkout@v3
- name: Download amd64
uses: actions/download-artifact@v3
with:
name: amdcache
path: amdcache
- name: Download arm64
uses: actions/download-artifact@v3
with:
name: armcache
path: armcache
- name: "Create docker cache"
run: >
cp -rf amdcache dockercache
- name: "Reload build cache for amd64"
run: >
./build_images.sh temporary-build-image linux/amd64
- name: "Smoke test with php -v"
run: docker run --pull=never --rm -t temporary-build-image-linux-amd64 php -v
- name: "PHP_VERSION Env"
run: echo "PHP_VERSION=`docker run --pull=never --rm -t temporary-build-image-linux-amd64 php --version | head -n 1 | cut -f 2 -d ' '``docker run --pull=never --rm -t temporary-build-image-linux-amd64 php --version | grep 'ZTS' >/dev/null && echo '-zts' || echo ''`" >> $GITHUB_ENV
- name: Tag also with php:${{ env.PHP_VERSION }}
run: docker tag temporary-build-image-linux-amd64 php-${{ env.PHP_VERSION }}
- name: "Check Alpine -i"
run: docker run --pull=never --rm -t php-${{ env.PHP_VERSION }} php -i
- name: "Check Alpine -v"
run: docker run --pull=never --rm -t php-${{ env.PHP_VERSION }} php -v
- name: "Run Tests"
run: tests/run_tests.sh
env:
DOCKER_REGISTRY_IMAGE: "temporary-build-image-linux-amd64"
- name: Run Alpine Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: php-${{ env.PHP_VERSION }}
format: 'table'
exit-code: '0' # we don't break the build if vulnerabilities are included!
ignore-unfixed: true
vuln-type: 'os,library'
severity: 'CRITICAL,HIGH'
- if: contains(github.ref, 'refs/heads/release/')
name: Run Alpine Trivy vulnerability scanner and upload to github security tab
uses: aquasecurity/trivy-action@master
with:
image-ref: php-${{ env.PHP_VERSION }}
format: 'sarif'
output: 'trivy-results.sarif'
- if: contains(github.ref, 'refs/heads/release/')
name: Upload Alpine Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
#
- if: contains(github.ref, 'refs/heads/release/')
name: Run Trivy in GitHub SBOM mode and submit results to Dependency Snapshots
uses: aquasecurity/trivy-action@master
with:
format: 'github'
output: 'dependency-results.sbom.json'
image-ref: 'temporary-build-image-linux-amd64'
github-pat: ${{ secrets.PAT }}
- if: contains(github.ref, 'refs/heads/release/')
name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- if: contains(github.ref, 'refs/heads/release/')
name: Login to Quay.io
uses: docker/login-action@v2
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_PASSWORD }}
- if: contains(github.ref, 'refs/heads/release/')
name: Login to ghcr.io
uses: docker/login-action@v2
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- if: contains(github.ref, 'refs/heads/release/')
name: "Build and Push Multi Arch PHP"
env:
GHCR_DOCKER_IMAGE_NAME: ghcr.io/endava/docker-php:${{ env.PHP_VERSION }}
QUAY_DOCKER_IMAGE_NAME: quay.io/endava/php:${{ env.PHP_VERSION }}
run: ./build_and_push_multi_arch_images.sh endava/php:${{ env.PHP_VERSION }}