-
Notifications
You must be signed in to change notification settings - Fork 6
213 lines (181 loc) · 5.91 KB
/
pipeline-docker-cloud.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
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
name: Pipeline using Docker cloud services
on:
push:
branches:
- main
tags:
- '*'
pull_request:
workflow_dispatch:
env:
DOCKERHUB_ORG_NAME: dockerdevrel
IMAGE_NAME: catalog-service-node
DBC_BUILDER_NAME: dockerdevrel/demo-builder
jobs:
prettier:
name: "Validate code formatting"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
- name: Install dependencies
run: yarn install
- name: Run Prettier
run: yarn run prettier-check
unit-test:
name: "Run tests"
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: yarn
- name: Install dependencies
run: yarn install
- name: Run unit tests
run: yarn unit-test
integration-test:
name: "Run integration tests"
needs: [ prettier, unit-test ]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: lts/*
cache: yarn
- name: Install dependencies
run: yarn install
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Setup Testcontainers Cloud Client
uses: atomicjar/testcontainers-cloud-setup-action@v1
with:
token: ${{ secrets.TC_CLOUD_TOKEN }}
- name: Run integration tests
run: yarn run integration-test
build:
name: Build and push image
needs: [unit-test, integration-test]
runs-on: ubuntu-latest
permissions:
pull-requests: write
outputs:
IMAGE_TAGS: ${{ toJSON( fromJSON(steps.meta.outputs.json).tags ) }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up containerd
uses: docker/setup-docker-action@v4
with:
set-host: true
daemon-config: |
{
"features": {
"containerd-snapshotter": true
}
}
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Determine image tags and labels
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.DOCKERHUB_ORG_NAME }}/${{ env.IMAGE_NAME }}
tags: |
type=ref,enable=true,event=branch,suffix=--{{sha}}
type=ref,enable=true,event=branch,suffix=--latest
type=ref,event=tag
type=ref,event=pr
type=raw,value=latest,enable={{is_default_branch}}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
with:
version: "lab:latest"
driver: cloud
endpoint: ${{ env.DBC_BUILDER_NAME }}
- name: Build and push Docker image
uses: docker/build-push-action@v6
with:
context: .
platforms: ${{ github.event_name == 'pull_request' && 'linux/amd64' || 'linux/amd64,linux/arm64' }}
provenance: mode=max
sbom: true
push: ${{ github.event_name != 'pull_request' }}
load: ${{ github.event_name == 'pull_request' }}
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
- name: Analyze and compare image against production
uses: docker/scout-action@v1
if: ${{ github.event_name == 'pull_request' }}
with:
command: quickview,compare
image: ${{ steps.meta.outputs.tags }}
to-env: production
write-comment: true
organization: ${{ env.DOCKERHUB_ORG_NAME }}
# TODO Update this to include policy once DBC image loading includes attestations
exit-on: vulnerability
stage-deploy:
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
name: Deploy to stage environment
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Do the deploy
run: |
echo "Do the staging deployment here. Would deploy image ${IMAGE_TAG}"
env:
IMAGE_TAG: ${{ fromJSON( needs.build.outputs.IMAGE_TAGS )[0] }}
- name: Update Scout environment
id: docker-scout-environment
uses: docker/scout-action@v1
with:
command: environment
image: ${{ fromJSON( needs.build.outputs.IMAGE_TAGS )[0] }}
environment: stage
organization: ${{ env.DOCKERHUB_ORG_NAME }}
prod-deploy:
if: github.ref_type == 'tag'
name: Deploy to production environment
needs: [build]
runs-on: ubuntu-latest
steps:
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Do the deploy
run: |
echo "Do the production deployment here. Would deploy image ${IMAGE_TAG}"
env:
IMAGE_TAG: ${{ fromJSON( needs.build.outputs.IMAGE_TAGS )[0] }}
- name: Update Scout environment
id: docker-scout-environment
uses: docker/scout-action@v1
with:
command: environment
image: ${{ fromJSON( needs.build.outputs.IMAGE_TAGS )[0] }}
environment: production
organization: ${{ env.DOCKERHUB_ORG_NAME }}