From 94fffc569584039b91184432584b6dd27264d07e Mon Sep 17 00:00:00 2001 From: Nandor Magyar Date: Sun, 31 Aug 2025 15:55:44 +0200 Subject: [PATCH] add healthz, docker fixes, minor readme tweaks --- .env.example | 2 +- Dockerfile | 4 ++++ Makefile | 10 +++++----- README.md | 19 ++++++++++++++----- docker-compose.yml | 3 +-- src/routes/healthz/+server.ts | 16 ++++++++++++++++ 6 files changed, 41 insertions(+), 13 deletions(-) create mode 100644 src/routes/healthz/+server.ts diff --git a/.env.example b/.env.example index c6d7b37..dd31228 100644 --- a/.env.example +++ b/.env.example @@ -5,7 +5,7 @@ POSTGRES_PASSWORD=cactoide_password POSTGRES_PORT=5432 # localhost -DATABASE_URL="postgres://cactoide:cactoide_password@localhost:5432/cactoied_database" +DATABASE_URL="postgres://cactoide:cactoide_password@localhost:5432/cactoide_database" # docker # DATABASE_URL="postgres://cactoide:cactoide_password@postgres:5432/cactoied_database" diff --git a/Dockerfile b/Dockerfile index 1f78765..a44214f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,8 @@ EXPOSE 3000 ENV PORT 3000 ENV HOSTNAME "0.0.0.0" + +HEALTHCHECK --interval=30s --timeout=10s --start-period=10s --retries=3 \ + CMD wget --no-verbose --tries=1 --spider http://127.0.0.1:3000/healthz || exit 1 + CMD [ "node", "build" ] diff --git a/Makefile b/Makefile index 6968741..b811830 100644 --- a/Makefile +++ b/Makefile @@ -19,26 +19,26 @@ help: # Build the Docker images build: @echo "Building Docker images..." - docker-compose build + docker compose build # Start all services up: @echo "Starting all services..." - docker-compose up -d + docker compose up -d # Start only the database db-only: @echo "Starting only the database..." - docker-compose up -d postgres + docker compose up -d postgres # Show logs from all services logs: @echo "Showing logs from all services..." - docker-compose logs -f + docker compose logs -f # Clean up everything (containers, images, volumes) clean: @echo "Cleaning up all Docker resources..." - docker-compose down -v --rmi all + docker compose down -v --rmi all diff --git a/README.md b/README.md index bb4fa41..c465632 100644 --- a/README.md +++ b/README.md @@ -27,10 +27,23 @@ A mobile-first event RSVP platform that lets you create events, share unique URL ### Quick Start +Requirements: git, docker, docker-compose +Uses the [`docker-compose.yml`](docker-compose.yml) file to setup the application with the database. You can define all ENV variables in the [`.env`](.env.example) file from the `.env.example`. + +```bash +git clone https://github.com/polaroi8d/cactoide/ +cd cactoide +cp env.example .env +docker compose up -d +``` + +### Development + +Requirements: git, docker, docker-compose, node at least suggested 20.19.0 + ```bash git clone https://github.com/polaroi8d/cactoide/ cd cactoide -npm install cp env.example .env make db-only npm run dev -- --open @@ -38,10 +51,6 @@ npm run dev -- --open Your app will be available at `http://localhost:5173`. You can use the Makefile commands to run the application or the database, eg.: `make db-only`. -### Self-Host - -Use the [`docker-compose.yml`](docker-compose.yml) file to setup the application with the database. You can define all ENV variables in the [`.env`](.env.example) file from the `.env.example`. - ### License This project is licensed under the MIT License - see the [LICENSE](./LICENSE) file for details. diff --git a/docker-compose.yml b/docker-compose.yml index fdc7828..7f3ed8d 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,5 +1,3 @@ -version: '3.8' - services: # Database postgres: @@ -29,6 +27,7 @@ services: # Application app: image: ghcr.io/polaroi8d/cactoide/cactoide:${APP_VERSION:-latest} + build: . container_name: cactoide-app ports: - '${PORT:-5111}:3000' diff --git a/src/routes/healthz/+server.ts b/src/routes/healthz/+server.ts new file mode 100644 index 0000000..4e8ccce --- /dev/null +++ b/src/routes/healthz/+server.ts @@ -0,0 +1,16 @@ +// src/routes/healthz/+server.ts +import { json } from '@sveltejs/kit'; +import { drizzleQuery } from '$lib/database/db'; +import { sql } from 'drizzle-orm'; + +export async function GET() { + try { + await drizzleQuery.execute(sql`select 1`); + return json({ ok: true }, { headers: { 'cache-control': 'no-store' } }); + } catch (err) { + return json( + { ok: false, error: (err as Error)?.message ?? 'DB unavailable' }, + { status: 503, headers: { 'cache-control': 'no-store' } } + ); + } +}