From 32a2f06c1651cf44ff558935741eb44de3209a3e Mon Sep 17 00:00:00 2001 From: Adam Reese Date: Thu, 24 Aug 2023 17:17:40 -0700 Subject: [PATCH] Use Spin for building components Signed-off-by: Adam Reese --- Makefile | 2 +- README.md | 4 ++-- serve.sh | 16 ---------------- site/Makefile | 3 ++- spin.toml | 5 +++-- tests/test-server.sh | 4 ++-- 6 files changed, 10 insertions(+), 24 deletions(-) delete mode 100755 serve.sh diff --git a/Makefile b/Makefile index 260118c..50a3ebe 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,7 @@ build: .PHONY: serve serve: - ./serve.sh + spin up --sqlite @highscore/migration.sql .PHONY: test-server test-server: diff --git a/README.md b/README.md index b3f2964..0947997 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ $ brew install kateinoigakukun/wasi-vfs/wasi-vfs This will by default build all microservices per the `Makefile` in their directories: ```console -make build +spin build ``` You may also build a particular microservice by navigating into its directory @@ -39,7 +39,7 @@ make build-session The following command will serve the Finicky Whiskers site locally: ```console -make serve +spin up --sqlite @highscore/migration.sql ``` This will run the game at [http://127.0.0.1:3000](http://127.0.0.1:3000) diff --git a/serve.sh b/serve.sh deleted file mode 100755 index af50841..0000000 --- a/serve.sh +++ /dev/null @@ -1,16 +0,0 @@ -#!/usr/bin/env bash -set -euo pipefail - -# IP address and port to listen on -SPIN_ADDRESS="${SPIN_ADDRESS:-127.0.0.1:3000}" - -# Log directory for the stdout and stderr of spin components -SPIN_LOG_DIR="${SPIN_LOG_DIR:-log}" - -# Kill running jobs on exit -trap 'kill $(jobs -p)' EXIT - -# Start HTTP handlers -spin up --log-dir "${SPIN_LOG_DIR}" --file spin.toml --listen "${SPIN_ADDRESS}" --sqlite @highscore/migration.sql & - -wait diff --git a/site/Makefile b/site/Makefile index 4f2c0dd..f048823 100644 --- a/site/Makefile +++ b/site/Makefile @@ -1,3 +1,4 @@ .PHONY: build build: - npm run build \ No newline at end of file + [[ -d node_modules ]] || npm install + npm run build diff --git a/spin.toml b/spin.toml index 94871ed..ee42c2a 100644 --- a/spin.toml +++ b/spin.toml @@ -12,7 +12,7 @@ files = [{ source = "site/dist", destination = "/" }] route = "/..." [component.build] workdir = "site" -command = "npm run build" +command = "make" # Redirect / to /index.html [[component]] @@ -87,4 +87,5 @@ route = "/reset" [component.build] workdir = "reset" command = "make" -watch = ["src/**/*.rs", "Cargo.toml"] \ No newline at end of file +watch = ["src/**/*.rs", "Cargo.toml"] + diff --git a/tests/test-server.sh b/tests/test-server.sh index b8f8b1c..6def827 100755 --- a/tests/test-server.sh +++ b/tests/test-server.sh @@ -1,7 +1,7 @@ #!/bin/bash set -beuo pipefail -./serve.sh & +spin up --sqlite @highscore/migration.sql & timeout ${TIMEOUT:-10s} bash -c 'until curl -q 127.0.0.1:3000/index.html &>/dev/null; do sleep 1; done' @@ -9,4 +9,4 @@ trap 'kill -s SIGTERM $(jobs -p)' EXIT ./tally_test.sh && \ echo "Tally test success!" || \ - echo "Tally test failed." \ No newline at end of file + echo "Tally test failed."