-
Notifications
You must be signed in to change notification settings - Fork 72
300 lines (277 loc) · 12.2 KB
/
upgrade.yml
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
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
name: Build an upgrade
on:
workflow_dispatch:
# pull_request:
# branches:
# - '*'
jobs:
build-and-test-upgrade:
runs-on: self-hosted
env:
UNIQUE_ID:
IP_ADDRESS:
LS1_IP:
LATEST_BRANCH:
BRANCH_NAME:
elastic:
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Setup environment variables
run: |
PUBLIC_IP=$(curl -s https://api.ipify.org)
echo "IP_ADDRESS=$PUBLIC_IP" >> $GITHUB_ENV
echo "UNIQUE_ID=$(openssl rand -hex 3 | head -c 6)" >> $GITHUB_ENV
LATEST_BRANCH_VAR=$(curl -s https://api.github.com/repos/cisagov/LME/tags | jq -r '.[].name | sub("^v"; "") | "release-" + .' | head -n 1)
echo "LATEST_BRANCH=$LATEST_BRANCH_VAR"
echo "LATEST_BRANCH=$LATEST_BRANCH_VAR" >> $GITHUB_ENV
- name: Get branch name
shell: bash
run: |
if [ "${{ github.event_name }}" == "pull_request" ]; then
echo "BRANCH_NAME=${{ github.head_ref }}" >> $GITHUB_ENV
else
echo "BRANCH_NAME=${GITHUB_REF##*/}" >> $GITHUB_ENV
fi
- name: Set up Docker Compose
run: |
sudo curl -L "https://github.com/docker/compose/releases/download/v2.3.3/docker-compose-$(uname -s)-$(uname -m)" \
-o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
- name: Set the environment for docker-compose
run: |
cd testing/development
# Get the UID and GID of the current user
echo "HOST_UID=$(id -u)" > .env
echo "HOST_GID=$(id -g)" >> .env
# - name: Run Docker Compose Build to fix a user id issue in a prebuilt container
# run: |
# cd testing/development
# docker-compose -p ${{ env.UNIQUE_ID }} build --no-cache
- name: Run Docker Compose
run: docker compose -p ${{ env.UNIQUE_ID }} -f testing/development/docker-compose.yml up -d
- name: List docker containers to wait for them to start
run: |
docker ps
- name: List files in home directory
run: |
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme bash -c "pwd && ls -la"
- name: Check powershell environment
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "& {
cd /home/admin.ackbar/LME; \
ls -la; \
exit \$LASTEXITCODE;
}"
EXIT_CODE=$?
echo "Exit code: $EXIT_CODE"
set -e
if [ "$EXIT_CODE" -ne 0 ]; then
exit $EXIT_CODE
fi
- name: Build the cluster
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "& {
cd /home/admin.ackbar/LME/testing; \
\$env:AZURE_CLIENT_ID='${{ secrets.AZURE_CLIENT_ID }}'; \
\$env:AZURE_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_CLIENT_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_TENANT='${{ secrets.AZURE_TENANT }}'; \
\$env:UNIQUE_ID='${{ env.UNIQUE_ID }}'; \
\$env:RESOURCE_GROUP='LME-pipe-${{ env.UNIQUE_ID }}'; \
\$env:IP_ADDRESS='${{ env.IP_ADDRESS }}'; \
./development/build_cluster.ps1 -IPAddress \$env:IP_ADDRESS; \
exit \$LASTEXITCODE;
}"
EXIT_CODE=$?
echo "Exit code: $EXIT_CODE"
set -e
if [ "$EXIT_CODE" -ne 0 ]; then
exit $EXIT_CODE
fi
cd ..
. configure/lib/functions.sh
extract_ls1_ip 'LME-pipe-${{ env.UNIQUE_ID }}.cluster.output.log'
echo "LS1_IP=$LS1_IP" >> $GITHUB_ENV
- name: Install lme on cluster
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "& {
cd /home/admin.ackbar/LME/testing; \
\$env:AZURE_CLIENT_ID='${{ secrets.AZURE_CLIENT_ID }}'; \
\$env:AZURE_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_CLIENT_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_TENANT='${{ secrets.AZURE_TENANT }}'; \
\$env:UNIQUE_ID='${{ env.UNIQUE_ID }}'; \
\$env:RESOURCE_GROUP='LME-pipe-${{ env.UNIQUE_ID }}'; \
./development/install_lme.ps1 -b '${{ env.LATEST_BRANCH }}'; \
exit \$LASTEXITCODE;
}"
EXIT_CODE=$?
echo "Exit code: $EXIT_CODE"
set -e
if [ "$EXIT_CODE" -ne 0 ]; then
exit $EXIT_CODE
fi
- name: Set the environment passwords for other steps
run: |
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme bash -c "
cd /home/admin.ackbar/LME/testing \
&& . configure/lib/functions.sh \
&& extract_credentials 'LME-pipe-${{ env.UNIQUE_ID }}.password.txt' \
&& write_credentials_to_file '${{ env.UNIQUE_ID }}.github_env.sh' \
"
. ../${{ env.UNIQUE_ID }}.github_env.sh
rm ../${{ env.UNIQUE_ID }}.github_env.sh
echo "elastic=$elastic" >> $GITHUB_ENV
echo "kibana=$kibana" >> $GITHUB_ENV
echo "logstash_system=$logstash_system" >> $GITHUB_ENV
echo "logstash_writer=$logstash_writer" >> $GITHUB_ENV
echo "dashboard_update=$dashboard_update" >> $GITHUB_ENV
- name: Check that the environment variables are set
run: |
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme bash -c "
if [ -z \"${{ env.elastic }}\" ]; then
echo 'Error: env.elastic variable is not set' >&2
exit 1
else
echo 'Elastic password is set'
fi
"
- name: Upgrade to the version being built
# This will check out the code in the /root directory so that it can use the latest version of the code.
# But it will also check out the branch in the /opt/lme directory so that upgrade_lme.sh script can use the branch.
run: |
set +e
cd testing/development
output=$(docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "\
cd /home/admin.ackbar/LME/testing; \
\$env:AZURE_CLIENT_ID='${{ secrets.AZURE_CLIENT_ID }}'; \
\$env:AZURE_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_CLIENT_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_TENANT='${{ secrets.AZURE_TENANT }}'; \
\$env:UNIQUE_ID='${{ env.UNIQUE_ID }}'; \
\$env:RESOURCE_GROUP='LME-pipe-${{ env.UNIQUE_ID }}'; \
az login --service-principal -u \$env:AZURE_CLIENT_ID -p \$env:AZURE_SECRET --tenant \$env:AZURE_TENANT; \
az vm run-command invoke \
--command-id RunShellScript \
--name LS1 \
--resource-group \$env:RESOURCE_GROUP \
--scripts 'export HOME=/root; pwd && whoami && cd ~ \
&& git clone https://github.com/cisagov/LME.git \
&& cd LME \
&& echo "Checking out current branch: ${{ env.BRANCH_NAME }}" \
&& git checkout ${{ env.BRANCH_NAME }} \
&& cd testing \
&& ./development/upgrade_lme.sh; exit \$?'")
echo "Output: $output"
if echo "$output" | grep -q "UPGRADE_SUCCESSFUL"; then
echo "Upgrade successful"
exit 0
else
echo "Upgrade failed"
exit 1
fi
# - name: Run a command on the domain controller
# run: |
# set +e
# cd testing/development
# docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "& {
# cd /home/admin.ackbar/LME/testing; \
# \$env:AZURE_CLIENT_ID='${{ secrets.AZURE_CLIENT_ID }}'; \
# \$env:AZURE_SECRET='${{ secrets.AZURE_SECRET }}'; \
# \$env:AZURE_CLIENT_SECRET='${{ secrets.AZURE_SECRET }}'; \
# \$env:AZURE_TENANT='${{ secrets.AZURE_TENANT }}'; \
# \$env:UNIQUE_ID='${{ env.UNIQUE_ID }}'; \
# \$env:RESOURCE_GROUP='LME-pipe-${{ env.UNIQUE_ID }}'; \
# az login --service-principal -u \$env:AZURE_CLIENT_ID -p \$env:AZURE_SECRET --tenant \$env:AZURE_TENANT; \
# az vm run-command invoke \
# --command-id RunPowerShellScript \
# --name DC1 \
# --resource-group \$env:RESOURCE_GROUP \
# --scripts 'ls C:\'; \
# exit \$LASTEXITCODE;
# }"
# EXIT_CODE=$?
# echo "Exit code: $EXIT_CODE"
# set -e
# if [ "$EXIT_CODE" -ne 0 ]; then
# exit $EXIT_CODE
# fi
- name: Run a command on the linux machine
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "& {
cd /home/admin.ackbar/LME/testing; \
\$env:AZURE_CLIENT_ID='${{ secrets.AZURE_CLIENT_ID }}'; \
\$env:AZURE_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_CLIENT_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_TENANT='${{ secrets.AZURE_TENANT }}'; \
\$env:UNIQUE_ID='${{ env.UNIQUE_ID }}'; \
\$env:RESOURCE_GROUP='LME-pipe-${{ env.UNIQUE_ID }}'; \
az login --service-principal -u \$env:AZURE_CLIENT_ID -p \$env:AZURE_SECRET --tenant \$env:AZURE_TENANT; \
az vm run-command invoke \
--command-id RunShellScript \
--name LS1 \
--resource-group \$env:RESOURCE_GROUP \
--scripts 'ls -lan'; \
exit \$LASTEXITCODE;
}"
EXIT_CODE=$?
echo "Exit code: $EXIT_CODE"
set -e
if [ "$EXIT_CODE" -ne 0 ]; then
exit $EXIT_CODE
fi
# This only passes when you do a full install
- name: Run api tests in container
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c " cd testing/tests \
&& echo export elastic=${{ env.elastic }} > .env \
&& echo export ES_HOST=${{ env.LS1_IP }} >> .env \
&& cat .env \
&& python3 -m venv /home/admin.ackbar/venv_test \
&& . /home/admin.ackbar/venv_test/bin/activate \
&& pip install -r requirements.txt \
&& sudo chmod ugo+w /home/admin.ackbar/LME/ -R \
&& pytest -v api_tests/"
- name: Run selenium tests in container
run: |
set +e
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T -u admin.ackbar lme bash -c " cd testing/tests \
&& echo export ELASTIC_PASSWORD=${{ env.elastic }} > .env \
&& . .env \
&& python3 -m venv /home/admin.ackbar/venv_test \
&& . /home/admin.ackbar/venv_test/bin/activate \
&& pip install -r requirements.txt \
&& sudo chmod ugo+w /home/admin.ackbar/LME/ -R \
&& python selenium_tests.py --domain ${{ env.LS1_IP }} -v"
- name: Cleanup environment
if: always()
run: |
cd testing/development
docker compose -p ${{ env.UNIQUE_ID }} exec -T lme pwsh -Command "& {
cd /home/admin.ackbar/LME/testing; \
\$env:AZURE_CLIENT_ID='${{ secrets.AZURE_CLIENT_ID }}'; \
\$env:AZURE_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_CLIENT_SECRET='${{ secrets.AZURE_SECRET }}'; \
\$env:AZURE_TENANT='${{ secrets.AZURE_TENANT }}'; \
\$env:UNIQUE_ID='${{ env.UNIQUE_ID }}'; \
\$env:RESOURCE_GROUP='LME-pipe-${{ env.UNIQUE_ID }}'; \
./development/destroy_cluster.ps1; \
exit \$LASTEXITCODE;
}"
docker compose -p ${{ env.UNIQUE_ID }} down
docker system prune --force