-
-
Notifications
You must be signed in to change notification settings - Fork 11
166 lines (162 loc) · 5.35 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
name: DevOps
on:
schedule:
- cron: '5 4 * * 2'
push:
pull_request:
env:
GHCR_REGISTRY: ghcr.io
IMAGE_NAME: llaumgui/php
LATEST: '8.3'
jobs:
##############################################################################
# Dockerfile tests job
#
test_dockerfiles:
runs-on: ubuntu-latest
name: Linters for Dockerfile
steps:
- name: Git checkout
uses: actions/checkout@v4
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@v4
with:
fetch-depth: 0
- name: Use markdownlint-cli2
uses: DavidAnson/markdownlint-cli2-action@v17
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.2", "8.3", "8.3-nextcloud"]
steps:
- name: Git checkout
uses: actions/checkout@v4
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@v5
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@v6
with:
context: ${{ matrix.php-version }}
tags: |
${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
cache-to: type=inline
# Test with Trivy
# https://github.com/aquasecurity/trivy-action
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
image-ref: ${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
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@v3
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.2", "8.3", "8.3-nextcloud"]
steps:
- name: Git checkout
uses: actions/checkout@v4
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@v3
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@v3
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@v5
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@v6
with:
context: ${{ matrix.php-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
${{ env.IMAGE_NAME }}:latest
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:latest
labels: ${{ steps.meta.outputs.labels }}
cache-from: type=registry,ref=${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
cache-to: type=inline
- name: Build and push Docker image
if: ${{ matrix.php-version != env.LATEST }}
uses: docker/build-push-action@v6
with:
context: ${{ matrix.php-version }}
push: ${{ github.event_name != 'pull_request' }}
tags: |
${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
${{ env.GHCR_REGISTRY }}/${{ env.IMAGE_NAME }}:${{ matrix.php-version }}-fpm
labels: ${{ steps.meta.outputs.labels }}