-
Notifications
You must be signed in to change notification settings - Fork 0
128 lines (115 loc) · 3.97 KB
/
Copy pathdeploy.yml
File metadata and controls
128 lines (115 loc) · 3.97 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
name: Deploy
on:
workflow_dispatch:
push:
branches: [main]
paths:
- "cmd/**"
- "internal/**"
- "config/**"
- "template.yaml"
- "Makefile"
- "go.mod"
- "go.sum"
- ".github/workflows/deploy.yml"
concurrency:
group: weles-deploy
cancel-in-progress: false
permissions:
id-token: write
contents: read
jobs:
deploy:
runs-on: ubuntu-latest
environment: production
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: "1.24.x"
cache: true
- name: Install SAM CLI
run: pip install aws-sam-cli
- name: Configure AWS credentials (OIDC)
uses: aws-actions/configure-aws-credentials@v4
with:
role-to-assume: ${{ vars.AWS_ROLE_TO_ASSUME }}
aws-region: ${{ vars.AWS_REGION }}
- name: Validate apps config and SES identities
env:
APPS_CONFIG: ${{ secrets.APPS_CONFIG }}
SES_IDENTITIES: ${{ vars.SES_IDENTITIES }}
SES_IDENTITY: ${{ vars.SES_IDENTITY }}
AWS_REGION: ${{ vars.AWS_REGION }}
run: |
set -euo pipefail
IDENTITIES="${SES_IDENTITIES:-${SES_IDENTITY:-}}"
if [[ -z "${IDENTITIES}" ]]; then
echo "SES_IDENTITIES (or SES_IDENTITY) GitHub variable is required — comma-separated SES domains/emails for IAM" >&2
exit 1
fi
REGION="${AWS_REGION:?AWS_REGION is required}"
ACCOUNT="$(aws sts get-caller-identity --query Account --output text)"
APPS_FILE="$(mktemp)"
printf '%s' "$APPS_CONFIG" > "$APPS_FILE"
# Fails if YAML is invalid, emails missing, or fromEmail is outside SES identities.
JOINED_ARNS="$(go run ./cmd/deploycheck -apps "$APPS_FILE" -identities "$IDENTITIES" -region "$REGION" -account "$ACCOUNT" -print-arns)"
rm -f "$APPS_FILE"
{
echo "IDENTITIES<<EOF"
echo "$IDENTITIES"
echo "EOF"
echo "JOINED_ARNS<<EOF"
echo "$JOINED_ARNS"
echo "EOF"
} >> "$GITHUB_ENV"
- name: Publish secrets and allowlist to SSM
env:
APPS_CONFIG: ${{ secrets.APPS_CONFIG }}
TURNSTILE_SECRET: ${{ secrets.TURNSTILE_SECRET }}
APPS_PARAMETER_NAME: ${{ vars.APPS_PARAMETER_NAME }}
TURNSTILE_PARAMETER_NAME: ${{ vars.TURNSTILE_PARAMETER_NAME }}
run: |
normalize() {
local n="$1"
if [[ "$n" != /* ]]; then
n="/$n"
fi
printf '%s' "$n"
}
APPS_PARAM="$(normalize "${APPS_PARAMETER_NAME:-/weles/prod/apps}")"
TURNSTILE_PARAM="$(normalize "${TURNSTILE_PARAMETER_NAME:-/weles/prod/turnstile-secret}")"
echo "APPS_PARAM=$APPS_PARAM" >> "$GITHUB_ENV"
echo "TURNSTILE_PARAM=$TURNSTILE_PARAM" >> "$GITHUB_ENV"
aws ssm put-parameter \
--name "$APPS_PARAM" \
--type String \
--value "$APPS_CONFIG" \
--overwrite
aws ssm put-parameter \
--name "$TURNSTILE_PARAM" \
--type SecureString \
--value "$TURNSTILE_SECRET" \
--overwrite
- name: SAM build
run: sam build
- name: SAM deploy
env:
SES_CONFIGURATION_SET: ${{ vars.SES_CONFIGURATION_SET }}
run: |
set -euo pipefail
OVERRIDES=(
"SesIdentityArns=${JOINED_ARNS}"
"AppsParameterName=${APPS_PARAM}"
"TurnstileParameterName=${TURNSTILE_PARAM}"
)
if [[ -n "${SES_CONFIGURATION_SET:-}" ]]; then
OVERRIDES+=("SesConfigurationSet=${SES_CONFIGURATION_SET}")
fi
sam deploy \
--no-confirm-changeset \
--no-fail-on-empty-changeset \
--stack-name weles \
--capabilities CAPABILITY_IAM \
--resolve-s3 \
--parameter-overrides "${OVERRIDES[@]}"