Skip to content

Commit b594449

Browse files
ryapricJDeBo
andauthored
Post-event(s) fixes/tweaks (#3)
Co-authored-by: Justin DeBo <justin.debo@gmail.com>
1 parent b2f9d31 commit b594449

8 files changed

Lines changed: 94 additions & 32 deletions

File tree

linux/Makefile

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@ up-local:
55
@vagrant up $(local_team_servers)
66

77
up-aws:
8-
@(cd ./terraform && terraform apply)
8+
@terraform -chdir=./terraform apply
99

1010
yeet-aws:
11-
@(cd ./terraform && terraform apply -auto-approve)
11+
@terraform -chdir=./terraform apply -auto-approve
12+
@printf 'Waiting 30s for EC2 instances to hopefully process userdata...\n' && sleep 30
1213
@make -s provision-aws
1314

1415
provision-local:
@@ -17,13 +18,14 @@ provision-local:
1718
@vagrant provision $(local_team_servers)
1819

1920
provision-aws:
21+
# TODO: just run this script without cd-ing but need to test later
2022
@(cd ./terraform && bash ../scripts/provision-ec2.sh)
2123

2224
down-local:
2325
@vagrant destroy -f
2426

2527
down-aws:
26-
@(cd ./terraform && terraform destroy)
28+
@terraform -chdir=./terraform destroy
2729

2830
nuke-aws:
29-
@(cd ./terraform && terraform destroy -auto-approve)
31+
@terraform -chdir=./terraform destroy -auto-approve

linux/docs/Linux-Workshop.odp

2.06 MB
Binary file not shown.

linux/instructions/step_2.md

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ following:
1717

1818
- Once there, the app there needs to be named `run-app`, not `app`
1919

20-
- The app source code (including the built binary) need to *remain under
21-
`/opt/app`* as well
22-
23-
- To prevent possible issues with hotfix rebuilds of the app (like we're doing
24-
now) causing the rebuild to fall out-of-sync with the right location, the app
25-
must *not be copied to the correct directory* -- you must find another way to
26-
have the same file appear in multiple places at once.
20+
- To ensure both locations always have the same version (e.g. during hotfixes),
21+
make a reference from the binary location to the target location without
22+
copying the actual file. This way, any update or change will reflect in both
23+
places at once without needing to manually sync them.

linux/scripts/linux-workshop-admin.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,33 @@ check-binary-built() {
9191
}
9292

9393
check-symlink() {
94-
if [[ -L /usr/local/bin/run-app ]] && file /usr/local/bin/run-app | grep -q -v 'broken' ; then
94+
if \
95+
[[ -L /usr/local/bin/run-app ]] && \
96+
[[ -f /usr/local/bin/run-app ]] && \
97+
file /usr/local/bin/run-app | grep -q -v 'broken' \
98+
; then
9599
score-for-step 2
96100
else
97101
printf '* Symlink from Go binary to desired location does not yet exist\n'
98102
fi
99103
}
100104

101105
check-systemd-service-running() {
102-
if systemctl is-active app.service > /dev/null && systemctl is-enabled app.service > /dev/null ; then
106+
if \
107+
systemctl is-active app.service > /dev/null && \
108+
systemctl is-enabled app.service > /dev/null \
109+
; then
103110
score-for-step 3
104111
else
105112
printf '* app.service is either not running, not enabled, or both\n'
106113
fi
107114
}
108115

109116
check-debfile-service-running() {
110-
if systemctl is-active app-deb.service > /dev/null && systemctl is-enabled app-deb.service > /dev/null ; then
117+
if \
118+
systemctl is-active app-deb.service > /dev/null && \
119+
systemctl is-enabled app-deb.service > /dev/null \
120+
; then
111121
score-for-step 4
112122
else
113123
printf '* app-deb.service is either not running, not enabled, or both\n'
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
4+
################################################################################
5+
# Child script used to provision AWS EC2 instances in parallel (the caller wraps
6+
# this script in GNU Parallel).
7+
#
8+
# This script is not intended to be run directly, but only as a subprocess of
9+
# the root provisioning script.
10+
################################################################################
11+
12+
server_num="${1:-NOT_SET}"
13+
14+
if [[ -z "${db_priv_ip:-NOT_SET}" ]] ; then
15+
printf 'ERROR: db_priv_ip not provided to team server provisioning script\n'
16+
exit 1
17+
fi
18+
if [[ -z "${team_server_ips:-NOT_SET}" ]] ; then
19+
printf 'ERROR: team_server_ips not provided to team server provisioning script\n'
20+
exit 1
21+
fi
22+
23+
server_ip=$(echo "${team_server_ips}" | jq -rc ".[$((server_num - 1))]")
24+
printf '>>> Team %s IP is %s\n' "${server_num}" "${server_ip}"
25+
26+
printf '>>> Adding files to Team server %s at %s...\n' "${server_num}" "${server_ip}"
27+
scp -P 2332 -r -o StrictHostKeyChecking=accept-new ../scripts ../services ../instructions ../dummy-app-src admin@"${server_ip}":/tmp
28+
29+
printf '>>> Running init on Team server %s at %s...\n' "${server_num}" "${server_ip}"
30+
ssh -p 2332 admin@"${server_ip}" "export team_name=Team-${server_num} && export db_addr=${db_priv_ip} && sudo -E bash /tmp/scripts/init.sh"
31+
32+
printf '>>> Running tests on Team server %s at %s...\n' "${server_num}" "${server_ip}"
33+
ssh -p 2332 admin@"${server_ip}" "sudo -E bats /.ws/scripts/test.bats"
34+
35+
printf '>>> Done with Team server %s at %s\n' "${server_num}" "${server_ip}"

linux/scripts/provision-ec2.sh

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,27 @@
11
#!/usr/bin/env bash
22
set -euo pipefail
33

4+
################################################################################
5+
# Root script to provision AWS EC2 instances for the workshop.
6+
#
7+
# The DB server is provisioned first, and then each team server is provisioned
8+
# in parallel by the neighbor script.
9+
################################################################################
10+
11+
cd "$(dirname "$0")"
12+
13+
# Make sure GNU Parallel is installed for later, but check early so we don't
14+
# waste anyone's time
15+
if ! command -v parallel > /dev/null ; then
16+
printf 'ERROR: GNU Parallel does not seem to be installed. You can install it via "[brew|apt|dnf|pacman|etc] install parallel"\n'
17+
exit 1
18+
fi
19+
20+
# Set all the variables
421
outputs_file='/tmp/outputs.json'
522

6-
cd "$(dirname $0)"
7-
823
printf '>>> Getting Terraform outputs...\n'
24+
# TODO: use -chdir here but needs testing if you change the Makefile target as well
925
(cd ../terraform && terraform output -json) > "${outputs_file}"
1026

1127
printf '>>> Determining IP addresses of DB server...\n'
@@ -18,25 +34,22 @@ num_teams="$(jq '[.instance_ips.value[]] | length' ${outputs_file})"
1834
team_server_ips="$(jq -c '[.instance_ips.value[]]' ${outputs_file})"
1935
printf '>>> %s teams, with IPs of: %s\n' "${num_teams}" "${team_server_ips}"
2036

37+
# Provision the DB server first, so that if it fails we know we're about to have
38+
# a bad time overall
2139
printf '>>> Adding DB server init script...\n'
2240
scp -P 2332 -o StrictHostKeyChecking=accept-new -r ../scripts ../score-server admin@"${db_pub_ip}":/tmp
2341
ssh -p 2332 admin@"${db_pub_ip}" -- 'sudo cp -r /tmp/score-server /root/'
2442
printf '>>> Running DB server init script...\n'
2543
ssh -p 2332 admin@"${db_pub_ip}" 'sudo bash /tmp/scripts/init-db.sh'
2644

27-
for server_num in $(seq 1 "${num_teams}") ; do
28-
server_index=$((server_num - 1))
29-
server_ip=$(echo "${team_server_ips}" | jq -rc ".[${server_index}]")
30-
printf '>>> Team %s IP is %s\n' "${server_num}" "${server_ip}"
31-
32-
printf '>>> Adding files to Team server %s at %s...\n' "${server_num}" "${server_ip}"
33-
scp -P 2332 -r -o StrictHostKeyChecking=accept-new ../scripts ../services ../instructions ../dummy-app-src admin@"${server_ip}":/tmp
34-
35-
printf '>>> Running init on Team server %s at %s...\n' "${server_num}" "${server_ip}"
36-
ssh -p 2332 admin@"${server_ip}" "export team_name=Team-${server_num} && export db_addr=${db_priv_ip} && sudo -E bash /tmp/scripts/init.sh"
37-
38-
printf '>>> Running tests on Team server %s at %s...\n' "${server_num}" "${server_ip}"
39-
ssh -p 2332 admin@"${server_ip}" "sudo -E bats /.ws/scripts/test.bats"
40-
41-
printf '>>> Done with Team server %s at %s\n' "${server_num}" "${server_ip}"
42-
done
45+
# Export needed vars so the subscript can see them
46+
export db_priv_ip
47+
export team_server_ips
48+
49+
# Parallelize provisioning of the team servers
50+
parallel \
51+
-j0 \
52+
--lb \
53+
-- \
54+
bash ./provision-ec2-team-parallelizer.sh {} \
55+
:::: <(seq 1 "${num_teams}")

linux/scripts/test.bats

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ if [[ "$(id -u)" -ne 0 ]] ; then
1818
fi
1919

2020
# This file should have been populated on init
21+
# shellcheck disable=SC1091
2122
source "${wsroot}"/env || exit 1
2223

2324
# setup* and teardown* are bats-specifically-named pre-/post-test hook

linux/terraform/outputs.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ output "db_pub_ip" {
66
value = module.db.public_ip
77
}
88

9+
output "db_pub_endpoint" {
10+
value = "http://${module.db.public_ip}:8080"
11+
}
12+
913
output "db_priv_ip" {
1014
value = module.db.private_ip
1115
}

0 commit comments

Comments
 (0)