-
-
Notifications
You must be signed in to change notification settings - Fork 11
184 lines (158 loc) · 5.1 KB
/
devops.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
name: DevOps
on:
schedule:
- cron: '5 4 * * 2'
push:
pull_request:
env:
GHCR_REGISTRY: ghcr.io
IMAGE_NAME: llaumgui/php-fpm
LATEST: '8.2'
jobs:
##############################################################################
# Dockerfile tests job
#
test_dockerfiles:
runs-on: ubuntu-latest
name: Linters for Dockerfile
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: hadolint
if: github.event.schedule == ''
uses: hadolint/[email protected]
with:
recursive: true
##############################################################################
# Several linter tests job
#
test_linters:
runs-on: ubuntu-latest
name: Linters and checkstyle
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Use markdownlint-cli2
uses: DavidAnson/markdownlint-cli2-action@v11
with:
config: .markdownlint.yaml
- name: Use editorconfig-checker
uses: editorconfig-checker/action-editorconfig-checker@main
##############################################################################
# Build and tests job
#
build_test:
runs-on: ubuntu-latest
name: Build and test docker images
strategy:
fail-fast: false
matrix:
php-version: ["8.1", "8.2", "8.2-nextcloud"]
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images:
${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build Docker image
uses: docker/build-push-action@v4
with:
context: ${{ matrix.php-version }}
tags: |
${{ github.actor }}/php:${{ matrix.php-version }}
labels: ${{ steps.meta.outputs.labels }}
# Test with Trivy
# https://github.com/aquasecurity/trivy-action
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ github.actor }}/php:${{ matrix.php-version }}
format: 'template'
template: '@/contrib/sarif.tpl'
output: 'trivy-results.sarif'
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
with:
sarif_file: 'trivy-results.sarif'
##############################################################################
# Build and deploy job (only on main)
#
build_deploy:
if: github.ref == 'refs/heads/main'
needs: [
test_dockerfiles,
test_linters,
build_test
]
runs-on: ubuntu-latest
name: Build and deploy docker images
strategy:
fail-fast: false
matrix:
php-version: ["8.1", "8.2", "8.2-nextcloud"]
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
# Login against 2 Docker registries except on PR
# https://github.com/docker/login-action
- name: Log in to Docker Hub
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
- name: Log into registry ${{ env.GHCR_REGISTRY }}
if: github.event_name != 'pull_request'
uses: docker/login-action@v2
with:
registry: ${{ env.GHCR_REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
# Extract metadata (tags, labels) for Docker
# https://github.com/docker/metadata-action
- name: Extract Docker metadata
id: meta
uses: docker/metadata-action@v4
with:
images: |
${{ env.IMAGE_NAME }}
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}
# Build and push Docker image with Buildx (don't push on PR)
# https://github.com/docker/build-push-action
- name: Build and push Docker image
if: matrix.php-version == ${{ env.LATEST }}
uses: docker/build-push-action@v4
with:
context: ${{ matrix.php-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ github.actor }}/php:${{ matrix.php-version }}
${{ github.actor }}/php:latest
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php-version }}
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push Docker image
if: matrix.php-version != ${{ env.LATEST }}
uses: docker/build-push-action@v4
with:
context: ${{ matrix.php-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ github.actor }}/php:${{ matrix.php-version }}
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php-version }}
labels: ${{ steps.meta.outputs.labels }}