Skip to content

Commit 3080ae3

Browse files
committed
Rename "db" to "hub" in preparation for score-pull vs. score-push
1 parent fc16410 commit 3080ae3

10 files changed

Lines changed: 56 additions & 56 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ connect-aws:
2020

2121
provision-local:
2222
# Don't re-provision DB at the same time, since it throws off team server tests
23-
@vagrant provision db
23+
@vagrant provision hub
2424
@vagrant provision $(local_team_servers)
2525

2626
provision-aws:

Vagrantfile

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,26 @@ Vagrant.configure("2") do |config|
2222
config.vbguest.auto_update = false
2323
end
2424

25-
# DB server static IP
26-
db_addr = "10.0.1.10"
27-
ip_bytes = db_addr.split(".")
25+
# hub server static IP
26+
hub_addr = "10.0.1.10"
27+
ip_bytes = hub_addr.split(".")
2828

29-
config.vm.define "db" do |db|
30-
db.vm.box = box
29+
config.vm.define "hub" do |hub|
30+
hub.vm.box = box
3131

32-
db.vm.network "private_network", ip: db_addr
33-
db.vm.network "forwarded_port", guest: 5432, host: 5432, protocol: "tcp" # DB
34-
db.vm.network "forwarded_port", guest: 8000, host: 8000, protocol: "tcp" # Dummy web app
35-
db.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp" # Score dashboard
32+
hub.vm.network "private_network", ip: hub_addr
33+
hub.vm.network "forwarded_port", guest: 5432, host: 5432, protocol: "tcp" # hub
34+
hub.vm.network "forwarded_port", guest: 8000, host: 8000, protocol: "tcp" # Dummy web app
35+
hub.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp" # Score dashboard
3636

37-
db.vm.synced_folder ".", "/vagrant", disabled: true
37+
hub.vm.synced_folder ".", "/vagrant", disabled: true
3838

39-
db.vm.provision "file", source: "./scripts", destination: "/tmp/scripts"
40-
db.vm.provision "file", source: "./services", destination: "/tmp/services"
41-
db.vm.provision "file", source: "./score-server", destination: "/tmp/score-server"
42-
db.vm.provision "file", source: "./dummy-web-app", destination: "/tmp/dummy-web-app"
39+
hub.vm.provision "file", source: "./scripts", destination: "/tmp/scripts"
40+
hub.vm.provision "file", source: "./services", destination: "/tmp/services"
41+
hub.vm.provision "file", source: "./score-server", destination: "/tmp/score-server"
42+
hub.vm.provision "file", source: "./dummy-web-app", destination: "/tmp/dummy-web-app"
4343

44-
db.vm.provision "shell",
44+
hub.vm.provision "shell",
4545
inline: <<-SCRIPT
4646
#!/usr/bin/env bash
4747
set -euo pipefail
@@ -52,7 +52,7 @@ Vagrant.configure("2") do |config|
5252
5353
rm -rf /root/{score-server,services,dummy-web-app}
5454
sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/
55-
bash /tmp/scripts/init-db.sh
55+
bash /tmp/scripts/init-hub.sh
5656
SCRIPT
5757
end
5858

@@ -81,7 +81,7 @@ Vagrant.configure("2") do |config|
8181
sudo systemctl restart ssh
8282
8383
export team_name="Team-#{i}"
84-
export db_addr='#{db_addr}'
84+
export hub_addr='#{hub_addr}'
8585
bash /tmp/scripts/init.sh
8686
bats -F pretty /.ws/scripts/test.bats
8787
SCRIPT
File renamed without changes.

scripts/init.sh

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ if [[ -z "${team_name}" ]]; then
1818
log-fatal 'Env var "team_name" not set at runtime'
1919
fi
2020

21-
if [[ -z "${db_addr}" ]]; then
22-
log-fatal 'Env var "db_addr" not set at runtime'
21+
if [[ -z "${hub_addr}" ]]; then
22+
log-fatal 'Env var "hub_addr" not set at runtime'
2323
fi
2424

2525
###
@@ -84,13 +84,13 @@ ufw default allow incoming
8484
ufw default allow outgoing
8585
ufw deny out 8000
8686
log-info 'Adding file for teams to know which IP to use for one of the networking challenges'
87-
printf '%s\n' "${db_addr}" > /home/appuser/.remote-ip.txt
87+
printf '%s\n' "${hub_addr}" > /home/appuser/.remote-ip.txt
8888

8989
###
9090
log-info 'Writing out vars to env file(s) for systemd services'
9191
rm -f "${wsroot}"/env && touch "${wsroot}"/env
9292
{
93-
printf 'db_addr=%s\n' "${db_addr}"
93+
printf 'hub_addr=%s\n' "${hub_addr}"
9494
printf 'team_name=%s\n' "$(hostname)"
9595
} >> "${wsroot}"/env
9696

@@ -103,24 +103,24 @@ systemctl enable linux-workshop-admin.timer
103103
systemctl start linux-workshop-admin.timer
104104

