Adds flake, but just builds docker images directly

This commit is contained in:
Drew Haven 2025-05-31 15:12:44 -07:00
parent 8bee0973cd
commit b3d4e90e7f
8 changed files with 239 additions and 23 deletions

5
.gitignore vendored
View File

@ -5,4 +5,9 @@ dist-ssr
*.local
.direnv/
.vite/
# Local Pocketbase data
pb_data/
# Mprocs drops stuff here
mprocs.log

11
docker/app.dockerfile Normal file
View File

@ -0,0 +1,11 @@
FROM node:22-alpine3.20 AS builder
WORKDIR /app
COPY package.json package-lock.json ./
RUN npm install
COPY . .
RUN npm run build
FROM nginx:alpine AS runner
COPY --from=builder /app/dist /usr/share/nginx/html
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]

View File

@ -0,0 +1,23 @@
# See https://pocketbase.io/docs/going-to-production/#using-docker
FROM alpine:latest
ARG PB_VERSION=0.28.1
RUN apk add --no-cache \
unzip \
ca-certificates
# 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/
# uncomment to copy the local pb_migrations dir into the image
COPY ./pb_migrations /pb/pb_migrations
# uncomment to copy the local pb_hooks dir into the image
COPY ./pb_hooks /pb/pb_hooks
EXPOSE 8080
# start PocketBase
CMD ["/pb/pocketbase", "serve", "--http=0.0.0.0:8080"]

61
flake.lock Normal file
View File

@ -0,0 +1,61 @@
{
"nodes": {
"nixpkgs": {
"locked": {
"lastModified": 1748302896,
"narHash": "sha256-ixMT0a8mM091vSswlTORZj93WQAJsRNmEvqLL+qwTFM=",
"owner": "nixos",
"repo": "nixpkgs",
"rev": "7848cd8c982f7740edf76ddb3b43d234cb80fc4d",
"type": "github"
},
"original": {
"owner": "nixos",
"ref": "nixos-25.05",
"repo": "nixpkgs",
"type": "github"
}
},
"root": {
"inputs": {
"nixpkgs": "nixpkgs",
"utils": "utils"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
},
"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"
}
}
},
"root": "root",
"version": 7
}

134
flake.nix Normal file
View File

@ -0,0 +1,134 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-25.05";
utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
utils,
}:
utils.lib.eachDefaultSystem (
system:
let
# The path to the npm project
src = ./.;
# Read the package-lock.json as a Nix attrset
packageLock = builtins.fromJSON (builtins.readFile (src + "/package-lock.json"));
# Create an array of all (meaningful) dependencies
deps = builtins.attrValues (removeAttrs packageLock.packages [ "" ]);
# ++ builtins.attrValues (removeAttrs packageLock.dependencies [ "" ]);
# Turn each dependency into a fetchurl call
tarballs = map (
p:
pkgs.fetchurl {
url = p.resolved;
hash = p.integrity;
}
) deps;
# Write a file with the list of tarballs
tarballsFile = pkgs.writeTextFile {
name = "tarballs";
text = builtins.concatStringsSep "\n" tarballs;
};
pkgs = import nixpkgs { inherit system; };
in
{
devShell =
with pkgs;
mkShell {
buildInputs = [
nodejs_22 # Even versions are more stable
pocketbase
];
};
nodeModules = pkgs.stdenv.mkDerivation {
name = "lazy-dm-node-modules";
src = ./.;
buildInputs = [ pkgs.nodejs ];
buildPhase = ''
export HOME=$PWD/.home
export npm_config_cache=$PWD/.npm
mkdir -p $out
cd $out
cp -r $src/package.json $src/package-lock.json .
while read package
do
echo "caching $package"
npm cache add "$package"
done <${tarballsFile}
npm ci
'';
};
# Derivation for node_modules (npm ci)
# nodeModules = pkgs.stdenv.mkDerivation {
# name = "lazy-dm-node-modules";
# src = ./.;
# buildInputs = [ pkgs.nodejs_22 ];
# installPhase = ''
# mkdir -p $out
# cp package.json package-lock.json $out/
# cd $out
# npm ci --ignore-scripts
# '';
# # Only output node_modules
# dontBuild = true;
# dontConfigure = true;
# };
# Derivation for vite build
viteBuild = pkgs.stdenv.mkDerivation {
name = "lazy-dm-vite-build";
src = ./.;
buildInputs = [ pkgs.nodejs_22 ];
# Use node_modules from previous derivation
NODE_PATH = "${self.outputs.nodeModules}/node_modules";
installPhase = ''
cp -r $src $out/app
cd $out/app
cp ${self.outputs.nodeModules}/package.json .
cp -r ${self.outputs.nodeModules}/node_modules .
npm run build
mkdir -p $out/dist
cp -r dist/* $out/dist/
'';
dontBuild = true;
dontConfigure = true;
};
dockerImage = pkgs.dockerTools.buildLayeredImage {
name = "lazy-dm-app";
tag = "latest";
contents = [ pkgs.caddy ];
config = {
Cmd = [
"/bin/caddy"
"file-server"
"--root"
"/srv"
"--listen"
":8080"
];
ExposedPorts = {
"8080/tcp" = { };
};
WorkingDir = "/srv";
};
extraCommands = ''
mkdir -p $out/srv
cp -r ${self.outputs.viteBuild}/dist/* $out/srv/
'';
};
}
);
}

View File

@ -7,7 +7,10 @@
"start": "vite --port 3000",
"build": "vite build && tsc",
"serve": "vite preview",
"test": "vitest run"
"test": "vitest run",
"docker:build:app": "docker build -t docker.havenisms.com/lazy-dm/app -f docker/app.dockerfile .",
"docker:build:pocketbase": "docker build -t docker.havenisms.com/lazy-dm/pocketbase -f docker/pocketsbase.dockerfile .",
"docker:build": "npm run docker:build:app && npm run docker:build:pocketbase"
},
"dependencies": {
"@tailwindcss/vite": "^4.0.6",

View File

@ -1,21 +0,0 @@
{
pkgs ? import <nixpkgs> { },
}:
pkgs.mkShell {
packages = with pkgs; [
nodejs_22 # Even versions are more stable
pocketbase
# (vscode-with-extensions.override {
# vscodeExtensions = with pkgs.vscode-extensions; [
# asvetliakov.vscode-neovim
# enkia.tokyo-night
# github.copilot
# github.copilot-chat
# ];
# })
# Full VSCode seems to be required to get the Copilot extension to be able
# to authenticate, likely due to some setting not present in
# `vscode-with-extensions`.
# vscode
];
}

View File

@ -3,4 +3,4 @@
*
* This includes endpoints and other environment-specific settings.
*/
export const POCKETBASE_URL: string = "http://127.0.0.1:8090"; // Update as needed for deployment
export const POCKETBASE_URL: string = import.meta.env.VITE_POCKETBASE_URL || "http://127.0.0.1:8090"; // Update as needed for deployment