-
Notifications
You must be signed in to change notification settings - Fork 13
143 lines (122 loc) · 4.56 KB
/
Copy pathdeploy.yml
File metadata and controls
143 lines (122 loc) · 4.56 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
name: Deploy
run-name: Deploy to ${{ inputs.env-name }} (${{ inputs.env-type }}) ${{ inputs.target-git-branch }} - ${{ inputs.target-git-sha }}
on:
workflow_dispatch:
# when you want to trigger deployment manually
inputs:
# env-type and env-name are mutually exclusive
env-type:
required: true
description: 'The environment type to deploy. This also is used to know which credentials to use.'
type: choice
options:
- dev
- test
- prod
env-name:
required: false
type: string
description: 'The environment name to deploy. If not specified all environments with the above type will be deployed.'
target-git-branch:
required: true
type: string
description: 'The target git branch name to deploy'
target-git-sha:
required: true
type: string
description: 'The target git commit sha to deploy'
workflow_call:
inputs:
# env-type and env-name are mutually exclusive
env-type:
required: false
type: string
description: 'The environment type to deploy'
env-name:
required: false
type: string
description: 'The environment name to deploy'
target-git-branch:
required: true
type: string
description: 'The branch name/version to deploy'
target-git-sha:
required: true
type: string
description: 'The commit sha to deploy'
jobs:
deploy:
runs-on: ubuntu-latest
steps:
# 1. checkout.
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ inputs.target-git-sha }}
- name: Setup python
uses: actions/setup-python@v5
with:
python-version: '3.11'
cache: 'pip' # caching pip dependencies
- name: Cache Pulumi plugins
id: cache-pulumi-plugins
uses: actions/cache@v4
with:
path: ~/.pulumi/plugins
key: ${{ runner.os }}-pulumi-plugins-${{ hashFiles('iac/requirements.txt') }}
- name: Install python packages
run: pip install -r requirements.txt
working-directory: iac
# 2. setup google cloud platform.
- name: Authenticate to google cloud
uses: google-github-actions/auth@v2.1.2
with:
# IF
# the env dir is upper OR env_type is prod
# THEN
# use the upper envs service account json,
# OTHERWISE
# use the lower envs service account json.
# We are using Boo
credentials_json:
${{ (inputs.env-type == 'prod' && secrets.GCP_UPPER_ENVS_SERVICE_ACCOUNT_JSON) || secrets.GCP_LOWER_ENVS_SERVICE_ACCOUNT_JSON }}
- name: Set up Cloud SDK
uses: google-github-actions/setup-gcloud@v2
# 3. setup pulumi.
- name: Install pulumi
id: pulumi
uses: pulumi/actions@v5
- name: Login to pulumi
run: |
pulumi login
pulumi org set-default tabiya-tech
env:
PULUMI_ACCESS_TOKEN: ${{ secrets.PULUMI_ACCESS_TOKEN }}
# 3. setup AWS.
- name: Configure AWS Credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_DNS_UPDATE_ACCESS_KEY }}
aws-secret-access-key: ${{ secrets.AWS_DNS_UPDATE_SECRET_ACCESS_KEY }}
aws-region: eu-central-1
role-duration-seconds: 1200
role-session-name: Compass AWS NS
# 4. run the deployment scripts.
- name: Get Target environment(s) arguments.
id: target_environments
# Trim the environment name.
# If the environment name was provided then use it, otherwise use the environment type.
# Construct the arguments that are going to be used in the next steps.
run: |
ENV_NAME="$(echo '${{ inputs.env-name }}' | xargs)"
if [ -n "$ENV_NAME" ]; then
echo "args=--env-name $ENV_NAME" >> $GITHUB_OUTPUT
else
echo "args=--env-type ${{ inputs.env-type }}" >> $GITHUB_OUTPUT
fi
- name: Prepare the deployment(s)
working-directory: iac
run: ./scripts/prepare.py --realm-name ${{ vars.REALM_NAME }} ${{ steps.target_environments.outputs.args }} --target-git-sha ${{ inputs.target-git-sha }} --target-git-branch ${{ inputs.target-git-branch }}
- name: Deploy the infrastructure
working-directory: iac
run: ./scripts/up.py --realm-name ${{ vars.REALM_NAME }} ${{ steps.target_environments.outputs.args }}