From 30836373fdf2cb3d4d2230fc18d00b011cd69f09 Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 4 Feb 2024 00:38:43 -0600 Subject: [PATCH 1/7] WIP post-Codemash --- linux/instructions/challenge_1.md | 2 ++ linux/instructions/challenge_4.md | 3 ++- linux/instructions/challenge_5.md | 2 ++ linux/scripts/linux-workshop-admin.sh | 4 ++-- 4 files changed, 8 insertions(+), 3 deletions(-) diff --git a/linux/instructions/challenge_1.md b/linux/instructions/challenge_1.md index a01e5d9..e88102b 100644 --- a/linux/instructions/challenge_1.md +++ b/linux/instructions/challenge_1.md @@ -11,3 +11,5 @@ a Go binary. Take note of any error messages when trying to build it, and fix any issues you find. + +NOTE APP NEEDS TO BE CALLED `app`, NOT `main` diff --git a/linux/instructions/challenge_4.md b/linux/instructions/challenge_4.md index d5b365c..d732017 100644 --- a/linux/instructions/challenge_4.md +++ b/linux/instructions/challenge_4.md @@ -24,4 +24,5 @@ look at the `/opt/app` directory again, you may have noticed that there is a correctly-installed app binary. Once you do that, be sure to check the `systemd` and/or `journald` logs of the -new `app-deb.service` to make sure it's running successfully! +new `app-deb.service` to make sure it's running successfully! (and, just like +the last one, that it would keep running after a reboot) diff --git a/linux/instructions/challenge_5.md b/linux/instructions/challenge_5.md index d3036c1..3f30a12 100644 --- a/linux/instructions/challenge_5.md +++ b/linux/instructions/challenge_5.md @@ -22,5 +22,7 @@ number is: 1. *Not* `8080` +1. *Not* managed by the `iptables` tool. + Finally, you will want to figure out what firewall issue your own server has that seems to be causing problems, and fix it. diff --git a/linux/scripts/linux-workshop-admin.sh b/linux/scripts/linux-workshop-admin.sh index 46fe892..f3aff85 100755 --- a/linux/scripts/linux-workshop-admin.sh +++ b/linux/scripts/linux-workshop-admin.sh @@ -54,8 +54,8 @@ _score-for-challenge() { # challenges. _get-last-challenge-completed() { local last_challenge_completed - last_challenge_completed="$(find /home/appuser -type f -name '*.md' | grep -E -o '[0-9]+' | sort -h | tail -n1)" - max_possible_challenge_completed="$(find "${wsroot}"/instructions -type f -name '*.md' | grep -E -o '[0-9]+' | sort -h | tail -n1)" + last_challenge_completed="$(find /home/appuser -type f -name 'challenge_*.md' | grep -E -o '[0-9]+' | sort -h | tail -n1)" + max_possible_challenge_completed="$(find "${wsroot}"/instructions -type f -name 'challenge_*.md' | grep -E -o '[0-9]+' | sort -h | tail -n1)" if [[ -f /home/appuser/congrats.md ]] ; then last_challenge_completed="${max_possible_challenge_completed}" else From 8e077118755d225aba8b6e799e63017714a8d201 Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 20 Oct 2024 16:31:23 -0500 Subject: [PATCH 2/7] Move files up a level, tidy up some challenge instructions --- linux/Makefile => Makefile | 0 README.md | 44 ++++++++++++++++-- linux/Vagrantfile => Vagrantfile | 0 {linux/docs => docs}/Linux-Workshop.odp | Bin .../.gitignore | 0 .../dist/linux/app/DEBIAN/control | 0 .../dist/linux/app/usr/bin/.env | 0 {linux/dummy-app-src => dummy-app-src}/go.mod | 0 .../dummy-app-src => dummy-app-src}/main.go | 0 .../dummy-web-app => dummy-web-app}/README.md | 0 {linux/dummy-web-app => dummy-web-app}/go.mod | 0 {linux/dummy-web-app => dummy-web-app}/go.sum | 0 .../dummy-web-app => dummy-web-app}/main.go | 0 .../challenge_0.md | 0 .../challenge_1.md | 2 +- .../challenge_2.md | 0 .../challenge_3.md | 0 .../challenge_4.md | 0 .../challenge_5.md | 4 +- .../challenge_6.md | 0 .../challenge_7.md | 0 .../instructions => instructions}/congrats.md | 0 linux/README.md | 42 ----------------- .../score-server => score-server}/README.md | 0 .../content/content.go | 0 .../content/www/index.html | 0 {linux/score-server => score-server}/go.mod | 0 {linux/score-server => score-server}/go.sum | 0 {linux/score-server => score-server}/main.go | 0 .../pkg/fetch-server/serve.go | 0 .../pkg/fetch-server/serve_test.go | 0 {linux/scripts => scripts}/ci.sh | 0 {linux/scripts => scripts}/init-db.sh | 0 {linux/scripts => scripts}/init.sh | 0 .../linux-workshop-admin.sh | 0 .../provision-ec2-team-parallelizer.sh | 0 {linux/scripts => scripts}/provision-ec2.sh | 0 {linux/scripts => scripts}/setup-git.sh | 0 {linux/scripts => scripts}/test.bats | 0 .../dummy-web-app.service | 0 .../linux-workshop-admin.service | 0 .../linux-workshop-admin.timer | 0 .../score-server.service | 0 {linux/terraform => terraform}/.gitignore | 0 .../.terraform.lock.hcl | 0 {linux/terraform => terraform}/data.tf | 0 {linux/terraform => terraform}/main.tf | 0 {linux/terraform => terraform}/outputs.tf | 0 {linux/terraform => terraform}/variables.tf | 0 49 files changed, 44 insertions(+), 48 deletions(-) rename linux/Makefile => Makefile (100%) rename linux/Vagrantfile => Vagrantfile (100%) rename {linux/docs => docs}/Linux-Workshop.odp (100%) rename {linux/dummy-app-src => dummy-app-src}/.gitignore (100%) rename {linux/dummy-app-src => dummy-app-src}/dist/linux/app/DEBIAN/control (100%) rename {linux/dummy-app-src => dummy-app-src}/dist/linux/app/usr/bin/.env (100%) rename {linux/dummy-app-src => dummy-app-src}/go.mod (100%) rename {linux/dummy-app-src => dummy-app-src}/main.go (100%) rename {linux/dummy-web-app => dummy-web-app}/README.md (100%) rename {linux/dummy-web-app => dummy-web-app}/go.mod (100%) rename {linux/dummy-web-app => dummy-web-app}/go.sum (100%) rename {linux/dummy-web-app => dummy-web-app}/main.go (100%) rename {linux/instructions => instructions}/challenge_0.md (100%) rename {linux/instructions => instructions}/challenge_1.md (90%) rename {linux/instructions => instructions}/challenge_2.md (100%) rename {linux/instructions => instructions}/challenge_3.md (100%) rename {linux/instructions => instructions}/challenge_4.md (100%) rename {linux/instructions => instructions}/challenge_5.md (94%) rename {linux/instructions => instructions}/challenge_6.md (100%) rename {linux/instructions => instructions}/challenge_7.md (100%) rename {linux/instructions => instructions}/congrats.md (100%) delete mode 100644 linux/README.md rename {linux/score-server => score-server}/README.md (100%) rename {linux/score-server => score-server}/content/content.go (100%) rename {linux/score-server => score-server}/content/www/index.html (100%) rename {linux/score-server => score-server}/go.mod (100%) rename {linux/score-server => score-server}/go.sum (100%) rename {linux/score-server => score-server}/main.go (100%) rename {linux/score-server => score-server}/pkg/fetch-server/serve.go (100%) rename {linux/score-server => score-server}/pkg/fetch-server/serve_test.go (100%) rename {linux/scripts => scripts}/ci.sh (100%) rename {linux/scripts => scripts}/init-db.sh (100%) rename {linux/scripts => scripts}/init.sh (100%) rename {linux/scripts => scripts}/linux-workshop-admin.sh (100%) rename {linux/scripts => scripts}/provision-ec2-team-parallelizer.sh (100%) rename {linux/scripts => scripts}/provision-ec2.sh (100%) rename {linux/scripts => scripts}/setup-git.sh (100%) rename {linux/scripts => scripts}/test.bats (100%) rename {linux/services => services}/dummy-web-app.service (100%) rename {linux/services => services}/linux-workshop-admin.service (100%) rename {linux/services => services}/linux-workshop-admin.timer (100%) rename {linux/services => services}/score-server.service (100%) rename {linux/terraform => terraform}/.gitignore (100%) rename {linux/terraform => terraform}/.terraform.lock.hcl (100%) rename {linux/terraform => terraform}/data.tf (100%) rename {linux/terraform => terraform}/main.tf (100%) rename {linux/terraform => terraform}/outputs.tf (100%) rename {linux/terraform => terraform}/variables.tf (100%) diff --git a/linux/Makefile b/Makefile similarity index 100% rename from linux/Makefile rename to Makefile diff --git a/README.md b/README.md index 0010ce4..1c1cee0 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,42 @@ -Workshops, Hackathons, etc -========================== +Linux System Breakfixing +======================== -This repository houses workshop, etc. content put on by OpenSourceCorp. +In this workshop, teams will work to fix the broken deployment of an application +running on a Linux server. + +System Requirements +------------------- + +Note that this workshop content was authored on a Debian Linux machine, and so +the various scripts & utilities are written in support of that. There may be a +few instances of code that is non-portable to BSDs like macOS, but should work +fine on WSL. + +--- + +As a ***workshop administrator***, you will need the following: + +- A terminal emulator capable of running the `bash` shell program + +- [HashiCorp Terraform](https://terraform.io) (if running workshop on a cloud + platform) + +- x + +In addition, for local testing you will need [HashiCorp +Vagrant](https://www.vagrantup.com/), and at least one installation of a +supported Vagrant provider. At the time of this writing, those supported +providers were VirtualBox and `libvirt`. If on WSLv2 on Windows, you will have a +MUCH easier time using the `libvirt` provider. + +--- + +***Workshop participants*** will need the following: + +- An SSH client + - On Windows, this is typically `puTTY` as a standalone tool, or Git Bash or + WSL. macOS should already have the `ssh` client program installed. + - Note: participants will ***not*** need knowledge of SSH key management, etc. + -- auth to the team servers will be password-based. + +- Little enough knowledge of Linux OSes to not figure out how to cheat `:)` diff --git a/linux/Vagrantfile b/Vagrantfile similarity index 100% rename from linux/Vagrantfile rename to Vagrantfile diff --git a/linux/docs/Linux-Workshop.odp b/docs/Linux-Workshop.odp similarity index 100% rename from linux/docs/Linux-Workshop.odp rename to docs/Linux-Workshop.odp diff --git a/linux/dummy-app-src/.gitignore b/dummy-app-src/.gitignore similarity index 100% rename from linux/dummy-app-src/.gitignore rename to dummy-app-src/.gitignore diff --git a/linux/dummy-app-src/dist/linux/app/DEBIAN/control b/dummy-app-src/dist/linux/app/DEBIAN/control similarity index 100% rename from linux/dummy-app-src/dist/linux/app/DEBIAN/control rename to dummy-app-src/dist/linux/app/DEBIAN/control diff --git a/linux/dummy-app-src/dist/linux/app/usr/bin/.env b/dummy-app-src/dist/linux/app/usr/bin/.env similarity index 100% rename from linux/dummy-app-src/dist/linux/app/usr/bin/.env rename to dummy-app-src/dist/linux/app/usr/bin/.env diff --git a/linux/dummy-app-src/go.mod b/dummy-app-src/go.mod similarity index 100% rename from linux/dummy-app-src/go.mod rename to dummy-app-src/go.mod diff --git a/linux/dummy-app-src/main.go b/dummy-app-src/main.go similarity index 100% rename from linux/dummy-app-src/main.go rename to dummy-app-src/main.go diff --git a/linux/dummy-web-app/README.md b/dummy-web-app/README.md similarity index 100% rename from linux/dummy-web-app/README.md rename to dummy-web-app/README.md diff --git a/linux/dummy-web-app/go.mod b/dummy-web-app/go.mod similarity index 100% rename from linux/dummy-web-app/go.mod rename to dummy-web-app/go.mod diff --git a/linux/dummy-web-app/go.sum b/dummy-web-app/go.sum similarity index 100% rename from linux/dummy-web-app/go.sum rename to dummy-web-app/go.sum diff --git a/linux/dummy-web-app/main.go b/dummy-web-app/main.go similarity index 100% rename from linux/dummy-web-app/main.go rename to dummy-web-app/main.go diff --git a/linux/instructions/challenge_0.md b/instructions/challenge_0.md similarity index 100% rename from linux/instructions/challenge_0.md rename to instructions/challenge_0.md diff --git a/linux/instructions/challenge_1.md b/instructions/challenge_1.md similarity index 90% rename from linux/instructions/challenge_1.md rename to instructions/challenge_1.md index e88102b..368add7 100644 --- a/linux/instructions/challenge_1.md +++ b/instructions/challenge_1.md @@ -12,4 +12,4 @@ a Go binary. Take note of any error messages when trying to build it, and fix any issues you find. -NOTE APP NEEDS TO BE CALLED `app`, NOT `main` +(NOTE: the built application needs to be named `app`, NOT `main`) diff --git a/linux/instructions/challenge_2.md b/instructions/challenge_2.md similarity index 100% rename from linux/instructions/challenge_2.md rename to instructions/challenge_2.md diff --git a/linux/instructions/challenge_3.md b/instructions/challenge_3.md similarity index 100% rename from linux/instructions/challenge_3.md rename to instructions/challenge_3.md diff --git a/linux/instructions/challenge_4.md b/instructions/challenge_4.md similarity index 100% rename from linux/instructions/challenge_4.md rename to instructions/challenge_4.md diff --git a/linux/instructions/challenge_5.md b/instructions/challenge_5.md similarity index 94% rename from linux/instructions/challenge_5.md rename to instructions/challenge_5.md index 3f30a12..8271ae0 100644 --- a/linux/instructions/challenge_5.md +++ b/instructions/challenge_5.md @@ -20,9 +20,9 @@ number is: 1. Higher than `6000` -1. *Not* `8080` +2. *Not* `8080` -1. *Not* managed by the `iptables` tool. +3. *Not* managed by the `iptables` tool. Finally, you will want to figure out what firewall issue your own server has that seems to be causing problems, and fix it. diff --git a/linux/instructions/challenge_6.md b/instructions/challenge_6.md similarity index 100% rename from linux/instructions/challenge_6.md rename to instructions/challenge_6.md diff --git a/linux/instructions/challenge_7.md b/instructions/challenge_7.md similarity index 100% rename from linux/instructions/challenge_7.md rename to instructions/challenge_7.md diff --git a/linux/instructions/congrats.md b/instructions/congrats.md similarity index 100% rename from linux/instructions/congrats.md rename to instructions/congrats.md diff --git a/linux/README.md b/linux/README.md deleted file mode 100644 index 1c1cee0..0000000 --- a/linux/README.md +++ /dev/null @@ -1,42 +0,0 @@ -Linux System Breakfixing -======================== - -In this workshop, teams will work to fix the broken deployment of an application -running on a Linux server. - -System Requirements -------------------- - -Note that this workshop content was authored on a Debian Linux machine, and so -the various scripts & utilities are written in support of that. There may be a -few instances of code that is non-portable to BSDs like macOS, but should work -fine on WSL. - ---- - -As a ***workshop administrator***, you will need the following: - -- A terminal emulator capable of running the `bash` shell program - -- [HashiCorp Terraform](https://terraform.io) (if running workshop on a cloud - platform) - -- x - -In addition, for local testing you will need [HashiCorp -Vagrant](https://www.vagrantup.com/), and at least one installation of a -supported Vagrant provider. At the time of this writing, those supported -providers were VirtualBox and `libvirt`. If on WSLv2 on Windows, you will have a -MUCH easier time using the `libvirt` provider. - ---- - -***Workshop participants*** will need the following: - -- An SSH client - - On Windows, this is typically `puTTY` as a standalone tool, or Git Bash or - WSL. macOS should already have the `ssh` client program installed. - - Note: participants will ***not*** need knowledge of SSH key management, etc. - -- auth to the team servers will be password-based. - -- Little enough knowledge of Linux OSes to not figure out how to cheat `:)` diff --git a/linux/score-server/README.md b/score-server/README.md similarity index 100% rename from linux/score-server/README.md rename to score-server/README.md diff --git a/linux/score-server/content/content.go b/score-server/content/content.go similarity index 100% rename from linux/score-server/content/content.go rename to score-server/content/content.go diff --git a/linux/score-server/content/www/index.html b/score-server/content/www/index.html similarity index 100% rename from linux/score-server/content/www/index.html rename to score-server/content/www/index.html diff --git a/linux/score-server/go.mod b/score-server/go.mod similarity index 100% rename from linux/score-server/go.mod rename to score-server/go.mod diff --git a/linux/score-server/go.sum b/score-server/go.sum similarity index 100% rename from linux/score-server/go.sum rename to score-server/go.sum diff --git a/linux/score-server/main.go b/score-server/main.go similarity index 100% rename from linux/score-server/main.go rename to score-server/main.go diff --git a/linux/score-server/pkg/fetch-server/serve.go b/score-server/pkg/fetch-server/serve.go similarity index 100% rename from linux/score-server/pkg/fetch-server/serve.go rename to score-server/pkg/fetch-server/serve.go diff --git a/linux/score-server/pkg/fetch-server/serve_test.go b/score-server/pkg/fetch-server/serve_test.go similarity index 100% rename from linux/score-server/pkg/fetch-server/serve_test.go rename to score-server/pkg/fetch-server/serve_test.go diff --git a/linux/scripts/ci.sh b/scripts/ci.sh similarity index 100% rename from linux/scripts/ci.sh rename to scripts/ci.sh diff --git a/linux/scripts/init-db.sh b/scripts/init-db.sh similarity index 100% rename from linux/scripts/init-db.sh rename to scripts/init-db.sh diff --git a/linux/scripts/init.sh b/scripts/init.sh similarity index 100% rename from linux/scripts/init.sh rename to scripts/init.sh diff --git a/linux/scripts/linux-workshop-admin.sh b/scripts/linux-workshop-admin.sh similarity index 100% rename from linux/scripts/linux-workshop-admin.sh rename to scripts/linux-workshop-admin.sh diff --git a/linux/scripts/provision-ec2-team-parallelizer.sh b/scripts/provision-ec2-team-parallelizer.sh similarity index 100% rename from linux/scripts/provision-ec2-team-parallelizer.sh rename to scripts/provision-ec2-team-parallelizer.sh diff --git a/linux/scripts/provision-ec2.sh b/scripts/provision-ec2.sh similarity index 100% rename from linux/scripts/provision-ec2.sh rename to scripts/provision-ec2.sh diff --git a/linux/scripts/setup-git.sh b/scripts/setup-git.sh similarity index 100% rename from linux/scripts/setup-git.sh rename to scripts/setup-git.sh diff --git a/linux/scripts/test.bats b/scripts/test.bats similarity index 100% rename from linux/scripts/test.bats rename to scripts/test.bats diff --git a/linux/services/dummy-web-app.service b/services/dummy-web-app.service similarity index 100% rename from linux/services/dummy-web-app.service rename to services/dummy-web-app.service diff --git a/linux/services/linux-workshop-admin.service b/services/linux-workshop-admin.service similarity index 100% rename from linux/services/linux-workshop-admin.service rename to services/linux-workshop-admin.service diff --git a/linux/services/linux-workshop-admin.timer b/services/linux-workshop-admin.timer similarity index 100% rename from linux/services/linux-workshop-admin.timer rename to services/linux-workshop-admin.timer diff --git a/linux/services/score-server.service b/services/score-server.service similarity index 100% rename from linux/services/score-server.service rename to services/score-server.service diff --git a/linux/terraform/.gitignore b/terraform/.gitignore similarity index 100% rename from linux/terraform/.gitignore rename to terraform/.gitignore diff --git a/linux/terraform/.terraform.lock.hcl b/terraform/.terraform.lock.hcl similarity index 100% rename from linux/terraform/.terraform.lock.hcl rename to terraform/.terraform.lock.hcl diff --git a/linux/terraform/data.tf b/terraform/data.tf similarity index 100% rename from linux/terraform/data.tf rename to terraform/data.tf diff --git a/linux/terraform/main.tf b/terraform/main.tf similarity index 100% rename from linux/terraform/main.tf rename to terraform/main.tf diff --git a/linux/terraform/outputs.tf b/terraform/outputs.tf similarity index 100% rename from linux/terraform/outputs.tf rename to terraform/outputs.tf diff --git a/linux/terraform/variables.tf b/terraform/variables.tf similarity index 100% rename from linux/terraform/variables.tf rename to terraform/variables.tf From e643e4d6fde91fe2faf1b9ecfab2aa8b7e3ff441 Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 20 Oct 2024 16:36:50 -0500 Subject: [PATCH 3/7] Fix CI pathing --- .github/workflows/main.yaml | 19 +++++++++---------- terraform/variables.tf | 1 - 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index e23a9c4..78b0640 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -2,21 +2,20 @@ name: main on: push: - branches: ['**'] + branches: ["**"] jobs: main: runs-on: ubuntu-latest steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Checkout repository + uses: actions/checkout@v4 - - name: Set up Go 1.19+ - uses: actions/setup-go@v4 - with: - go-version: '>=1.19' + - name: Set up Go 1.19+ + uses: actions/setup-go@v4 + with: + go-version: ">=1.19" - # Linux workshop - - name: CI - run: 'cd ./linux && bash ./scripts/ci.sh' + - name: CI + run: "bash ./scripts/ci.sh" diff --git a/terraform/variables.tf b/terraform/variables.tf index 870ad77..2a27336 100644 --- a/terraform/variables.tf +++ b/terraform/variables.tf @@ -19,7 +19,6 @@ variable "custom_security_group_ingress" { variable "event_name" { description = "Name of the event that the workshop is being run for, e.g. 'STL-Public-Library-Hackathon'" type = string - default = "testing" } variable "num_teams" { From fc1641089c193233e346f563e627c661f99e14c3 Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 5 Jan 2025 21:42:37 -0600 Subject: [PATCH 4/7] Fix some typos etc --- Makefile | 2 +- score-server/{pkg => internal}/fetch-server/serve.go | 0 score-server/{pkg => internal}/fetch-server/serve_test.go | 0 score-server/main.go | 2 +- scripts/linux-workshop-admin.sh | 4 ++-- 5 files changed, 4 insertions(+), 4 deletions(-) rename score-server/{pkg => internal}/fetch-server/serve.go (100%) rename score-server/{pkg => internal}/fetch-server/serve_test.go (100%) diff --git a/Makefile b/Makefile index ac8575b..b67100f 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -local_team_servers := $(shell vagrant status | grep -E -o 'team[0-9]+') +local_team_servers = $(shell vagrant status | grep -E -o 'team[0-9]+') ci: @bash ./scripts/ci.sh diff --git a/score-server/pkg/fetch-server/serve.go b/score-server/internal/fetch-server/serve.go similarity index 100% rename from score-server/pkg/fetch-server/serve.go rename to score-server/internal/fetch-server/serve.go diff --git a/score-server/pkg/fetch-server/serve_test.go b/score-server/internal/fetch-server/serve_test.go similarity index 100% rename from score-server/pkg/fetch-server/serve_test.go rename to score-server/internal/fetch-server/serve_test.go diff --git a/score-server/main.go b/score-server/main.go index 9419830..58496ba 100644 --- a/score-server/main.go +++ b/score-server/main.go @@ -5,7 +5,7 @@ import ( "net" "net/http" - fetchserver "github.com/opensourcecorp/workshops/linux/score-server/pkg/fetch-server" + fetchserver "github.com/opensourcecorp/workshops/linux/score-server/internal/fetch-server" "github.com/sirupsen/logrus" ) diff --git a/scripts/linux-workshop-admin.sh b/scripts/linux-workshop-admin.sh index f3aff85..85c857c 100755 --- a/scripts/linux-workshop-admin.sh +++ b/scripts/linux-workshop-admin.sh @@ -35,13 +35,13 @@ _score-for-challenge() { log-info "Providing instruction to user for Challenge ${next_challenge}" cp "${wsroot}/instructions/challenge_${next_challenge}.md" /home/appuser/ # Also broadcast message to user when challenge is complete - wall "Congrats on finishing Challenge ${which_challenge}! Be sure to check your home directory for any new instruction files! (hit any key to dismiss this message)" + wall "Congrats on finishing Challenge ${which_challenge}! Be sure to check your home directory for any new instruction files! (hit Enter to dismiss this message)" else log-info 'Team is done with the workshop!' cp "${wsroot}/instructions/congrats.md" /home/appuser/ # This check suppresses an infinite loop of congratulations, lol if [[ ! -f "${wsroot}"/team_has_been_congratulated ]] ; then - wall "Congratulations -- you have completed ALL CHALLENGES! Be sure to read congrats.md in your home directory! (hit any key to dismiss this message)" + wall "Congratulations -- you have completed ALL CHALLENGES! Be sure to read congrats.md in your home directory! (hit Enter to dismiss this message)" touch "${wsroot}"/team_has_been_congratulated fi fi From 3080ae3d6692c38c8d903a22263f3b89140c0a2e Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 5 Jan 2025 21:53:37 -0600 Subject: [PATCH 5/7] Rename "db" to "hub" in preparation for score-pull vs. score-push --- Makefile | 2 +- Vagrantfile | 34 +++++++++++----------- scripts/{init-db.sh => init-hub.sh} | 0 scripts/init.sh | 18 ++++++------ scripts/linux-workshop-admin.sh | 4 +-- scripts/provision-ec2-team-parallelizer.sh | 6 ++-- scripts/provision-ec2.sh | 22 +++++++------- scripts/test.bats | 8 ++--- terraform/main.tf | 6 ++-- terraform/outputs.tf | 12 ++++---- 10 files changed, 56 insertions(+), 56 deletions(-) rename scripts/{init-db.sh => init-hub.sh} (100%) diff --git a/Makefile b/Makefile index b67100f..f088e67 100644 --- a/Makefile +++ b/Makefile @@ -20,7 +20,7 @@ connect-aws: provision-local: # Don't re-provision DB at the same time, since it throws off team server tests - @vagrant provision db + @vagrant provision hub @vagrant provision $(local_team_servers) provision-aws: diff --git a/Vagrantfile b/Vagrantfile index a7f78d1..515d400 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -22,26 +22,26 @@ Vagrant.configure("2") do |config| config.vbguest.auto_update = false end - # DB server static IP - db_addr = "10.0.1.10" - ip_bytes = db_addr.split(".") + # hub server static IP + hub_addr = "10.0.1.10" + ip_bytes = hub_addr.split(".") - config.vm.define "db" do |db| - db.vm.box = box + config.vm.define "hub" do |hub| + hub.vm.box = box - db.vm.network "private_network", ip: db_addr - db.vm.network "forwarded_port", guest: 5432, host: 5432, protocol: "tcp" # DB - db.vm.network "forwarded_port", guest: 8000, host: 8000, protocol: "tcp" # Dummy web app - db.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp" # Score dashboard + hub.vm.network "private_network", ip: hub_addr + hub.vm.network "forwarded_port", guest: 5432, host: 5432, protocol: "tcp" # hub + hub.vm.network "forwarded_port", guest: 8000, host: 8000, protocol: "tcp" # Dummy web app + hub.vm.network "forwarded_port", guest: 8080, host: 8080, protocol: "tcp" # Score dashboard - db.vm.synced_folder ".", "/vagrant", disabled: true + hub.vm.synced_folder ".", "/vagrant", disabled: true - db.vm.provision "file", source: "./scripts", destination: "/tmp/scripts" - db.vm.provision "file", source: "./services", destination: "/tmp/services" - db.vm.provision "file", source: "./score-server", destination: "/tmp/score-server" - db.vm.provision "file", source: "./dummy-web-app", destination: "/tmp/dummy-web-app" + hub.vm.provision "file", source: "./scripts", destination: "/tmp/scripts" + hub.vm.provision "file", source: "./services", destination: "/tmp/services" + hub.vm.provision "file", source: "./score-server", destination: "/tmp/score-server" + hub.vm.provision "file", source: "./dummy-web-app", destination: "/tmp/dummy-web-app" - db.vm.provision "shell", + hub.vm.provision "shell", inline: <<-SCRIPT #!/usr/bin/env bash set -euo pipefail @@ -52,7 +52,7 @@ Vagrant.configure("2") do |config| rm -rf /root/{score-server,services,dummy-web-app} sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/ - bash /tmp/scripts/init-db.sh + bash /tmp/scripts/init-hub.sh SCRIPT end @@ -81,7 +81,7 @@ Vagrant.configure("2") do |config| sudo systemctl restart ssh export team_name="Team-#{i}" - export db_addr='#{db_addr}' + export hub_addr='#{hub_addr}' bash /tmp/scripts/init.sh bats -F pretty /.ws/scripts/test.bats SCRIPT diff --git a/scripts/init-db.sh b/scripts/init-hub.sh similarity index 100% rename from scripts/init-db.sh rename to scripts/init-hub.sh diff --git a/scripts/init.sh b/scripts/init.sh index 0f92f0d..70d3675 100755 --- a/scripts/init.sh +++ b/scripts/init.sh @@ -18,8 +18,8 @@ if [[ -z "${team_name}" ]]; then log-fatal 'Env var "team_name" not set at runtime' fi -if [[ -z "${db_addr}" ]]; then - log-fatal 'Env var "db_addr" not set at runtime' +if [[ -z "${hub_addr}" ]]; then + log-fatal 'Env var "hub_addr" not set at runtime' fi ### @@ -84,13 +84,13 @@ ufw default allow incoming ufw default allow outgoing ufw deny out 8000 log-info 'Adding file for teams to know which IP to use for one of the networking challenges' -printf '%s\n' "${db_addr}" > /home/appuser/.remote-ip.txt +printf '%s\n' "${hub_addr}" > /home/appuser/.remote-ip.txt ### log-info 'Writing out vars to env file(s) for systemd services' rm -f "${wsroot}"/env && touch "${wsroot}"/env { - printf 'db_addr=%s\n' "${db_addr}" + printf 'hub_addr=%s\n' "${hub_addr}" printf 'team_name=%s\n' "$(hostname)" } >> "${wsroot}"/env @@ -103,24 +103,24 @@ systemctl enable linux-workshop-admin.timer systemctl start linux-workshop-admin.timer ### -_db_init() { +_hub_init() { # shellcheck disable=SC1091 source /usr/local/share/ezlog/src/main.sh log-info 'Waiting for DB to be reachable...' - until timeout 2s psql -U postgres -h "${db_addr}" -c 'SELECT NOW();' > /dev/null ; do + until timeout 2s psql -U postgres -h "${hub_addr}" -c 'SELECT NOW();' > /dev/null ; do log-info 'Still waiting for DB to be reachable...' sleep 5 done log-info 'Successfully reached DB, trying to initialize with base values so team appears on dashboard...' # until-loop because DB can be reachable before schema is made - 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 + 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 log-info 'Issue with setting base values; trying again...' sleep 1 done log-info 'Successfully initialized with base values' } -export -f _db_init -timeout 180s bash -c _db_init +export -f _hub_init +timeout 180s bash -c _hub_init ### log-info 'Dumping the first instruction(s) to the appuser homedir' diff --git a/scripts/linux-workshop-admin.sh b/scripts/linux-workshop-admin.sh index 85c857c..9f3cb43 100755 --- a/scripts/linux-workshop-admin.sh +++ b/scripts/linux-workshop-admin.sh @@ -67,7 +67,7 @@ _get-last-challenge-completed() { # _accrue-points adds monotonically-increasing point values, the rate of which # will increase over time at aggregate since this is called per-challenge. _accrue-points() { - psql -U postgres -h "${db_addr:-NOT_SET}" -c " + psql -U postgres -h "${hub_addr:-NOT_SET}" -c " INSERT INTO scoring ( timestamp, team_name, @@ -131,7 +131,7 @@ _check-debfile-service-running() { } _check-webapp-reachable() { - if timeout 1s curl -fsSL "${db_addr:-NOT_SET}:8000" > /dev/null ; then + if timeout 1s curl -fsSL "${hub_addr:-NOT_SET}:8000" > /dev/null ; then _score-for-challenge 5 else log-error "web app is not reachable" diff --git a/scripts/provision-ec2-team-parallelizer.sh b/scripts/provision-ec2-team-parallelizer.sh index bcc33a2..61bea22 100644 --- a/scripts/provision-ec2-team-parallelizer.sh +++ b/scripts/provision-ec2-team-parallelizer.sh @@ -18,8 +18,8 @@ source "${HOME}/.local/ezlog/src/main.sh" server_num="${1:-NOT_SET}" -if [[ -z "${db_priv_ip:-NOT_SET}" ]] ; then - log-fatal 'db_priv_ip not provided to team server provisioning script' +if [[ -z "${hub_priv_ip:-NOT_SET}" ]] ; then + log-fatal 'hub_priv_ip not provided to team server provisioning script' fi if [[ -z "${team_server_ips:-NOT_SET}" ]] ; then 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}..." scp -P 2332 -r -o StrictHostKeyChecking=accept-new ../scripts ../services ../instructions ../dummy-app-src admin@"${server_ip}":/tmp log-info "Running init on Team server ${server_num} at ${server_ip}..." -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" +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" log-info "Running tests on Team server ${server_num} at ${server_ip}..." ssh -p 2332 admin@"${server_ip}" "sudo -E bats /.ws/scripts/test.bats" diff --git a/scripts/provision-ec2.sh b/scripts/provision-ec2.sh index 814115c..9784652 100755 --- a/scripts/provision-ec2.sh +++ b/scripts/provision-ec2.sh @@ -4,7 +4,7 @@ set -euo pipefail ################################################################################ # Root script to provision AWS EC2 instances for the workshop. # -# The DB server is provisioned first, and then each team server is provisioned +# The Hub server is provisioned first, and then each team server is provisioned # in parallel by the neighbor script. ################################################################################ @@ -31,25 +31,25 @@ log-info 'Getting Terraform outputs...' (cd ../terraform && terraform output -json) > "${outputs_file}" log-info 'Determining IP addresses of DB server...' -db_pub_ip="$(jq -rc '.db_pub_ip.value' ${outputs_file})" -db_priv_ip="$(jq -rc '.db_priv_ip.value' ${outputs_file})" -log-info "DB IPs: Public ${db_pub_ip}, Private ${db_priv_ip}" +hub_pub_ip="$(jq -rc '.hub_pub_ip.value' ${outputs_file})" +hub_priv_ip="$(jq -rc '.hub_priv_ip.value' ${outputs_file})" +log-info "Hub IPs: Public ${hub_pub_ip}, Private ${hub_priv_ip}" log-info 'Determining IP addresses of Team servers...' num_teams="$(jq '[.instance_ips.value[]] | length' ${outputs_file})" team_server_ips="$(jq -c '[.instance_ips.value[]]' ${outputs_file})" log-info "${num_teams} teams, with IPs of: ${team_server_ips}" -# Provision the DB server first, so that if it fails we know we're about to have +# Provision the Hub server first, so that if it fails we know we're about to have # a bad time overall -log-info 'Adding DB server init script...' -scp -P 2332 -o StrictHostKeyChecking=accept-new -r ../{scripts,services,score-server,dummy-web-app} "admin@${db_pub_ip}":/tmp -ssh -p 2332 admin@"${db_pub_ip}" -- 'sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/' -log-info 'Running DB server init script...' -ssh -p 2332 admin@"${db_pub_ip}" 'sudo bash /tmp/scripts/init-db.sh' +log-info 'Adding Hub server init script...' +scp -P 2332 -o StrictHostKeyChecking=accept-new -r ../{scripts,services,score-server,dummy-web-app} "admin@${hub_pub_ip}":/tmp +ssh -p 2332 admin@"${hub_pub_ip}" -- 'sudo cp -r /tmp/{score-server,services,dummy-web-app} /root/' +log-info 'Running Hub server init script...' +ssh -p 2332 admin@"${hub_pub_ip}" 'sudo bash /tmp/scripts/init-hub.sh' # Export needed vars so the subscript can see them -export db_priv_ip +export hub_priv_ip export team_server_ips # Parallelize provisioning of the team servers diff --git a/scripts/test.bats b/scripts/test.bats index 77d7148..6c0c95c 100755 --- a/scripts/test.bats +++ b/scripts/test.bats @@ -20,7 +20,7 @@ fi # This file should have been populated on init # shellcheck disable=SC1091 source "${wsroot}"/env || exit 1 -[[ -n "${db_addr:-}" ]] || exit 1 +[[ -n "${hub_addr:-}" ]] || exit 1 # setup* and teardown* are bats-specifically-named pre-/post-test hook # functions. _file run once, period, and run @@ -89,7 +89,7 @@ teardown_file() { } _reset-score() { - psql -U postgres -h "${db_addr}" -c " + psql -U postgres -h "${hub_addr}" -c " DELETE FROM scoring WHERE team_name = '$(hostname)'; INSERT INTO scoring (timestamp, team_name, last_challenge_completed, score) VALUES (NOW(), '$(hostname)', 0, 0); " @@ -101,7 +101,7 @@ _get-score() { # Need to stop again becaue starting the .service restarts the timer because # of its 'Want' directive systemctl stop linux-workshop-admin.timer - local score="$(psql -U postgres -h "${db_addr}" -tAc 'SELECT SUM(score) FROM scoring;')" + local score="$(psql -U postgres -h "${hub_addr}" -tAc 'SELECT SUM(score) FROM scoring;')" printf '%s' "${score}" } @@ -288,7 +288,7 @@ _solve-challenge-7() { sleep 1 printf 'DEBUG: Score from challenge 5: %s\n' "${score}" counter=0 - until timeout 1s curl -fsSL "${db_addr}:8000" ; do + until timeout 1s curl -fsSL "${hub_addr}:8000" ; do printf 'Web app not reachable, trying again...\n' >&2 counter="$((counter + 1))" if [[ "${counter}" -ge 30 ]] ; then diff --git a/terraform/main.tf b/terraform/main.tf index 97d969b..cbcba0b 100644 --- a/terraform/main.tf +++ b/terraform/main.tf @@ -5,7 +5,7 @@ provider "aws" { } locals { - db_ip = "10.0.1.10" + hub_ip = "10.0.1.10" region = var.aws_region name = "${var.event_name}-osc-workshop-linux" my_cidr = "${chomp(data.http.my_ip.response_body)}/32" @@ -89,11 +89,11 @@ module "security_group" { tags = local.tags } -module "db" { +module "hub" { source = "terraform-aws-modules/ec2-instance/aws" version = "~> 4.0" - name = "${local.name}-db" + name = "${local.name}-hub" ami = data.aws_ami.latest.id instance_type = "t3a.micro" diff --git a/terraform/outputs.tf b/terraform/outputs.tf index 3928af0..c0af411 100644 --- a/terraform/outputs.tf +++ b/terraform/outputs.tf @@ -2,14 +2,14 @@ output "instance_ips" { value = { for instance in module.team_servers : instance.tags_all["Name"] => instance.public_ip } } -output "db_pub_ip" { - value = module.db.public_ip +output "hub_pub_ip" { + value = module.hub.public_ip } -output "db_pub_endpoint" { - value = "http://${module.db.public_ip}:8080" +output "hub_pub_endpoint" { + value = "http://${module.hub.public_ip}:8080" } -output "db_priv_ip" { - value = module.db.private_ip +output "hub_priv_ip" { + value = module.hub.private_ip } From db54ede88e9ab53e2a1b8c6bb73bc29055ba14f1 Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 5 Jan 2025 22:07:44 -0600 Subject: [PATCH 6/7] Rename fetchserver to hubserver, and add teamserver placeholder --- .../internal/{fetch-server => hub-server}/serve.go | 6 +++--- .../internal/{fetch-server => hub-server}/serve_test.go | 2 +- score-server/internal/team-server/serve.go | 3 +++ score-server/internal/team-server/serve_test.go | 1 + score-server/main.go | 4 ++-- scripts/ci.sh | 7 +++++-- 6 files changed, 15 insertions(+), 8 deletions(-) rename score-server/internal/{fetch-server => hub-server}/serve.go (96%) rename score-server/internal/{fetch-server => hub-server}/serve_test.go (96%) create mode 100644 score-server/internal/team-server/serve.go create mode 100644 score-server/internal/team-server/serve_test.go diff --git a/score-server/internal/fetch-server/serve.go b/score-server/internal/hub-server/serve.go similarity index 96% rename from score-server/internal/fetch-server/serve.go rename to score-server/internal/hub-server/serve.go index 1bbf6b4..067663b 100644 --- a/score-server/internal/fetch-server/serve.go +++ b/score-server/internal/hub-server/serve.go @@ -1,6 +1,6 @@ -// Package fetchserver implements server-side and template-rendering logic for -// the score fetcher service -package fetchserver +// Package hubserver implements server-side and template-rendering logic for +// the Hub server's score retrieval & display services +package hubserver import ( "bytes" diff --git a/score-server/internal/fetch-server/serve_test.go b/score-server/internal/hub-server/serve_test.go similarity index 96% rename from score-server/internal/fetch-server/serve_test.go rename to score-server/internal/hub-server/serve_test.go index ae52c0f..4fc0017 100644 --- a/score-server/internal/fetch-server/serve_test.go +++ b/score-server/internal/hub-server/serve_test.go @@ -1,4 +1,4 @@ -package fetchserver +package hubserver import ( "reflect" diff --git a/score-server/internal/team-server/serve.go b/score-server/internal/team-server/serve.go new file mode 100644 index 0000000..40a1e7c --- /dev/null +++ b/score-server/internal/team-server/serve.go @@ -0,0 +1,3 @@ +// Package teamserver implements score-serving functionality on each workshop +// team's server, which is retrieved by the Hub server +package teamserver diff --git a/score-server/internal/team-server/serve_test.go b/score-server/internal/team-server/serve_test.go new file mode 100644 index 0000000..a226917 --- /dev/null +++ b/score-server/internal/team-server/serve_test.go @@ -0,0 +1 @@ +package teamserver diff --git a/score-server/main.go b/score-server/main.go index 58496ba..8f54fee 100644 --- a/score-server/main.go +++ b/score-server/main.go @@ -5,12 +5,12 @@ import ( "net" "net/http" - fetchserver "github.com/opensourcecorp/workshops/linux/score-server/internal/fetch-server" + hubserver "github.com/opensourcecorp/workshops/linux/score-server/internal/hub-server" "github.com/sirupsen/logrus" ) func main() { - http.HandleFunc("/", fetchserver.Root) + http.HandleFunc("/", hubserver.Root) addr := net.JoinHostPort("0.0.0.0", "8080") logrus.Infof("Starting server on %s\n", addr) diff --git a/scripts/ci.sh b/scripts/ci.sh index 93b120f..4a7eb9e 100644 --- a/scripts/ci.sh +++ b/scripts/ci.sh @@ -24,6 +24,7 @@ if [[ "$( Installing CI checks for Go...\n' for pkg in \ honnef.co/go/tools/cmd/staticcheck@latest \ + github.com/mgechev/revive@latest \ github.com/kisielk/errcheck@latest \ ; do go install "${pkg}" @@ -39,9 +40,11 @@ while read -r module ; do cd "${mod_dir}" printf '>> Running go vet...\n' go vet ./... - printf '>> Running linter...\n' + printf '>> Running staticcheck linter...\n' staticcheck ./... - printf '>> Running error checker...\n' + printf '>> Running revive linter...\n' + revive --set_exit_status ./... + printf '>> Running error-checker...\n' errcheck ./... ) done < /tmp/go-modules From e50a096135abbb70086f20b7e3b7b0375d62a785 Mon Sep 17 00:00:00 2001 From: "Ryan J. Price" Date: Sun, 5 Jan 2025 22:21:25 -0600 Subject: [PATCH 7/7] itty bitty baby typo fixes --- instructions/challenge_2.md | 4 ++-- instructions/challenge_3.md | 4 ++-- instructions/challenge_4.md | 4 ++-- instructions/challenge_6.md | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/instructions/challenge_2.md b/instructions/challenge_2.md index 7379a4d..5cd5253 100644 --- a/instructions/challenge_2.md +++ b/instructions/challenge_2.md @@ -18,6 +18,6 @@ following: - Once there, the app there needs to be named `run-app`, not `app` - To ensure both locations always have the same version (e.g. during hotfixes), - make a reference from the binary location to the target location without - copying the actual file. This way, any update or change will reflect in both + make a reference from the binary location to the target location *without + copying the actual file*. This way, any update or change will reflect in both places at once without needing to manually sync them. diff --git a/instructions/challenge_3.md b/instructions/challenge_3.md index 31a1739..df7d085 100644 --- a/instructions/challenge_3.md +++ b/instructions/challenge_3.md @@ -15,5 +15,5 @@ Create that service, and get it running. You need to make sure it runs *even if the system reboots* -- meaning that if the server is restarted for any reason, the app service needs to start again *without you starting it manually*. -If for any reason you need to check out more detailed logs of the service, you -can also use the separate `journalctl` command to inspect them. +If for any reason you need to check out more detailed logs of the service you're +creating, you can also use the separate `journalctl` command to inspect them. diff --git a/instructions/challenge_4.md b/instructions/challenge_4.md index d732017..6f9634d 100644 --- a/instructions/challenge_4.md +++ b/instructions/challenge_4.md @@ -24,5 +24,5 @@ look at the `/opt/app` directory again, you may have noticed that there is a correctly-installed app binary. Once you do that, be sure to check the `systemd` and/or `journald` logs of the -new `app-deb.service` to make sure it's running successfully! (and, just like -the last one, that it would keep running after a reboot) +new `app-deb.service` to make sure it's running successfully (and, just like +the last one, that it would keep running after a reboot). diff --git a/instructions/challenge_6.md b/instructions/challenge_6.md index 9e09159..25ecd5b 100644 --- a/instructions/challenge_6.md +++ b/instructions/challenge_6.md @@ -8,7 +8,7 @@ dissappeared while on a golfing trip a few weeks past. We were told that the code was about ready to deploy, just hadn't gotten the chance to merge it into the main branch. See if you can figure out how to get it up and running. -The name of the app is 'carrot-cruncher'. The last dev got the repo set up +The name of the app is "carrot-cruncher". The last dev got the repo set up somewhere on disk, but they never said where... hopefully you'll able to find it. When you do, supposedly there was a new working branch pushed to the remote repo, so you'll need to figure out how to authenticate to that repo.