-
Notifications
You must be signed in to change notification settings - Fork 2
165 lines (145 loc) · 4.75 KB
/
deploy-service-dev.yml
File metadata and controls
165 lines (145 loc) · 4.75 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
name: Deploy Service - Dev
run-name: "${{ inputs.service_name }} | Is deployment? = ${{ inputs.is_deployment }}"
on:
workflow_dispatch:
inputs:
service_name:
description: "Which Service are we running against?"
required: true
type: choice
options:
- spine-exporter
- ods-downloader
- transfer-classifier
- metrics-calculator
- reports-generator
is_deployment:
description: "Do you want changes deployed?"
required: true
type: boolean
default: false
workflow_call:
inputs:
service_name:
description: "Which Service are we running against?"
required: true
type: string
is_deployment:
description: "Do you want changes deployed?"
required: true
type: boolean
default: false
permissions:
pull-requests: write
id-token: write
contents: read
jobs:
test-environment:
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./services/${{ inputs.service_name }}
steps:
- uses: actions/checkout@v6
- name: Set up Python 3.14
uses: actions/setup-python@v6
with:
python-version: 3.14
- name: Make virtual environment
run: |
python -m pip install -U pipenv
./tasks devenv
- name: Check formatting
run: pipenv run check-format
- name: Run linters
run: |
pipenv run lint-bandit
- name: Type check
run: pipenv run typecheck
- name: Run tests
run: pipenv run test
build-and-publish-service:
if: inputs.is_deployment
environment: dev
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./services/${{ inputs.service_name }}
steps:
- uses: actions/checkout@v6
- name: Set up Python 3.14
uses: actions/setup-python@v6
with:
python-version: 3.14
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v6
with:
mask-aws-account-id: true
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
role-skip-session-tagging: true
aws-region: ${{ vars.AWS_REGION }}
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2
- name: Get ECR repository URI from SSM
id: ecr-repo
run: |
uri=$(aws ssm get-parameter \
--name "/registrations/${{ vars.AWS_ENVIRONMENT }}/data-pipeline/ecr/url/${{ inputs.service_name }}" \
--query "Parameter.Value" --output text)
echo "::add-mask::$uri"
echo "uri=$uri" >> $GITHUB_OUTPUT
- name: Make virtual environment
run: |
python -m pip install -U pipenv
./tasks devenv
- name: Build and Push Docker Image
env:
REF_NAME: ${{ github.ref_name }}
ECR_URI: ${{ steps.ecr-repo.outputs.uri }}
IMAGE_TAG: ${{ github.sha }}
run: |
TAG_ARGS=(-t "$ECR_URI:$IMAGE_TAG" -t "$ECR_URI:latest")
if [ -n "${REF_NAME:-}" ]; then
REF_TAG="${REF_NAME//\//-}"
TAG_ARGS+=(-t "$ECR_URI:$REF_TAG")
fi
docker build "${TAG_ARGS[@]}" --build-arg BUILD_TAG="$IMAGE_TAG" .
docker push "$ECR_URI:$IMAGE_TAG"
docker push "$ECR_URI:latest"
if [ -n "${GITHUB_REF_NAME:-}" ]; then
REF_TAG="${GITHUB_REF_NAME//\//-}"
docker push "$ECR_URI:$REF_TAG"
fi
transform-service-name:
name: Transform Service Name
needs: [build-and-publish-service]
runs-on: ubuntu-latest
outputs:
sanitized_service_name: ${{ steps.set.outputs.sanitized }}
steps:
- id: set
run: echo "sanitized=${{ inputs.service_name }}" | sed 's/-/_/g' >> "$GITHUB_OUTPUT"
redeploy_image_on_infra:
name: Redeploy image on Infrastructure
needs: [transform-service-name]
uses: NHSDigital/gp2gp-reporting-infrastructure/.github/workflows/deploy-stack.yml@v4
with:
environment: dev
is_deployment: ${{ inputs.is_deployment }}
terraform_stack: ${{ needs.transform-service-name.outputs.sanitized_service_name }}
has_image: true
build_lambda: true
hyphenated_alias: ${{ inputs.service_name }}
secrets: inherit
redeploy_step_functions_on_infra:
name: Redeploy step functions on infrastructure
needs: [redeploy_image_on_infra]
uses: NHSDigital/gp2gp-reporting-infrastructure/.github/workflows/deploy-stack.yml@v4
if: github.event_name == 'workflow_dispatch'
with:
environment: dev
is_deployment: ${{ inputs.is_deployment }}
terraform_stack: step_function
hyphenated_alias: step-function
secrets: inherit