From d2f8ece09ac355f698ef4f88417bc7a520d75a53 Mon Sep 17 00:00:00 2001 From: Bruno Bernardino Date: Sun, 16 Feb 2025 08:56:00 +0000 Subject: [PATCH] Update Deno Also update documentation for easier/quicker self-hosting according to suggestions on #8 --- .dockerignore | 9 +++++++++ .dvmrc | 2 +- Dockerfile | 4 +++- README.md | 16 ++++++++++++--- docker-compose.dev.yml | 20 ++++++++++++++++++ docker-compose.yml | 46 ++++++++++++++++++++++++++++++++++++++---- 6 files changed, 88 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 docker-compose.dev.yml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..3411d3d --- /dev/null +++ b/.dockerignore @@ -0,0 +1,9 @@ +.do +.github +.git +.gitignore +Caddyfile +docker-compose* +Dockerfile +Makefile +render.yaml diff --git a/.dvmrc b/.dvmrc index eca07e4..63a1a1c 100644 --- a/.dvmrc +++ b/.dvmrc @@ -1 +1 @@ -2.1.2 +2.1.9 diff --git a/Dockerfile b/Dockerfile index 4e42f11..1ea93bf 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,7 +1,9 @@ -FROM denoland/deno:alpine-2.1.2 +FROM denoland/deno:alpine-2.1.9 EXPOSE 8000 +RUN apk add bash make + WORKDIR /app # Prefer not to run as root. diff --git a/README.md b/README.md index f5e34ad..3d96938 100644 --- a/README.md +++ b/README.md @@ -16,9 +16,19 @@ It's not compatible with Budget Zen v2 ([end-to-end encrypted via Userbase](http [![Deploy to Render](https://render.com/images/deploy-to-render-button.svg)](https://render.com/deploy?repo=https://github.com/BrunoBernardino/budgetzen-web) -Or check the [Development section below](#development). +Or on your own machine: -> **NOTE:** You don't need to have emails (Brevo) and subscriptions (Stripe) setup to have the app work. Those are only used for allowing others to automatically manage their account. You can simply make any `user.status = 'active'` and `user.subscription.expires_at = new Date('2100-01-01')` to "never" expire, in the database, directly. +Download/copy [`docker-compose.yml`](/docker-compose.yml) and [`.env.sample`](/.env.sample) as `.env`. + +```sh +$ docker compose up -d # makes the app available at https://localhost +$ docker compose run --rm website bash -c "cd /app && make migrate-db" # initializes/updates the database (only needs to be executed the first time and on any updates) +``` + +> [!NOTE] +> You don't need to have emails (Brevo) and subscriptions (Stripe) setup to have the app work. Those are only used for allowing others to automatically manage their account. You can simply make any `user.status = 'active'` and `user.subscription.expires_at = new Date('2100-01-01')` to "never" expire, in the database, directly. + +Alternatively, check the [Development section below](#development). ## Framework-less @@ -39,7 +49,7 @@ Don't forget to set up your `.env` file based on `.env.sample`. ## Development ```sh -$ docker compose up # (optional) runs docker with postgres, locally +$ docker compose -f docker-compose.dev.yml up # (optional) runs docker with postgres, locally $ sudo caddy run # (optional) runs an https proxy for the deno app $ make migrate-db # runs any missing database migrations $ make start # runs the app diff --git a/docker-compose.dev.yml b/docker-compose.dev.yml new file mode 100644 index 0000000..5bf0e8d --- /dev/null +++ b/docker-compose.dev.yml @@ -0,0 +1,20 @@ +services: + postgresql: + image: postgres:15 + environment: + - POSTGRES_USER=postgres + - POSTGRES_PASSWORD=fake + - POSTGRES_DB=budgetzen + restart: on-failure + volumes: + - pgdata:/var/lib/postgresql/data + ports: + - 5432:5432 + ulimits: + memlock: + soft: -1 + hard: -1 + +volumes: + pgdata: + driver: local diff --git a/docker-compose.yml b/docker-compose.yml index 5bf0e8d..56a0d12 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,10 +2,9 @@ services: postgresql: image: postgres:15 environment: - - POSTGRES_USER=postgres - - POSTGRES_PASSWORD=fake - - POSTGRES_DB=budgetzen - restart: on-failure + - POSTGRES_USER=${POSTGRESQL_USER:-postgres} + - POSTGRES_PASSWORD=${POSTGRESQL_PASSWORD:-fake} + - POSTGRES_DB=${POSTGRESQL_DBNAME:-budgetzen} volumes: - pgdata:/var/lib/postgresql/data ports: @@ -14,7 +13,46 @@ services: memlock: soft: -1 hard: -1 + restart: unless-stopped + + website: + image: ghcr.io/brunobernardino/budgetzen-web:main + # If you want to build the image locally, uncomment the following lines and comment the image line above + # build: + # context: . + # dockerfile: Dockerfile + ports: + - ${PORT:-8000}:8000 + restart: unless-stopped + environment: + - BASE_URL=${BASE_URL:-https://localhost} + - POSTGRESQL_HOST=${POSTGRESQL_HOST:-postgresql} + - POSTGRESQL_USER=${POSTGRESQL_USER:-postgres} + - POSTGRESQL_PASSWORD=${POSTGRESQL_PASSWORD:-fake} + - POSTGRESQL_DBNAME=${POSTGRESQL_DBNAME:-budgetzen} + - POSTGRESQL_PORT=${POSTGRESQL_PORT:-5432} + - POSTGRESQL_CAFILE=${POSTGRESQL_CAFILE:-} + - BREVO_API_KEY=${BREVO_API_KEY:-} + - STRIPE_API_KEY=${STRIPE_API_KEY:-} + + # any non-empty value will be considered true + - IS_UNSAFE_SELF_HOSTED="true" + + depends_on: + - postgresql + - caddy + + caddy: + image: caddy:2-alpine + restart: unless-stopped + command: caddy reverse-proxy --from https://localhost:443 --to http://website:8000 + ports: + - 443:443 + volumes: + - caddy:/data volumes: pgdata: driver: local + caddy: + driver: local