-
Notifications
You must be signed in to change notification settings - Fork 1
180 lines (167 loc) · 5.65 KB
/
main-deploy.yml
File metadata and controls
180 lines (167 loc) · 5.65 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
name: "🚀 Build and deploy to main"
on:
workflow_call:
inputs:
aws_dev_account_id:
required: true
type: string
aws_region:
default: eu-west-1
type: string
github_ci_role_arn:
required: true
type: string
github_ci_ecr_role_arn:
required: true
type: string
service_name:
required: false
type: string
services:
required: false
type: string
description: 'Services names when deploying multiple services. Should be a list of objects with keys "directory" and "name" e.g. [{"directory": "core", "name": "apro-core-service"}]'
cluster_name:
required: true
type: string
ecr_repository:
required: false
type: string
ecr_repositories:
required: false
type: string
custom_build_script:
required: false
type: string
terraform_version:
description: 'Terraform version'
type: string
default: '1.9.8'
working_directory:
description: 'Working directory'
type: string
default: '.'
build_checkout_with_lfs:
description: 'Checkout with LFS'
type: boolean
default: false
build_checkout_fetch_tags:
description: 'Fetch git tags during checkout'
type: boolean
default: false
use_latest_tag:
description: 'Use latest tag'
type: boolean
default: true
pre_applied_resources:
description: 'Resources to apply before main deploy'
type: string
default: '[]'
force_new_deployment:
description: 'Force a new deployment even if the image tag is the same as the current deployment. E.g. latest'
type: boolean
default: true
secrets:
token:
required: true
permissions:
id-token: write # Required f. IAM Token
contents: write
jobs:
terraform-quality-checks:
name: '✅ Terraform Quality checks'
uses: aproorg/github-workflows/.github/workflows/terraform-quality-checks.yml@main
with:
terraform_version: ${{ inputs.terraform_version }}
get-next-version:
name: 🏷️ Get next version
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.get-next-version.outputs.new_release_published }}
steps:
- name: 📁 Checkout
uses: actions/checkout@v4
- name: 🏷️ Get next version
id: get-next-version
uses: aproorg/github-workflows/.github/actions/get-next-version@main
with:
github_token: ${{ secrets.token }}
unify-services:
name: '🤝 Unify service inputs'
runs-on: ubuntu-latest
outputs:
final_services: ${{ steps.unify-services.outputs.final_services }}
steps:
- name: 🤝 Unify service inputs
id: unify-services
uses: aproorg/github-workflows/.github/actions/unify-services@main
with:
service_name: ${{ inputs.service_name }}
services: ${{ inputs.services }}
create-ecr-repo:
name: '🚀 Apply shared'
needs: unify-services
strategy:
matrix:
include: ${{ fromJSON(needs.unify-services.outputs.final_services) }}
runs-on: ubuntu-latest
steps:
- name: 📁 Checkout
uses: actions/checkout@v4
- name: '🚀 Apply shared'
uses: aproorg/github-workflows/.github/actions/apply-shared@main
with:
AWS_REGION: ${{ inputs.aws_region }}
AWS_ECR_DEPLOYMENT_ROLE: ${{ inputs.github_ci_ecr_role_arn }}
TERRAFORM_VERSION: ${{ inputs.terraform_version }}
TERRAFORM_PATH: '${{ matrix.directory }}/terraform'
build-and-push-all-images:
name: '️️️🏗️ Build and push all images'
needs:
- terraform-quality-checks
- get-next-version
if: ${{ needs.get-next-version.outputs.new_release_published == 'true' }}
runs-on: ubuntu-latest
steps:
- name: 📁 Checkout
uses: actions/checkout@v4
with:
lfs: ${{ inputs.build_checkout_with_lfs }}
fetch-tags: ${{ inputs.build_checkout_fetch_tags }}
- name: '️️️🏗️ Build and push image all images'
uses: aproorg/github-workflows/.github/actions/build-and-push-image@main
with:
AWS_REGION: ${{ inputs.aws_region }}
AWS_ROLE_ARN: ${{ inputs.github_ci_ecr_role_arn }}
WORKING_DIRECTORY: ${{ inputs.working_directory }}
ECR_REPOSITORY: ${{ inputs.ecr_repository }}
ECR_REPOSITORIES: ${{ inputs.ecr_repositories }}
CUSTOM_BUILD_SCRIPT: ${{ inputs.custom_build_script }}
deploy-to-dev:
name: '🚀 Deploy to dev'
strategy:
matrix:
include: ${{ fromJSON(needs.unify-services.outputs.final_services) }}
environment: dev
needs:
- build-and-push-all-images
- get-next-version
- unify-services
if: ${{ needs.get-next-version.outputs.new_release_published == 'true' }}
runs-on: ubuntu-latest
steps:
- name: 📁 Checkout
uses: actions/checkout@v4
- name: '🚀 Deploy to dev'
uses: aproorg/github-workflows/.github/actions/deploy-ecs-service@main
with:
AWS_REGION: ${{ inputs.aws_region }}
ENVIRONMENT: dev
AWS_DEPLOYMENT_ROLE: ${{ inputs.github_ci_role_arn }}
IMAGE_TAG: ${{ inputs.use_latest_tag && 'latest' || format('sha-{0}', github.sha) }}
FORCE_NEW_DEPLOYMENT: ${{ inputs.force_new_deployment }}
SERVICE_NAME: ${{ matrix.name }}
CLUSTER_NAME: ${{ inputs.cluster_name }}
TERRAFORM_VERSION: ${{ inputs.terraform_version }}
TERRAFORM_PATH: '${{ matrix.directory }}/terraform'
PRE_APPLIED_RESOURCES: ${{ inputs.pre_applied_resources }}