krops-multi-deploy/example-build-local.nix
padreug ca5b78b561 Add build-local.nix for machine-specific web-app builds and update deployment instructions
Introduced a new example-build-local.nix file to facilitate machine-specific web-app builds, enhancing the deployment process. Updated the .gitignore to include build-local.nix, ensuring user-specific configurations remain untracked. Revised the DEPLOYMENT-GUIDE.md to reflect the addition of build-local.nix and provide clearer instructions for setting up configuration files, improving the onboarding experience for new users.
2025-10-12 08:34:58 +02:00

59 lines
1.8 KiB
Nix

let
pkgs = import <nixpkgs> {};
# Build script for a specific machine
buildForMachine = name: pkgs.writeShellScriptBin "build-${name}" ''
set -e
BUILD_DIR="./build/${name}"
echo "Building web-app for ${name}..."
# Clean and create build directory
rm -rf "$BUILD_DIR"
mkdir -p "$BUILD_DIR"
# Copy web-app source
cp -r ./web-app/* "$BUILD_DIR/"
# Copy machine-specific .env
echo "Copying machine-specific .env..."
cp ./machine-specific/${name}/env/.env "$BUILD_DIR/.env"
# Copy machine-specific images to public folder
echo "Copying machine-specific images to public..."
cp -r ./machine-specific/${name}/images/* "$BUILD_DIR/public/"
# Copy machine-specific logo to assets
echo "Copying machine-specific logo to assets..."
mkdir -p "$BUILD_DIR/src/assets"
cp ./machine-specific/${name}/images/logo.png "$BUILD_DIR/src/assets/logo.png"
# Build the web-app
echo "Running build..."
cd "$BUILD_DIR"
${pkgs.nodejs}/bin/npm run build
echo "Build complete for ${name}! Output in $BUILD_DIR/dist"
'';
in {
# Example machine build (copy this line for each machine)
# Replace "example-machine" with your machine name
example-machine = buildForMachine "example-machine";
# Add more machines here:
# machine1 = buildForMachine "machine1";
# machine2 = buildForMachine "machine2";
# Build all machines (update this list with your machines)
all = pkgs.writeShellScriptBin "build-all" ''
set -e
echo "Building for all machines..."
${(buildForMachine "example-machine")}/bin/build-example-machine
# Add your machines here:
# ${(buildForMachine "machine1")}/bin/build-machine1
# ${(buildForMachine "machine2")}/bin/build-machine2
echo "All builds complete!"
'';
}