From 40b16e75b443d632f284f78f652f1940e7a5bfcb Mon Sep 17 00:00:00 2001 From: GarandPLG Date: Wed, 1 Oct 2025 19:15:14 +0200 Subject: [PATCH] init --- .dockerignore | 3 ++ .gitignore | 3 ++ Dockerfile | 32 +++++++++++++++ flake.lock | 61 ++++++++++++++++++++++++++++ flake.nix | 109 ++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 208 insertions(+) create mode 100644 .dockerignore create mode 100644 .gitignore create mode 100644 Dockerfile create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..1c254d7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +.envrc +.env +*.env diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..1c254d7 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.envrc +.env +*.env diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..846a021 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,32 @@ +FROM alpine:latest + +ARG PB_VERSION=0.30.0 + +LABEL maintainer="garandplg@garandplg.com" +LABEL version="${PB_VERSION}" +LABEL description="Pocketbase image" + +RUN apk add --no-cache \ + unzip \ + ca-certificates + +WORKDIR /pb + +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 ./ \ + && rm -rf \ + ./CHANGELOG.md \ + ./LICENSE.md \ + /tmp/pb.zip \ + /build \ + && mkdir -p pb_data pb_public pb_migrations pb_hooks \ + && chmod +x ./pocketbase \ + && adduser -D pocketbase \ + && chown -R pocketbase:pocketbase /pb + +USER pocketbase + +EXPOSE 8090 + +CMD ["./pocketbase", "serve", "--http", "0.0.0.0:8090", "--dir", "./pb_data", "--migrationsDir", "./pb_migrations", "--publicDir", "./pb_public", "--hooksDir", "./pb_hooks"] diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..5850e1a --- /dev/null +++ b/flake.lock @@ -0,0 +1,61 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1759036355, + "narHash": "sha256-0m27AKv6ka+q270dw48KflE0LwQYrO7Fm4/2//KCVWg=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9f00bd893984bc8ce46c895c3bf7cac95331127", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..0bf7d9f --- /dev/null +++ b/flake.nix @@ -0,0 +1,109 @@ +{ + description = "PocketBase project with Docker"; + + inputs = { + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = + { + self, + nixpkgs, + flake-utils, + }: + flake-utils.lib.eachDefaultSystem ( + system: + let + pkgs = nixpkgs.legacyPackages.${system}; + + dockerfileContent = builtins.readFile ./Dockerfile; + versionMatch = builtins.match ".*ARG PB_VERSION=([0-9]+\.[0-9]+\.[0-9]+).*" dockerfileContent; + version = if versionMatch != null then builtins.head versionMatch else "latest"; + + registry = "gitea.garandplg.com"; + imageName = "garandplg/pocketbase"; + + pushScript = pkgs.writeShellScriptBin "push-images" '' + set -e + + if [ -z "$DOCKER_USERNAME" ] || [ -z "$DOCKER_PASSWORD" ]; then + echo "❌ Set DOCKER_USERNAME and DOCKER_PASSWORD environment variables" + exit 1 + fi + + echo "🔐 Logging in to ${registry}..." + echo "$DOCKER_PASSWORD" | docker login ${registry} -u "$DOCKER_USERNAME" --password-stdin + + echo "🔨 Building Docker images with PocketBase version ${version}..." + docker build -t ${registry}/${imageName}:${version} . + docker tag ${registry}/${imageName}:${version} ${registry}/${imageName}:latest + + echo "📤 Pushing ${registry}/${imageName}:${version}..." + docker push ${registry}/${imageName}:${version} + + echo "📤 Pushing ${registry}/${imageName}:latest..." + docker push ${registry}/${imageName}:latest + + echo "✅ Successfully pushed both images!" + echo " - ${registry}/${imageName}:${version}" + echo " - ${registry}/${imageName}:latest" + ''; + + buildScript = pkgs.writeShellScriptBin "build-image" '' + set -e + + echo "🔨 Building PocketBase Docker image (version ${version})..." + docker build -t ${registry}/${imageName}:${version} . + docker tag ${registry}/${imageName}:${version} ${registry}/${imageName}:latest + + echo "✅ Successfully built image!" + echo " - ${registry}/${imageName}:${version}" + echo " - ${registry}/${imageName}:latest" + + echo "🚀 To run the container:" + echo " docker run -p 8090:8090 ${registry}/${imageName}:latest" + ''; + + in + { + devShells.default = pkgs.mkShell { + buildInputs = with pkgs; [ + docker + direnv + pushScript + buildScript + ]; + + shellHook = '' + echo "🗃️ PocketBase + Docker environment" + echo "📦 Detected PocketBase version: ${version}" + echo "" + echo "Commands:" + echo " build-image - Build Docker image locally" + echo " push-images - Build and push to registry" + echo "" + echo "Environment variables needed for push:" + echo " DOCKER_USERNAME - Your registry username" + echo " DOCKER_PASSWORD - Your registry password/token" + ''; + }; + + packages = { + push-images = pushScript; + build-image = buildScript; + }; + + apps = { + push = { + type = "app"; + program = "${pushScript}/bin/push-images"; + }; + build = { + type = "app"; + program = "${buildScript}/bin/build-image"; + }; + }; + } + ); +}