-
Notifications
You must be signed in to change notification settings - Fork 0
223 lines (201 loc) · 7.5 KB
/
main.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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
name: "Main Workflow"
on:
push:
tags:
- "**"
branches:
- master
pull_request:
env:
JAVA_VERSION: openjdk@1.11
SCALA_VERSION: "2.13"
ATALA_GITHUB_ACTOR: ${{ secrets.ATALA_GITHUB_ACTOR }}
ATALA_GITHUB_TOKEN: ${{ secrets.ATALA_GITHUB_TOKEN }}
jobs:
build-prism-backend:
name: "Build Prism Backend"
runs-on: ubuntu-20.04
defaults:
run:
working-directory: prism-backend
services:
postgres:
image: postgres:13.3
env:
POSTGRES_USER: postgres
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
# Set health checks to wait until postgres has started
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Setup Scala
uses: olafurpg/setup-scala@v10
with:
java-version: ${{ env.JAVA_VERSION }}
- name: Coursier cache
uses: coursier/cache-action@v6
- name: Show Version
run: sbt version
- name: Test Scala code is properly formatted
run: sbt scalafmtCheckAll
- name: Test terraform code format
run: terraform fmt -check -recursive
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Obtain Cardano db sync and wallet endpoints config
id: cardano
run: ../.github/generate_cardano_variables.sh
- name: Compile and test prism-backend components
run: sbt compile test:compile coverage test pushRemoteCache
env:
POSTGRES_TEST_HOST: localhost:5432
POSTGRES_TEST_DB: postgres
POSTGRES_TEST_USER: postgres
POSTGRES_TEST_PASSWORD: postgres
NODE_CARDANO_DB_SYNC_HOST: ${{ steps.cardano.outputs.db-sync-host }}
NODE_CARDANO_DB_SYNC_DATABASE: ${{ steps.cardano.outputs.db-sync-database }}
NODE_CARDANO_DB_SYNC_USERNAME: ${{ steps.cardano.outputs.db-sync-username }}
NODE_CARDANO_DB_SYNC_PASSWORD: ${{ steps.cardano.outputs.db-sync-password }}
NODE_CARDANO_WALLET_API_HOST: ${{ steps.cardano.outputs.wallet-api-host }}
NODE_CARDANO_WALLET_API_PORT: ${{ steps.cardano.outputs.wallet-api-port }}
NODE_CARDANO_WALLET_ID: ${{ secrets.NODE_CARDANO_WALLET_ID }}
NODE_CARDANO_WALLET_PASSPHRASE: ${{ secrets.NODE_CARDANO_WALLET_PASSPHRASE }}
NODE_CARDANO_CONFIRMATION_BLOCKS: ${{ secrets.NODE_CARDANO_CONFIRMATION_BLOCKS }}
NODE_CARDANO_PAYMENT_ADDRESS: ${{ secrets.NODE_CARDANO_PAYMENT_ADDRESS }}
- name: Assemble fat JARs
run: sbt assembly
- name: Upload SBT remote cache
uses: actions/upload-artifact@v2
with:
name: sbt-backend-remote-cache
path: /tmp/backend-remote-cache
- name: Generate code coverage reports
if: always()
run: sbt coverageReport coverageAggregate
- name: Aggregate test reports
if: always()
run: |
for reports in `find -name test-reports`; do
project=${reports%/target/*}
dest=target/test-reports/$project
mkdir -p $dest
cp $reports/* $dest
done
- name: Publish Backend Unit Test Results
if: always()
uses: EnricoMi/publish-unit-test-result-action@v1
with:
files: "prism-backend/target/test-reports/**/TEST-*.xml"
check_run_annotations_branch: "*"
deploy-ecr-images:
strategy:
matrix:
image:
["node", "connector", "management-console", "vault", "prism-lb-envoy"]
name: Deploy ECR Images
runs-on: ubuntu-20.04
needs: build-prism-backend
if: |
github.ref == 'refs/heads/master' ||
github.ref_type == 'tag'
permissions:
packages: write
contents: read
outputs:
tag: ${{ steps.set-tag.outputs.tag }}
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
- name: Install protoc
run: |
archive=protoc-"3.11.4"-linux-x86_64
curl -O -L https://github.com/protocolbuffers/protobuf/releases/download/v"3.11.4"/$archive.zip
sudo unzip -d '/usr/local' $archive.zip 'bin/*' 'include/*'
rm -rf ${archive}.zip
- name: Install protoc-gen-grpc-web
run: |
archive=protoc-gen-grpc-web-1.0.7-linux-x86_64
curl -O -L https://github.com/grpc/grpc-web/releases/download/1.0.7/$archive
chmod +x $archive
sudo mv $archive /usr/local/bin/protoc-gen-grpc-web
- name: Restore Cache
uses: actions/cache@v2
with:
key: cv-cache-v5-${{ hashFiles('prism-backend/build.sbt') }}-${{ hashFiles('prism-backend/project/PrismBuild.scala') }}-${{ hashFiles('prism-backend/project/Dependencies.scala') }}-${{ hashFiles('prism-backend/project/plugins.sbt') }}
path: |
~/.cache/coursier
~/.ivy2
~/.m2
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@13d241b293754004c80624b5567555c4a39ffbe3
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_DEFAULT_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@aaf69d68aa3fb14c1d5a6be9ac61fe15b48453a2
- name: Set Docker image tag
id: set-tag
run: |
if [[ ${GITHUB_REF_TYPE} == "tag" ]]
then
tag=$(echo $GITHUB_REF_NAME)
else
branchPrefix=$(git branch --show-current)
shaShort=$(git rev-parse --short HEAD)
tag="${branchPrefix}-${shaShort}"
fi
echo "Image tag set to $TAG"
echo "::set-output name=tag::$tag"
- name: Setup Github Container registry credentials
run: docker login ghcr.io -u atala-dev -p ${{ secrets.ATALA_GITHUB_TOKEN }}
- name: Build and publish Docker image
if: |
matrix.image == 'node' ||
matrix.image == 'connector' ||
matrix.image == 'management-console' ||
matrix.image == 'vault'
run: |
cd prism-backend
export TAG="${{ steps.set-tag.outputs.tag }}"
if [[ "${{ github.ref }}" == "refs/heads/master" ]]; then
export PUBLISH_LATEST_TAG=true
fi
sbt "${{ matrix.image }}/dockerBuildAndPush"
- name: Build and push prism-lb-envoy
if: matrix.image == 'prism-lb-envoy'
run: |
cd prism-backend/infra/docker/prism-lb-envoy
./build.sh -b
./build.sh -p
workflow-dispach:
name: "Workflow Dispach"
runs-on: ubuntu-20.04
if: github.ref_type != 'tag'
needs: deploy-ecr-images
steps:
- name: Workflow Dispatch
uses: benc-uk/workflow-dispatch@v1
with:
workflow: Manual Deploy
repo: input-output-hk/atala-prism-infra
token: ${{ secrets.ATALA_GITHUB_TOKEN }}
inputs: '{"environment": "${{ github.ref_name }}", "tag": "${{ needs.deploy-ecr-images.outputs.tag }}"}'
ref: "refs/heads/master"