105105
###
106-
_db_init() {
106+
_hub_init() {
107107
# shellcheck disable=SC1091
108108
source /usr/local/share/ezlog/src/main.sh
109109
log-info 'Waiting for DB to be reachable...'
110-
until timeout 2s psql -U postgres -h "${db_addr}" -c 'SELECT NOW();' > /dev/null ; do
110+
until timeout 2s psql -U postgres -h "${hub_addr}" -c 'SELECT NOW();' > /dev/null ; do
111111
log-info 'Still waiting for DB to be reachable...'
112112
sleep 5
113113
done
114114
log-info 'Successfully reached DB, trying to initialize with base values so team appears on dashboard...'
115115
# until-loop because DB can be reachable before schema is made
116-
until psql -U postgres -h "${db_addr}" -c "INSERT INTO scoring (timestamp, team_name, last_challenge_completed, score) VALUES (NOW(), '$(hostname)', 0, 0);" > /dev/null ; do
116+
until psql -U postgres -h "${hub_addr}" -c "INSERT INTO scoring (timestamp, team_name, last_challenge_completed, score) VALUES (NOW(), '$(hostname)', 0, 0);" > /dev/null ; do
117117
log-info 'Issue with setting base values; trying again...'
118118
sleep 1
119119
done
120120
log-info 'Successfully initialized with base values'
121121
}
122-
export -f _db_init
123-
timeout 180s bash -c _db_init
122+
export -f _hub_init
123+
timeout 180s bash -c _hub_init
124124

125125
###
126126
log-info 'Dumping the first instruction(s) to the appuser homedir'

scripts/linux-workshop-admin.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ _get-last-challenge-completed() {
6767
# _accrue-points adds monotonically-increasing point values, the rate of which
6868
# will increase over time at aggregate since this is called per-challenge.
6969
_accrue-points() {
70-
psql -U postgres -h "${db_addr:-NOT_SET}" -c "
70+
psql -U postgres -h "${hub_addr:-NOT_SET}" -c "
7171
INSERT INTO scoring (
7272
timestamp,
7373
team_name,
@@ -131,7 +131,7 @@ _check-debfile-service-running() {
131131
}
132132

133133
_check-webapp-reachable() {
134-
if timeout 1s curl -fsSL "${db_addr:-NOT_SET}:8000" > /dev/null ; then
134+
if timeout 1s curl -fsSL "${hub_addr:-NOT_SET}:8000" > /dev/null ; then
135135
_score-for-challenge 5
136136
else
137137
log-error "web app is not reachable"

scripts/provision-ec2-team-parallelizer.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ source "${HOME}/.local/ezlog/src/main.sh"
1818

1919
server_num="${1:-NOT_SET}"
2020

21-
if [[ -z "${db_priv_ip:-NOT_SET}" ]] ; then
22-
log-fatal 'db_priv_ip not provided to team server provisioning script'
21+
if [[ -z "${hub_priv_ip:-NOT_SET}" ]] ; then
22+
log-fatal 'hub_priv_ip not provided to team server provisioning script'
2323
fi
2424
if [[ -z "${team_server_ips:-NOT_SET}" ]] ; then
2525
log-fatal 'team_server_ips not provided to team server provisioning script'
@@ -32,7 +32,7 @@ log-info "Adding files to Team server ${server_num} at ${server_ip}..."
3232
scp -P 2332 -r -o StrictHostKeyChecking=accept-new ../scripts ../services ../instructions ../dummy-app-src admin@"${server_ip}":/tmp
3333

3434
log-info "Running init on Team server ${server_num} at ${server_ip}..."
35-
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"
35+
ssh -p 2332 admin@"${server_ip}" "export team_name=Team-${server_num} && export hub_addr=${hub_priv_ip} && sudo -E bash /tmp/scripts/init.sh"
3636

3737
log-info "Running tests on Team server ${server_num} at ${server_ip}..."
3838
ssh -p 2332 admin@"${server_ip}" "sudo -E bats /.ws/scripts/test.bats"

scripts/provision-ec2.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ set -euo pipefail
44
################################################################################
55
# Root script to provision AWS EC2 instances for the workshop.
66
#
7-
# The DB server is provisioned first, and then each team server is provisioned
7+
# The Hub server is provisioned first, and then each team server is provisioned
88
# in parallel by the neighbor script.
99
################################################################################
1010

@@ -31,25 +31,25 @@ log-info 'Getting Terraform outputs...'
3131
(cd ../terraform && terraform output -json) > "${outputs_file}"
3232

3333
log-info 'Determining IP addresses of DB server...'
34-
db_pub_ip="$(jq -rc '.db_pub_ip.value' ${outputs_file})"
35-
db_priv_ip="$(jq -rc '.db_priv_ip.value' ${outputs_file})"
36-
log-info "DB IPs: Public ${db_pub_ip}, Private ${db_priv_ip}"
34+
hub_pub_ip="$(jq -rc '.hub_pub_ip.value' ${outputs_file})"
35+
hub_priv_ip="$(jq -rc '.hub_priv_ip.value' ${outputs_file})"
36+
log-info "Hub IPs: Public ${hub_pub_ip}, Private ${hub_priv_ip}"
3737

3838
log-info 'Determining IP addresses of Team servers...'
3939
num_teams="$(jq '[.instance_ips.value[]] | length' ${outputs_file})"
4040
team_server_ips="$(jq -c '[.instance_ips.value[]]' ${outputs_file})"
4141
log-info "${num_teams} teams, with IPs of: ${team_server_ips}"
4242

43-
# Provision the DB server first, so that if it fails we know we're about to have
43+
# Provision the Hub server first, so that if it fails we know we're about to have
4444
# a bad time overall
45-
log-info 'Adding DB server init script...'
46-
scp -P 2332 -o StrictHostKeyChecking=accept-new -r ../{scripts,services,score-server,dummy-web-app} "admin@${db_pub_ip}":/tmp
47-
ssh -p 2332 admin@"${db_pub_ip}" -- 'sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/'
48-
log-info 'Running DB server init script...'
49-
ssh -p 2332 admin@"${db_pub_ip}" 'sudo bash /tmp/scripts/init-db.sh'
45+
log-info 'Adding Hub server init script...'
46+
scp -P 2332 -o StrictHostKeyChecking=accept-new -r ../{scripts,services,score-server,dummy-web-app} "admin@${hub_pub_ip}":/tmp
47+
ssh -p 2332 admin@"${hub_pub_ip}" -- 'sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/'
48+
log-info 'Running Hub server init script...'
49+
ssh -p 2332 admin@"${hub_pub_ip}" 'sudo bash /tmp/scripts/init-hub.sh'
5050

5151
# Export needed vars so the subscript can see them
52-
export db_priv_ip
52+
export hub_priv_ip
5353
export team_server_ips
5454

5555
# Parallelize provisioning of the team servers

scripts/test.bats

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ fi
2020
# This file should have been populated on init
2121
# shellcheck disable=SC1091
2222
source "${wsroot}"/env || exit 1
23-
[[ -n "${db_addr:-}" ]] || exit 1
23+
[[ -n "${hub_addr:-}" ]] || exit 1
2424

2525
# setup* and teardown* are bats-specifically-named pre-/post-test hook
2626
# functions. <setup|teardown>_file run once, period, and <setup|teardown> run
@@ -89,7 +89,7 @@ teardown_file() {
8989
}
9090

9191
_reset-score() {
92-
psql -U postgres -h "${db_addr}" -c "
92+
psql -U postgres -h "${hub_addr}" -c "
9393
DELETE FROM scoring WHERE team_name = '$(hostname)';
9494
INSERT INTO scoring (timestamp, team_name, last_challenge_completed, score) VALUES (NOW(), '$(hostname)', 0, 0);
9595
"
@@ -101,7 +101,7 @@ _get-score() {
101101
# Need to stop again becaue starting the .service restarts the timer because
102102
# of its 'Want' directive
103103
systemctl stop linux-workshop-admin.timer
104-
local score="$(psql -U postgres -h "${db_addr}" -tAc 'SELECT SUM(score) FROM scoring;')"
104+
local score="$(psql -U postgres -h "${hub_addr}" -tAc 'SELECT SUM(score) FROM scoring;')"
105105
printf '%s' "${score}"
106106
}
107107

@@ -288,7 +288,7 @@ _solve-challenge-7() {
288288
sleep 1
289289
printf 'DEBUG: Score from challenge 5: %s\n' "${score}"
290290
counter=0
291-
until timeout 1s curl -fsSL "${db_addr}:8000" ; do
291+
until timeout 1s curl -fsSL "${hub_addr}:8000" ; do
292292
printf 'Web app not reachable, trying again...\n' >&2
293293
counter="$((counter + 1))"
294294
if [[ "${counter}" -ge 30 ]] ; then

terraform/main.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ provider "aws" {
55
}
66

77
locals {
8-
db_ip = "10.0.1.10"
8+
hub_ip = "10.0.1.10"
99
region = var.aws_region
1010
name = "${var.event_name}-osc-workshop-linux"
1111
my_cidr = "${chomp(data.http.my_ip.response_body)}/32"
@@ -89,11 +89,11 @@ module "security_group" {
8989
tags = local.tags
9090
}
9191

92-
module "db" {
92+
module "hub" {
9393
source = "terraform-aws-modules/ec2-instance/aws"
9494
version = "~> 4.0"
9595

96-
name = "${local.name}-db"
96+
name = "${local.name}-hub"
9797

9898
ami = data.aws_ami.latest.id
9999
instance_type = "t3a.micro"

terraform/outputs.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,14 @@ output "instance_ips" {
22
value = { for instance in module.team_servers : instance.tags_all["Name"] => instance.public_ip }
33
}
44

5-
output "db_pub_ip" {
6-
value = module.db.public_ip
5+
output "hub_pub_ip" {
6+
value = module.hub.public_ip
77
}
88

9-
output "db_pub_endpoint" {
10-
value = "http://${module.db.public_ip}:8080"
9+
output "hub_pub_endpoint" {
10+
value = "http://${module.hub.public_ip}:8080"
1111
}
1212

13-
output "db_priv_ip" {
14-
value = module.db.private_ip
13+
output "hub_priv_ip" {
14+
value = module.hub.private_ip
1515
}

0 commit comments

Comments
 (0)