-
Notifications
You must be signed in to change notification settings - Fork 17
202 lines (175 loc) · 7.21 KB
/
docker_build.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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
name: Docker Build
on:
workflow_dispatch:
permissions:
id-token: write
contents: read
env:
VAULT_PW: ${{ secrets.VAULT_PW }}
REPORT_COVERAGE: true
DPC_CA_CERT: ${{ secrets.DPC_CA_CERT }}
ENV: "github-ci"
jobs:
docker_build_rails_apps:
runs-on: self-hosted
strategy:
matrix:
ecr_repository: [ web-portal, web-admin, web ]
include:
# note this is confusing, but make ci-web-portal points to dpc-web-portal-test.sh which runs
# docker compose -p ... dpc_web
- ecr_repository: web-portal
make_command: make ci-portal
- ecr_repository: web-admin
make_command: make ci-admin-portal
- ecr_repository: web
make_command: make ci-web-portal
steps:
- name: Install python3
run: sudo dnf install python3
- name: "Checkout code"
uses: actions/checkout@v4
- name: Install docker compose manually
run: |
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.32.4/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chown root:root /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
- name: Build specified app
run: ${{ matrix.make_command }}
- name: gzip the image
run: docker save dpc-${{ matrix.ecr_repository }}:latest | gzip > ${{ runner.temp }}/dpc_${{ matrix.ecr_repository }}_latest.tar.gz
- name: upload tar artifact
uses: actions/upload-artifact@v4
with:
name: dpc-${{ matrix.ecr_repository }}
path: ${{ runner.temp }}/dpc_${{ matrix.ecr_repository }}_latest.tar.gz
retention-days: 1
docker_push_rails_apps:
runs-on: self-hosted
strategy:
matrix:
ecr_repository: [ web-portal, web-admin, web ]
env:
ECR_REPOSITORY: ${{ matrix.ecr_repository }}
needs: docker_build_rails_apps
steps:
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: dpc-${{ matrix.ecr_repository }}
path: ${{ runner.temp }}
- name: Load docker image from artifact download
run: |
docker load --input ${{ runner.temp }}/dpc_${{ matrix.ecr_repository }}_latest.tar.gz
docker image ls -a
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/delegatedadmin/developer/dpc-dev-github-actions
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Push to ECR
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag dpc-$ECR_REPOSITORY:latest $REGISTRY/dpc-$ECR_REPOSITORY:latest
docker tag dpc-$ECR_REPOSITORY:latest $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
docker_build_java:
runs-on: self-hosted
steps:
- name: "Set up Ansible"
run: |
sudo dnf -y install python3 python3-pip
pip install ansible
- name: "Install npm for Postman tests"
run: |
sudo dnf -y install nodejs
npm --version
- name: Install docker compose manually
run: |
sudo mkdir -p /usr/local/lib/docker/cli-plugins
sudo curl -SL https://github.com/docker/compose/releases/download/v2.32.4/docker-compose-linux-x86_64 -o /usr/local/lib/docker/cli-plugins/docker-compose
sudo chown root:root /usr/local/lib/docker/cli-plugins/docker-compose
sudo chmod +x /usr/local/lib/docker/cli-plugins/docker-compose
- name: "Set up JDK 11"
uses: actions/setup-java@v3
with:
java-version: "11"
distribution: "corretto"
cache: maven
- name: Install Maven 3.6.3
run: |
export PATH="$PATH:/opt/maven/bin"
echo "PATH=$PATH" >> $GITHUB_ENV
if mvn -v; then echo "Maven already installed" && exit 0; else echo "Installing Maven"; fi
tmpdir="$(mktemp -d)"
curl -LsS https://archive.apache.org/dist/maven/maven-3/3.6.3/binaries/apache-maven-3.6.3-bin.tar.gz | tar xzf - -C "$tmpdir"
sudo rm -rf /opt/maven
sudo mv "$tmpdir/apache-maven-3.6.3" /opt/maven
- name: Clean maven
run: mvn -ntp -U clean
- name: "Checkout code"
uses: actions/checkout@v4
- name: Build ci app
id: api-build
run: |
export PATH=$PATH:~/.local/bin
make ci-app
# add extra commands to log docker containers during failure
- name: Consent Logs
if: ${{ failure() && steps.api-build.outcome == 'failure' }}
run: docker logs start-v1-app-consent-1
- name: Attribution Logs
if: ${{ failure() && steps.api-build.outcome == 'failure' }}
run: docker logs start-v1-app-attribution-1
- name: Aggregation Logs
if: ${{ failure() && steps.api-build.outcome == 'failure' }}
run: docker logs start-v1-app-aggregation-1
- name: Api Logs
if: ${{ failure() && steps.api-build.outcome == 'failure' }}
run: docker logs start-v1-app-api-1
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ vars.AWS_REGION }}
role-to-assume: arn:aws:iam::${{ secrets.ACCOUNT_ID }}:role/delegatedadmin/developer/dpc-dev-github-actions
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: ECR (1 of 4) - Push API
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: api
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag $REGISTRY/dpc-$ECR_REPOSITORY:latest $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
- name: ECR (2 of 4) - Push Attribution
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: attribution
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag $REGISTRY/dpc-$ECR_REPOSITORY:latest $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
- name: ECR (3 of 4) - Push Aggregation
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: aggregation
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag $REGISTRY/dpc-$ECR_REPOSITORY:latest $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
- name: ECR (4 of 4) - Push Consent
env:
REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: consent
IMAGE_TAG: ${{ github.sha }}
run: |
docker tag $REGISTRY/dpc-$ECR_REPOSITORY:latest $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG
docker push $REGISTRY/dpc-$ECR_REPOSITORY:$IMAGE_TAG