Files
pocketbase/flake.nix
2025-10-01 19:15:14 +02:00

110 lines
3.5 KiB
Nix
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
{
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";
};
};
}
);
}