Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ node_modules
**/.nitro
.env
**/.env
**/src/generated
**/src/generated/*
!packages/db/src/generated/pothos-types.ts
test-results
**/test-results
.DS_Store
Expand Down
43 changes: 41 additions & 2 deletions .github/workflows/deploy-azure.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@
# - The identity's role grants (Contributor on the resource group,
# AcrPush on the registry) are managed by the Terraform config, not
# by hand.
# - The runner needs the Docker CLI (preinstalled on ubuntu-latest).
# - The self-hosted runner needs Docker Engine and the buildx plugin
# (`docker buildx version` must work). The workflow checks this before
# logging in to the registry. Use Docker 28.x: 29.x has an always-on
# BuildKit session bug that can hang builds with "only one connection
# allowed".
#
# Rollback: `az containerapp revision list` + `az containerapp revision
# activate` for the previous revision, or re-run this workflow on an old
Expand Down Expand Up @@ -54,6 +58,22 @@ jobs:
- name: Check out source
uses: actions/checkout@v4

- name: Check Docker prerequisites
run: |
set -euo pipefail
command -v docker > /dev/null || {
echo "::error::docker is not installed on the runner"
exit 1
}
docker info > /dev/null || {
echo "::error::the Docker daemon is not reachable by the runner user"
exit 1
}
docker buildx version || {
echo "::error::the Docker buildx plugin is not installed on the runner"
exit 1
}
- name: Log in to Azure
uses: azure/login@v2
with:
Expand Down Expand Up @@ -82,7 +102,17 @@ jobs:
echo "GRAPHQL_PROXY_TARGET=http://$BACKEND_FQDN" >> "$GITHUB_ENV"
- name: Log in to the container registry
run: az acr login --name "$ACR_NAME"
run: |
set -euo pipefail
# `az acr login` shells out to the Docker CLI and fails with
# DOCKER_COMMAND_ERROR if it cannot find it. Ask ACR for a token
# instead and hand it to Docker directly; buildx still needs the
# registry login for `--push`.
ACR_TOKEN="$(az acr login --name "$ACR_NAME" --expose-token \
--query accessToken -o tsv)"
printf '%s' "$ACR_TOKEN" | docker login "$ACR_SERVER" \
--username 00000000-0000-0000-0000-000000000000 \
--password-stdin
- name: Build and push backend image
run: |
Expand Down Expand Up @@ -140,3 +170,12 @@ jobs:
run: |
az containerapp update -n "$FRONTEND_APP" -g "$RESOURCE_GROUP" \
--image "$ACR_SERVER/gspotter-frontend:$GITHUB_SHA"
# The runner shares a small disk with the production VM. Images have
# already been pushed to ACR, so drop the local copies and keep only a
# small build cache for the next deploy.
- name: Clean up Docker build cache
if: always()
run: |
docker image prune -af || true
docker builder prune -f --max-used-space 1GB || true
4 changes: 4 additions & 0 deletions .github/workflows/deploy-to-vm.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ jobs:
User=$(id -un)
Group=$(id -gn)
WorkingDirectory=$DEPLOY_ROOT/apps/backend
# pnpm start does not load .env (the Azure image gets its config
# from the Container App environment), so systemd passes it in.
EnvironmentFile=$DEPLOY_ROOT/apps/backend/.env
Environment=PORT=$BACKEND_PORT
ExecStart=/usr/bin/env pnpm start
Restart=always
RestartSec=2
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ dist-ssr
.vinxi
__unconfig*
todos.json
**/src/generated/
**/src/generated/*
!packages/db/src/generated/pothos-types.ts
test-results/

# Terraform
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,8 @@ pnpm test:backend

The deployment of both the backend and frontend is automated using the github action found in `./.github/workflows/deploy-to-vm.yaml`

Both workflows run on the self-hosted runner on the VM. The Azure workflow builds the images with Docker/buildx on that runner (ACR Tasks are not available on the student subscription), so the runner user must be able to access the Docker socket. Docker 28.x is required because 29.x has a BuildKit session bug that can hang builds. The backend systemd unit loads `apps/backend/.env`, because the production `start` script does not read it.

Deploys apply the Prisma migrations in `./packages/db/prisma/migrations` with `prisma migrate deploy` (via `pnpm db:deploy`). Migrations are the single source of truth for the database, so never change the deployed schema with `pnpm db:push`: it does not run the migration SQL (functions, triggers, ...) and skips the migration history, which leaves the deploy unable to apply those migrations later.

A database that was created with `pnpm db:push` before migrations were adopted has no `_prisma_migrations` table. Run `pnpm db:baseline` once against it, then `pnpm db:deploy`; after that the deploy workflow keeps it up to date.
Expand Down
8 changes: 5 additions & 3 deletions apps/backend/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,14 @@ RUN pnpm install --frozen-lockfile --filter @t09-project-2/backend...

# prisma.config.ts calls env('DATABASE_URL') even during `prisma generate`,
# so a placeholder value is required for the client generation step.
# .dockerignore excludes **/src/generated, so the generated client only
# exists inside this stage.
# Only the client generator runs here: the Pothos generator's child process
# hangs under Docker after writing its output. Its generated file is checked
# in (packages/db/src/generated/pothos-types.ts); regenerate it with
# `pnpm db:generate` and commit it whenever the Prisma schema changes.
COPY packages/db packages/db
COPY apps/backend apps/backend
RUN DATABASE_URL="postgresql://placeholder:placeholder@localhost:5432/placeholder" \
pnpm --filter @t09-project-2/db exec prisma generate
pnpm --filter @t09-project-2/db exec prisma generate --generator client

