-
Notifications
You must be signed in to change notification settings - Fork 3
191 lines (168 loc) · 5.99 KB
/
base-node-service-jobs.yml
File metadata and controls
191 lines (168 loc) · 5.99 KB
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
name: Base Node Services Build and Deploy
on:
workflow_call:
inputs:
environment:
type: string
default: dev
required: true
service:
type: string
required: true
is_deployment:
type: boolean
default: false
required: true
ecr_alias:
description: "ECR Repository Alias"
type: string
required: false
permissions:
pull-requests: write
id-token: write
contents: read
env:
S3_BUCKET_NAME: test-bucket
LOCALSTACK_URL: http://localhost:4566
DYNAMODB_NAME: local-test-db
DYNAMODB_LOCAL_ENDPOINT: http://localhost:4566
AWS_ACCESS_KEY_ID: LSIA5678901234567890
AWS_SECRET_ACCESS_KEY: LSIA5678901234567890
SERVICE_URL: http://localhost:3000
jobs:
run_tests:
name: Lint, Unit, and Integration
runs-on: ubuntu-latest
steps:
- name: Extract branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- name: Checkout
uses: actions/checkout@v6
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install dependencies
working-directory: ./services/${{ inputs.service }}
run: npm install
# https://github.com/localstack/setup-localstack/issues/65
- name: Install LocalStack manually
run: |
pip install --upgrade pip
pip install localstack==4.14.0
- name: Start LocalStack
uses: LocalStack/setup-localstack@v0.3.1
env:
LOCALSTACK_ACKNOWLEDGE_ACCOUNT_REQUIREMENT: "1" # https://github.com/localstack/setup-localstack/issues/65
with:
install-awslocal: "true"
use-pro: false
image-tag: "4.14.0"
# https://docs.aws.amazon.com/cli/latest/reference/dynamodb/create-table.html
- name: Create AWS resources
run: |
awslocal dynamodb create-table --region ${{ vars.AWS_REGION }} --cli-input-json file://services/ehr-repo/scripts/local-test-db-scheme.json
awslocal s3 mb s3://$S3_BUCKET_NAME --region ${{ vars.AWS_REGION }}
- name: Run Unit Tests and Lint Checks
working-directory: ./services/${{ inputs.service }}
env:
S3_BUCKET_NAME: test-bucket
LOCALSTACK_URL: http://localhost:4566
DYNAMODB_NAME: local-test-db
DYNAMODB_LOCAL_ENDPOINT: http://localhost:4566
AWS_ACCESS_KEY_ID: LSIA5678901234567890
AWS_SECRET_ACCESS_KEY: LSIA5678901234567890
SERVICE_URL: http://localhost:3000
NHS_ENVIRONMENT: local
EHR_URL: http://localhost:3000
AUTHORIZATION_KEYS: auth-key-1
run: npm run test
- name: Run Integration Tests
working-directory: ./services/${{ inputs.service }}
env:
S3_BUCKET_NAME: test-bucket
LOCALSTACK_URL: http://localhost:4566
DYNAMODB_NAME: local-test-db
DYNAMODB_LOCAL_ENDPOINT: http://localhost:4566
AWS_ACCESS_KEY_ID: LSIA5678901234567890
AWS_SECRET_ACCESS_KEY: LSIA5678901234567890
SERVICE_URL: http://localhost:3000
NHS_ENVIRONMENT: local
EHR_URL: http://localhost:3000
AUTHORIZATION_KEYS: auth-key-1
run: npm run test:integration
build_and_publish:
name: Build and Publish
needs: [run_tests]
runs-on: ubuntu-latest
environment: ${{ inputs.environment }}
defaults:
run:
working-directory: "./services/${{ inputs.service }}"
steps:
- name: Checkout
uses: actions/checkout@v6
- name: Set up Node
uses: actions/setup-node@v6
with:
node-version: 24
- name: Install dependencies
run: npm install
- name: Configure AWS Credentials (Read/Write)
uses: aws-actions/configure-aws-credentials@v6.1.0
with:
role-to-assume: ${{ secrets.IAM_ROLE }}
aws-region: ${{ vars.AWS_REGION }}
mask-aws-account-id: true
role-skip-session-tagging: true
- name: Login to Amazon ECR
id: ecr-login
uses: aws-actions/amazon-ecr-login@v2
- name: NPM Build
run: npm run build
- name: Docker Build and Tag
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
REPOSITORY: deductions/${{ inputs.service }}
IMAGE_TAG: ${{ github.sha }}
run: |
set -euo pipefail
docker build -t "$REGISTRY/$REPOSITORY:$IMAGE_TAG" --build-arg BUILD_TAG="$IMAGE_TAG" .
- name: Docker Publish
if: ${{ inputs.is_deployment }}
env:
REGISTRY: ${{ steps.ecr-login.outputs.registry }}
REPOSITORY: deductions/${{ inputs.service }}
IMAGE_TAG: ${{ github.sha }}
run: |
set -euo pipefail
docker push "$REGISTRY/$REPOSITORY:$IMAGE_TAG"
- name: Generate SBOM for Docker Image
uses: anchore/sbom-action@v0
if: ${{ inputs.environment == 'development' }}
with:
image: ${{ steps.ecr-login.outputs.registry }}/deductions/${{ inputs.service }}:${{ github.sha }}
format: cyclonedx-json
output-file: sbom-image-${{ github.event.repository.name }}--${{ github.sha }}.cdx.json
- name: Scan SBOM for Docker Image
uses: anchore/scan-action@v7
if: ${{ inputs.environment == 'development' }}
with:
sbom: sbom-image-${{ github.event.repository.name }}--${{ github.sha }}.cdx.json
fail-build: true
severity-cutoff: low
only-fixed: true
output-format: table
deploy_infra:
name: Deploy Infrastructure
needs: [build_and_publish]
uses: NHSDigital/orphaned-record-continuity-infrastructure/.github/workflows/deploy-stack.yml@v3
with:
stack: ${{ inputs.service }}
environment: ${{ inputs.environment }}
is_deployment: ${{ inputs.is_deployment }}
ecr_alias: ${{ inputs.ecr_alias }}
git_ref: refs/tags/v3
secrets: inherit