-
Notifications
You must be signed in to change notification settings - Fork 6
192 lines (163 loc) · 7.06 KB
/
ld-test-deployment.yaml
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
192
name: "Deploy to Test Environment"
on:
pull_request:
branches: [main]
concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }}
cancel-in-progress: true
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: us-east-1
KUBE_CONFIG_DATA: ${{ secrets.KUBE_CONFIG_DATA }}
ECR_REPOSITORY: ld-core-demo
KUBECTL_VERSION: "v1.23.0"
LD_API_KEY: ${{ secrets.LD_API_KEY }}
DEMO_NAMESPACE: coredemotest
jobs:
deploy-to-test:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v3
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.9"
- name: Install LaunchDarkly CLI
run: npm install -g @launchdarkly/ldcli
- name: Set LaunchDarkly CLI Config
run: |
echo "Setting up LaunchDarkly CLI"
ldcli config --set access-token ${{ secrets.LD_API_KEY }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r ./.github/workflows/requirements.txt
- name: Delete Test LD Project
run: |
ldcli projects delete --project ${{ env.DEMO_NAMESPACE }}-ld-demo
- name: Create LD Project
id: create_ld_project
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Creating LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/ld_api/create_ld_project.py
- name: Create Feature Flags in LD Project/Environment
id: create_feature_flag_in_LD
if: env.PROJECT_EXISTS == 'false'
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Creating feature flag in LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/ld_api/create_ld_featureflags.py
- name: Create metric group in LD Project/Environment
id: create_metric_group_in_LD
if: env.PROJECT_EXISTS == 'false'
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Creating metrics in LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/ld_api/create_metric_group.py
- name: Create experiment in LD Project/Environment
id: create_experiment_in_LD
if: env.PROJECT_EXISTS == 'false'
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Creating experiment in LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/ld_api/create_experiment.py
- name: Create Migration FF in LD Project/Environment
id: create_migration_FF_in_LD
if: env.PROJECT_EXISTS == 'false'
env:
LD_API_KEY: ${{ secrets.LD_API_KEY }}
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
run: |
echo "Creating migration feature flag in LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
python ./.github/workflows/ld_api/create_migration_flag.py
- name: Create .env file
run: |
touch ./.env.production
echo NEXT_PUBLIC_LD_CLIENT_KEY=${{ env.LD_CLIENT_KEY }} >> ./.env.production
echo LD_SDK_KEY=${{ env.LD_SDK_KEY }} >> ./.env.production
echo DB_URL=${{ secrets.DB_URL }} >> ./.env.production
echo LD_API_KEY=${{ secrets.LD_API_KEY }} >> ./.env.production
echo DESTINATIONENV=${{ env.DEMO_NAMESPACE }} >> ./.env.production
echo PROJECT_KEY=${{ env.DEMO_NAMESPACE }}-ld-demo >> ./.env.production
- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1
- name: Build, tag, and push image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: ld-core-demo
run: |
docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }} .
docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }}
- name: Update K8s Deploy File
run: python ./.github/workflows/update_k8s_deploy_file.py
env:
NAMESPACE: ${{ env.DEMO_NAMESPACE }}
URL: ${{ env.DEMO_NAMESPACE }}.launchdarklydemos.com
IMAGE: ${{ steps.login-ecr.outputs.registry }}/ld-core-demo:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }}
- name: Check Namespace in Kubernetes
uses: kodermax/kubectl-aws-eks@master
with:
args: get namespace ${{ env.DEMO_NAMESPACE }} &>/dev/null && echo "namespace_exists=true" >> $GITHUB_ENV || echo "namespace_exists=false" >> $GITHUB_ENV
- name: Create Namespace In Kubernetes
if: env.namespace_exists == 'false'
uses: kodermax/kubectl-aws-eks@master
with:
args: create namespace ${{ env.DEMO_NAMESPACE }}
- name: Applying deploy file to Kubernetes
uses: kodermax/kubectl-aws-eks@master
with:
args: apply -f ./.github/workflows/deploy_files/deploy.yaml -n ${{ env.DEMO_NAMESPACE }}
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1
- name: Add Route 53 Record
run: |
HOSTED_ZONE_ID=$(aws route53 list-hosted-zones-by-name --dns-name "launchdarklydemos.com." --query "HostedZones[0].Id" --output text)
RECORD_SET_JSON='{
"Comment": "Creating Alias record that points to ALB",
"Changes": [
{
"Action": "UPSERT",
"ResourceRecordSet": {
"Name": "${{ env.DEMO_NAMESPACE }}.launchdarklydemos.com",
"Type": "A",
"AliasTarget": {
"HostedZoneId": "Z35SXDOTRQ7X7K",
"DNSName": "k8s-ldcoredemolb-93af62c3af-1176236694.us-east-1.elb.amazonaws.com",
"EvaluateTargetHealth": false
}
}
}
]
}'
aws route53 change-resource-record-sets --hosted-zone-id $HOSTED_ZONE_ID --change-batch "$RECORD_SET_JSON"
env:
AWS_REGION: 'us-east-1'
- name: Delete the deploy file
run: rm -rf ./.github/workflows/deploy_files
- name: Remove .env file
run: rm ./.env.production
- uses: actions/checkout@v4
with:
fetch-depth: 11
- name: LaunchDarkly Code References
uses: launchdarkly/[email protected]
with:
accessToken: ${{ secrets.LD_API_KEY }}
projKey: ${{ env.DEMO_NAMESPACE }}-ld-demo
repoName: main