# --- runner: production deps only --------------------------------------------
# Ships only what the runtime needs: production dependencies, tsx (the start
Expand Down
3 changes: 3 additions & 0 deletions packages/db/prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ generator client {
output = "../src/generated/prisma"
}

// The generated file is checked in because the Pothos generator hangs inside
// the Docker image build. Run `pnpm db:generate` and commit the result after
// changing this schema.
generator pothos {
provider = "prisma-pothos-types"
clientOutput = "./prisma"
Expand Down
146 changes: 146 additions & 0 deletions packages/db/src/generated/pothos-types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
/* eslint-disable */
import type { Prisma, Venue, OpeningHours, OpeningHoursNote, City, PriceSighting, Review } from "./prisma/client.js";
import type { PothosPrismaDatamodel } from "@pothos/plugin-prisma";
export default interface PrismaTypes {
Venue: {
Name: "Venue";
Shape: Venue;
Include: Prisma.VenueInclude;
Select: Prisma.VenueSelect;
OrderBy: Prisma.VenueOrderByWithRelationInput;
WhereUnique: Prisma.VenueWhereUniqueInput;
Where: Prisma.VenueWhereInput;
Create: {};
Update: {};
RelationName: "openingHours" | "openingHoursNotes" | "city" | "pricesSighted" | "reviews";
ListRelations: "openingHours" | "openingHoursNotes" | "pricesSighted" | "reviews";
Relations: {
openingHours: {
Shape: OpeningHours[];
Name: "OpeningHours";
Nullable: false;
};
openingHoursNotes: {
Shape: OpeningHoursNote[];
Name: "OpeningHoursNote";
Nullable: false;
};
city: {
Shape: City;
Name: "City";
Nullable: false;
};
pricesSighted: {
Shape: PriceSighting[];
Name: "PriceSighting";
Nullable: false;
};
reviews: {
Shape: Review[];
Name: "Review";
Nullable: false;
};
};
};
OpeningHours: {
Name: "OpeningHours";
Shape: OpeningHours;
Include: Prisma.OpeningHoursInclude;
Select: Prisma.OpeningHoursSelect;
OrderBy: Prisma.OpeningHoursOrderByWithRelationInput;
WhereUnique: Prisma.OpeningHoursWhereUniqueInput;
Where: Prisma.OpeningHoursWhereInput;
Create: {};
Update: {};
RelationName: "venue";
ListRelations: never;
Relations: {
venue: {
Shape: Venue;
Name: "Venue";
Nullable: false;
};
};
};
OpeningHoursNote: {
Name: "OpeningHoursNote";
Shape: OpeningHoursNote;
Include: Prisma.OpeningHoursNoteInclude;
Select: Prisma.OpeningHoursNoteSelect;
OrderBy: Prisma.OpeningHoursNoteOrderByWithRelationInput;
WhereUnique: Prisma.OpeningHoursNoteWhereUniqueInput;
Where: Prisma.OpeningHoursNoteWhereInput;
Create: {};
Update: {};
RelationName: "venue";
ListRelations: never;
Relations: {
venue: {
Shape: Venue;
Name: "Venue";
Nullable: false;
};
};
};
City: {
Name: "City";
Shape: City;
Include: Prisma.CityInclude;
Select: Prisma.CitySelect;
OrderBy: Prisma.CityOrderByWithRelationInput;
WhereUnique: Prisma.CityWhereUniqueInput;
Where: Prisma.CityWhereInput;
Create: {};
Update: {};
RelationName: "venues";
ListRelations: "venues";
Relations: {
venues: {
Shape: Venue[];
Name: "Venue";
Nullable: false;
};
};
};
PriceSighting: {
Name: "PriceSighting";
Shape: PriceSighting;
Include: Prisma.PriceSightingInclude;
Select: Prisma.PriceSightingSelect;
OrderBy: Prisma.PriceSightingOrderByWithRelationInput;
WhereUnique: Prisma.PriceSightingWhereUniqueInput;
Where: Prisma.PriceSightingWhereInput;
Create: {};
Update: {};
RelationName: "venue";
ListRelations: never;
Relations: {
venue: {
Shape: Venue;
Name: "Venue";
Nullable: false;
};
};
};
Review: {
Name: "Review";
Shape: Review;
Include: Prisma.ReviewInclude;
Select: Prisma.ReviewSelect;
OrderBy: Prisma.ReviewOrderByWithRelationInput;
WhereUnique: Prisma.ReviewWhereUniqueInput;
Where: Prisma.ReviewWhereInput;
Create: {};
Update: {};
RelationName: "venue";
ListRelations: never;
Relations: {
venue: {
Shape: Venue;
Name: "Venue";
Nullable: false;
};
};
};
}
export function getDatamodel(): PothosPrismaDatamodel { return JSON.parse("{\"datamodel\":{\"models\":{\"Venue\":{\"fields\":[{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"id\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":true,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"name\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"address\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Float\",\"kind\":\"scalar\",\"name\":\"lat\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Float\",\"kind\":\"scalar\",\"name\":\"lon\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"OpeningHours\",\"kind\":\"object\",\"name\":\"openingHours\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"OpeningHoursToVenue\",\"relationFromFields\":[],\"isUpdatedAt\":false},{\"type\":\"OpeningHoursNote\",\"kind\":\"object\",\"name\":\"openingHoursNotes\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"OpeningHoursNoteToVenue\",\"relationFromFields\":[],\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"cityId\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"City\",\"kind\":\"object\",\"name\":\"city\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"CityToVenue\",\"relationFromFields\":[\"cityId\"],\"isUpdatedAt\":false},{\"type\":\"PriceSighting\",\"kind\":\"object\",\"name\":\"pricesSighted\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"PriceSightingToVenue\",\"relationFromFields\":[],\"isUpdatedAt\":false},{\"type\":\"Review\",\"kind\":\"object\",\"name\":\"reviews\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"ReviewToVenue\",\"relationFromFields\":[],\"isUpdatedAt\":false}],\"primaryKey\":null,\"uniqueIndexes\":[]},\"OpeningHours\":{\"fields\":[{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"id\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":true,\"isUpdatedAt\":false},{\"type\":\"Day\",\"kind\":\"enum\",\"name\":\"days\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"DateTime\",\"kind\":\"scalar\",\"name\":\"opening\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"DateTime\",\"kind\":\"scalar\",\"name\":\"closing\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"venueId\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Venue\",\"kind\":\"object\",\"name\":\"venue\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"OpeningHoursToVenue\",\"relationFromFields\":[\"venueId\"],\"isUpdatedAt\":false}],\"primaryKey\":null,\"uniqueIndexes\":[]},\"OpeningHoursNote\":{\"fields\":[{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"id\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":true,\"isUpdatedAt\":false},{\"type\":\"Day\",\"kind\":\"enum\",\"name\":\"days\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"note\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"venueId\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Venue\",\"kind\":\"object\",\"name\":\"venue\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"OpeningHoursNoteToVenue\",\"relationFromFields\":[\"venueId\"],\"isUpdatedAt\":false}],\"primaryKey\":null,\"uniqueIndexes\":[]},\"City\":{\"fields\":[{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"id\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":true,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"name\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Float\",\"kind\":\"scalar\",\"name\":\"centreLon\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Float\",\"kind\":\"scalar\",\"name\":\"centreLat\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Venue\",\"kind\":\"object\",\"name\":\"venues\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"CityToVenue\",\"relationFromFields\":[],\"isUpdatedAt\":false}],\"primaryKey\":null,\"uniqueIndexes\":[]},\"PriceSighting\":{\"fields\":[{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"id\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":true,\"isUpdatedAt\":false},{\"type\":\"Float\",\"kind\":\"scalar\",\"name\":\"price\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"GlassSize\",\"kind\":\"enum\",\"name\":\"size\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Limitations\",\"kind\":\"enum\",\"name\":\"limitation\",\"isRequired\":true,\"isList\":true,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"DateTime\",\"kind\":\"scalar\",\"name\":\"timeStart\",\"isRequired\":false,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"DateTime\",\"kind\":\"scalar\",\"name\":\"timeEnd\",\"isRequired\":false,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Float\",\"kind\":\"scalar\",\"name\":\"sizeMl\",\"isRequired\":false,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"DateTime\",\"kind\":\"scalar\",\"name\":\"timeSighted\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"venueId\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Venue\",\"kind\":\"object\",\"name\":\"venue\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"PriceSightingToVenue\",\"relationFromFields\":[\"venueId\"],\"isUpdatedAt\":false}],\"primaryKey\":null,\"uniqueIndexes\":[]},\"Review\":{\"fields\":[{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"id\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":true,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"username\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"body\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Int\",\"kind\":\"scalar\",\"name\":\"rating\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"DateTime\",\"kind\":\"scalar\",\"name\":\"timeCreated\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":true,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"String\",\"kind\":\"scalar\",\"name\":\"venueId\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"isUpdatedAt\":false},{\"type\":\"Venue\",\"kind\":\"object\",\"name\":\"venue\",\"isRequired\":true,\"isList\":false,\"hasDefaultValue\":false,\"isUnique\":false,\"isId\":false,\"relationName\":\"ReviewToVenue\",\"relationFromFields\":[\"venueId\"],\"isUpdatedAt\":false}],\"primaryKey\":null,\"uniqueIndexes\":[]}}}}"); }
Loading