From 3ed4a0f9fec6cd1f46e36bb2e45199811eb20f75 Mon Sep 17 00:00:00 2001 From: June Date: Mon, 17 Nov 2025 13:39:39 +1300 Subject: [PATCH] add pb stuff --- .gitignore | 2 + docker-compose.yml | 17 ++++ pb/.gitignore | 1 + pb/Dockerfile | 27 ++++++ pb/docker-entrypoint.sh | 17 ++++ .../1763339755_created_recipes.js | 89 +++++++++++++++++++ 6 files changed, 153 insertions(+) create mode 100644 .gitignore create mode 100644 docker-compose.yml create mode 100644 pb/.gitignore create mode 100644 pb/Dockerfile create mode 100644 pb/docker-entrypoint.sh create mode 100644 pb/pb_migrations/1763339755_created_recipes.js diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..93f1d2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +**/.DS_Store +**/.env \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..f3b509f --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + web: + build: web + env_file: .env + ports: + - "4321:4321" + + pb: + build: pb + env_file: .env + volumes: + - ./pb/pb_data:/pb/pb_data + - ./pb/pb_migrations:/pb/pb_migrations + - ./pb/pb_hooks:/pb/pb_hooks + ports: + - "8090:8090" + diff --git a/pb/.gitignore b/pb/.gitignore new file mode 100644 index 0000000..42ff718 --- /dev/null +++ b/pb/.gitignore @@ -0,0 +1 @@ +pb_data \ No newline at end of file diff --git a/pb/Dockerfile b/pb/Dockerfile new file mode 100644 index 0000000..2cc5dd6 --- /dev/null +++ b/pb/Dockerfile @@ -0,0 +1,27 @@ +FROM alpine:latest + +ARG PB_VERSION=0.29.2 + +WORKDIR /pb + +RUN apk add --no-cache \ + unzip \ + curl \ + ca-certificates \ + bash \ + sqlite + +# download and unzip PocketBase +ADD https://github.com/pocketbase/pocketbase/releases/download/v${PB_VERSION}/pocketbase_${PB_VERSION}_linux_amd64.zip /tmp/pb.zip +RUN unzip /tmp/pb.zip -d /pb/ + +# copy entrypoint +COPY docker-entrypoint.sh /usr/local/bin/ +RUN chmod +x /usr/local/bin/docker-entrypoint.sh + +VOLUME [ "/pb/pb_data", "/pb/pb_migrations", "/pb/pb_hooks" ] + +EXPOSE 8090 + +ENTRYPOINT ["docker-entrypoint.sh"] +CMD ["serve", "--http=0.0.0.0:8090"] diff --git a/pb/docker-entrypoint.sh b/pb/docker-entrypoint.sh new file mode 100644 index 0000000..fd02ea1 --- /dev/null +++ b/pb/docker-entrypoint.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash +set -e + +# if there are no users yet, create the superuser +# we check the sqlite file for any existing record in the users table +# /pb/pocketbase superuser create "${PB_ADMIN_EMAIL}" "${PB_ADMIN_PASSWORD}" +if [[ -f "${PB_DATA_DIR}/pb_data.db" ]] + sqlite3 "${PB_DATA_DIR}/data.db" "SELECT id FROM _superusers WHERE email='${PB_ADMIN_EMAIL}' LIMIT 1;" | grep -q .; then + + echo ">>> Creating PocketBase superuser: ${PB_ADMIN_EMAIL}" + /pb/pocketbase superuser create "${PB_ADMIN_EMAIL}" "${PB_ADMIN_PASSWORD}" +else + echo ">>> Superuser ${PB_ADMIN_EMAIL} already exists, skipping creation." +fi + +# exec the real pocketbase binary with any passed arguments +exec /pb/pocketbase "$@" diff --git a/pb/pb_migrations/1763339755_created_recipes.js b/pb/pb_migrations/1763339755_created_recipes.js new file mode 100644 index 0000000..4ce9521 --- /dev/null +++ b/pb/pb_migrations/1763339755_created_recipes.js @@ -0,0 +1,89 @@ +/// +migrate((app) => { + const collection = new Collection({ + "createRule": null, + "deleteRule": null, + "fields": [ + { + "autogeneratePattern": "[a-z0-9]{15}", + "hidden": false, + "id": "text3208210256", + "max": 15, + "min": 15, + "name": "id", + "pattern": "^[a-z0-9]+$", + "presentable": false, + "primaryKey": true, + "required": true, + "system": true, + "type": "text" + }, + { + "autogeneratePattern": "", + "hidden": false, + "id": "text1102439568", + "max": 0, + "min": 0, + "name": "cooklang", + "pattern": "", + "presentable": false, + "primaryKey": false, + "required": false, + "system": false, + "type": "text" + }, + { + "hidden": false, + "id": "file3760176746", + "maxSelect": 99, + "maxSize": 0, + "mimeTypes": [ + "image/png", + "image/jpeg", + "image/vnd.mozilla.apng" + ], + "name": "images", + "presentable": false, + "protected": false, + "required": false, + "system": false, + "thumbs": [], + "type": "file" + }, + { + "hidden": false, + "id": "autodate2990389176", + "name": "created", + "onCreate": true, + "onUpdate": false, + "presentable": false, + "system": false, + "type": "autodate" + }, + { + "hidden": false, + "id": "autodate3332085495", + "name": "updated", + "onCreate": true, + "onUpdate": true, + "presentable": false, + "system": false, + "type": "autodate" + } + ], + "id": "pbc_842702175", + "indexes": [], + "listRule": null, + "name": "recipes", + "system": false, + "type": "base", + "updateRule": null, + "viewRule": null + }); + + return app.save(collection); +}, (app) => { + const collection = app.findCollectionByNameOrId("pbc_842702175"); + + return app.delete(collection); +})