1
- name : Update All User Environments
1
+ name : " Update All User Environments"
2
2
3
3
on :
4
- pull_request :
5
- branches : [update_all_envs]
4
+ schedule :
5
+ - cron : ' 0 6 * * 0 '
6
6
7
7
8
+ env :
9
+ AWS_ACCESS_KEY_ID : ${{ secrets.AWS_ACCESS_KEY }}
10
+ AWS_SECRET_ACCESS_KEY : ${{ secrets.AWS_SECRET_ACCESS_KEY }}
11
+ AWS_REGION : us-east-1
12
+ KUBE_CONFIG_DATA : ${{ secrets.KUBE_CONFIG_DATA }}
13
+ ECR_REPOSITORY : ld-core-demo
14
+ KUBECTL_VERSION : " v1.23.0"
15
+ LD_API_KEY : ${{ secrets.LD_API_KEY }}
16
+
8
17
jobs :
9
- update -demo-environments :
18
+ get-all -demo-environments :
10
19
runs-on : ubuntu-latest
20
+ outputs :
21
+ branches : ${{ steps.set_branches.outputs.branches }}
11
22
steps :
12
23
- name : Checkout repository
13
24
uses : actions/checkout@v2
14
25
15
26
- name : Get all branches and loop through them
27
+ id : set_branches
16
28
run : |
17
29
git fetch --all
18
- for branch in $(git branch -r | grep -v '\->'); do
30
+ branches_to_update="["
31
+ for branch in $(git branch -r | grep -v '\->' | grep 'demoenv'); do
19
32
branch=${branch#origin/}
20
- echo "Processing branch: $branch"
21
- # Add commands to process each branch as needed
22
- done
33
+ echo "Branch $branch is a demo environment"
34
+ branches_to_update="$branches_to_update\"$branch\","
35
+ done
36
+ branches_to_update="${branches_to_update%,}]" # Remove trailing comma and close the array
37
+ echo "BRANCHES=$branches_to_update" >> $GITHUB_OUTPUT
38
+
39
+ update-all-demo-environments :
40
+ needs : get-all-demo-environments
41
+ runs-on : ubuntu-latest
42
+
43
+ env :
44
+ BRANCHES : ${{ needs.get-all-demo-environments.outputs.branches }}
45
+
46
+ strategy :
47
+ fail-fast : false
48
+ matrix :
49
+ branch : ${{ fromJson(needs.get-all-demo-environments.outputs.branches) }}
50
+
51
+
52
+ steps :
53
+ - name : Checkout repository
54
+ uses : actions/checkout@v2
55
+
56
+ - name : Setup branch environment
57
+ env :
58
+ GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
59
+ run : |
60
+ echo "Updating branch ${{ matrix.branch }}"
61
+ git config --global user.name "github-actions[bot]"
62
+ git config --global user.email "github-actions[bot]@users.noreply.github.com"
63
+ git fetch
64
+ git checkout ${{ matrix.branch }}
65
+ git merge origin/main --no-edit
66
+
67
+ - name : Get Namespace
68
+ id : get-namespace
69
+ run : |
70
+ NAMESPACE="${{ matrix.branch }}"
71
+ NAMESPACE=${NAMESPACE#demoenv-}
72
+ echo "DEMO_NAMESPACE=${NAMESPACE}" >> $GITHUB_ENV
73
+
74
+ - name : Set up Python
75
+ uses : actions/setup-python@v2
76
+ with :
77
+ python-version : " 3.9"
78
+
79
+ - name : Install dependencies
80
+ run : |
81
+ python -m pip install --upgrade pip
82
+ pip install -r ./.github/workflows/requirements.txt
83
+
84
+ - name : Get LD Env Vars for Demo Environment
85
+ id : create_ld_project
86
+ env :
87
+ LD_API_KEY : ${{ secrets.LD_API_KEY }}
88
+ NAMESPACE : ${{ env.DEMO_NAMESPACE }}
89
+ run : |
90
+ echo "Creating LaunchDarkly project for namespace: ${{ env.DEMO_NAMESPACE }}"
91
+ python ./.github/workflows/create_ld_project.py
92
+
93
+ - name : Create .env file
94
+ run : |
95
+ touch ./.env.production
96
+ echo NEXT_PUBLIC_LD_CLIENT_KEY=${{ env.LD_CLIENT_KEY }} >> ./.env.production
97
+ echo LD_SDK_KEY=${{ env.LD_SDK_KEY }} >> ./.env.production
98
+ echo DB_URL=${{ secrets.DB_URL }} >> ./.env.production
99
+ echo LD_API_KEY=${{ secrets.LD_API_KEY }} >> ./.env.production
100
+ echo DESTINATIONENV=${{ env.DEMO_NAMESPACE }} >> ./.env.production
101
+ echo PROJECT_KEY=${{ env.DEMO_NAMESPACE }}-ld-demo >> ./.env.production
102
+
103
+ - name : Login to Amazon ECR
104
+ id : login-ecr
105
+ uses : aws-actions/amazon-ecr-login@v1
106
+
107
+ - name : Build, tag, and push image to Amazon ECR
108
+ env :
109
+ ECR_REGISTRY : ${{ steps.login-ecr.outputs.registry }}
110
+ ECR_REPOSITORY : ld-core-demo
111
+ run : |
112
+ docker build -t $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }} .
113
+ docker push $ECR_REGISTRY/$ECR_REPOSITORY:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }}
114
+
115
+ - name : Update K8s Deploy File
116
+ run : python ./.github/workflows/update_k8s_deploy_file.py
117
+ env :
118
+ NAMESPACE : ${{ env.DEMO_NAMESPACE }}
119
+ URL : ${{ env.DEMO_NAMESPACE }}.launchdarklydemos.com
120
+ IMAGE : ${{ steps.login-ecr.outputs.registry }}/ld-core-demo:${{ env.DEMO_NAMESPACE }}-${{ github.run_id }}
121
+
122
+ - name : Check Namespace in Kubernetes
123
+ uses : kodermax/kubectl-aws-eks@master
124
+ with :
125
+ args : get namespace ${{ env.DEMO_NAMESPACE }} &>/dev/null && echo "namespace_exists=true" >> $GITHUB_ENV || echo "namespace_exists=false" >> $GITHUB_ENV
126
+
127
+ - name : Create Namespace In Kubernetes
128
+ if : env.namespace_exists == 'false'
129
+ uses : kodermax/kubectl-aws-eks@master
130
+ with :
131
+ args : create namespace ${{ env.DEMO_NAMESPACE }}
132
+
133
+ - name : Applying deploy file to Kubernetes
134
+ uses : kodermax/kubectl-aws-eks@master
135
+ with :
136
+ args : apply -f ./.github/workflows/deploy_files/deploy.yaml -n ${{ env.DEMO_NAMESPACE }}
137
+
138
+ - name : Delete the deploy file
139
+ run : rm -rf ./.github/workflows/deploy_files
140
+
141
+ - name : Remove .env file
142
+ run : rm ./.env.production
0 commit comments