-
Notifications
You must be signed in to change notification settings - Fork 0
177 lines (158 loc) · 5.62 KB
/
build-images.yaml
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
name: Build and Push Docker Images
on:
push:
branches:
- 'main'
- 'develop'
tags:
- '*'
pull_request:
branches:
- 'main'
- 'develop'
env:
AGENT_IMAGE_NAME: humitifier
AGENT_DOCKERFILE_PATH: ./agent/Dockerfile
AGENT_CONTEXT_PATH: ./agent
SERVER_IMAGE_NAME: humitifier-server
SERVER_DOCKERFILE_PATH: ./humitifier-server/Dockerfile
SERVER_CONTEXT_PATH: ./humitifier-server
jobs:
build-and-push-agent:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/centrefordigitalhumanities/humitifier/${{ env.AGENT_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
type=pep440,pattern={{major}}.{{minor}}
- name: Build and push main image
id: build
uses: docker/build-push-action@v6
with:
context: ${{ env.AGENT_CONTEXT_PATH }}
file: ${{ env.AGENT_DOCKERFILE_PATH }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Save Docker image to cache
run: |
docker save ${{ steps.build.outputs.imageid }} | gzip > agent_image.tar.gz
- name: Upload Docker image to cache
uses: actions/cache@v4
with:
path: agent_image.tar.gz
key: ${{ runner.os }}-agent-image-${{ github.sha }}
build-and-push-server:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/centrefordigitalhumanities/humitifier/${{ env.SERVER_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
type=pep440,pattern={{major}}.{{minor}}
- name: Build and push main image
uses: docker/build-push-action@v6
with:
context: ${{ env.SERVER_CONTEXT_PATH }}
file: ${{ env.SERVER_DOCKERFILE_PATH }}
push: ${{ github.event_name != 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
scan-agent:
needs: build-and-push-agent
runs-on: ubuntu-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Download Docker image from cache
uses: actions/cache@v4
with:
path: agent_image.tar.gz
key: ${{ runner.os }}-agent-image-${{ github.sha }}
restore-keys: |
${{ runner.os }}-agent-image-
- name: Load Docker image
run: |
gunzip -c agent_image.tar.gz | docker load
docker ps -a
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/centrefordigitalhumanities/humitifier/${{ env.AGENT_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
- name: Run the Anchore Grype scan action
uses: anchore/scan-action@v5
id: scan
with:
image: ghcr.io/centrefordigitalhumanities/humitifier/${{ env.AGENT_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
fail-build: ${{ github.event_name == 'pull_request' }}
severity-cutoff: critical
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif }}
scan-server:
needs: build-and-push-server
runs-on: ubuntu-latest
permissions:
contents: read # for actions/checkout to fetch code
security-events: write # for github/codeql-action/upload-sarif to upload SARIF results
actions: read # only required for a private repository by github/codeql-action/upload-sarif to get the Action run status
steps:
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: |
ghcr.io/centrefordigitalhumanities/humitifier/${{ env.SERVER_IMAGE_NAME }}
tags: |
type=ref,event=branch
type=ref,event=pr
type=pep440,pattern={{version}}
- name: Run the Anchore Grype scan action
uses: anchore/scan-action@v5
id: scan
with:
image: ghcr.io/centrefordigitalhumanities/humitifier/${{ env.SERVER_IMAGE_NAME }}:${{ steps.meta.outputs.version }}
fail-build: ${{ github.event_name == 'pull_request' }}
severity-cutoff: critical
- name: Upload vulnerability report
uses: github/codeql-action/upload-sarif@v3
with:
sarif_file: ${{ steps.scan.outputs.sarif }}