chore(vm): bring up database and backend on the group VM #56
+234
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #14
What and why
Gets the database and backend actually running on the group VM
(
it2810-13.idi.ntnu.no), and protects the data import against the Kaggledatasets changing or disappearing later.
backend/scripts/import.ts: records the SHA-256 of both Kaggle zips andthe expected recipe/photo counts (17698 / 5653), and fails loudly instead
of silently importing different data if either ever changes.
deploy/apache/project2.conf: proxies/project2/graphqlto the backendon port 3001 (so the browser never needs that port, and there's no CORS),
and serves
data/images/with a one-year cache lifetime.deploy/systemd/t13-backend.service: runs the backend as a systemdservice, restarting on crash or reboot.
README.md: a full "Deployment" section, including every gotcha weactually hit standing this up (see below) — the goal is that the next
person (or a grader) can reproduce this without guessing.
The VM itself is now live with this setup: Postgres role +
t13database,Node via nvm, the repo cloned,
npm run importrun (17698 recipes, 5653with photo — matches the reference run exactly), the backend running as
t13-backend.service, and Apache proxying/serving as above.Decisions worth flagging to a grader, found while actually bringing the
VM up rather than guessed in advance:
apt install nodejspackage is built without TypeScripttype-stripping support (
amaro), which this backend's no-build-stepdesign depends on (
node_use_amaroisfalse). Switched to annvm-installed Node instead, as the issue's acceptance criteria already
allowed ("NodeSource or nvm").
git cloneon the VM needs an SSH key registered on git.ntnu.no. Arepo-scoped read-only deploy key needs admin on the repo, which wasn't
available at the time, so we used a personal key on an existing
collaborator's account instead, scoped to just that one clone via
core.sshCommand. Documented both options in the README; a proper deploykey is a straightforward follow-up once someone with admin is around.
t13database already existed, owned by a different teammate's role —Postgres 15+'s default (no implicit
CREATEonpublicfor non-owners)blocked the import until we granted it explicitly.
DATABASE_URLconnects over TCP, which needs aPostgres password the deploy role doesn't have. Switched to the local
unix socket (peer-authenticated) in the VM's
backend/.env.drwx------) blocks Apache from traversing intoit to reach
data/images/, giving403even though the files underneathare world-readable. Fixed with
chmod o+x ~(traverse only, not list).How to test
npm run lint && npm run format:check && npm run typecheck && npm test— all pass.
backend/scripts/import.tsand runnpm run import— it should throwchecksum mismatchbefore touching the database. Revert and it importsnormally. (Verified locally against the real downloaded datasets; also
verified the count guard the same way.)
curl http://it2810-13.idi.ntnu.no/project2/→200curl http://it2810-13.idi.ntnu.no/project2/recipes/6→200(SPAfallback, not Apache's 404)
curl -X POST http://it2810-13.idi.ntnu.no/project2/graphql -H 'Content-Type: application/json' -d '{"query":"{ recipes(limit:1){ totalCount } }"}'→
{"data":{"recipes":{"totalCount":17698}}}curl -I http://it2810-13.idi.ntnu.no/project2/images/6.webp→200,Cache-Control: max-age=31536000ssh it2810-13.idi.ntnu.no systemctl is-active t13-backend→active,is-enabled→enabledAI usage
Done together with Claude Code, in an interactive session rather than
unattended: Claude wrote the
import.tschecksum/count checks, the Apacheand systemd config files, and the README section, and drove the actual VM
setup over SSH (surveying the VM's existing state, running
npm ci/npm run import, installing nvm, diagnosing the three deployment gotchaslisted above). Every
sudo-gated step (package installs, the Postgresgrant, installing the systemd unit and Apache config, enabling Apache
modules) and the git.ntnu.no deploy-key sign-in were run by the human
directly on the VM/in the browser, not by Claude, and reported back for the
next step. The human reviewed each generated file and the final README
before this PR, and verified the live endpoints above itself.
Checklist
against the real datasets, see "How to test")
— n/a, no UI changes