diff --git a/DEPLOYMENT-GUIDE.md b/DEPLOYMENT-GUIDE.md new file mode 100644 index 0000000..ac91b91 --- /dev/null +++ b/DEPLOYMENT-GUIDE.md @@ -0,0 +1,87 @@ +# Web-App Deployment Guide + +## Overview + +This setup allows each machine to build the web-app with its own specific configuration: +- Machine-specific `.env` files +- Machine-specific images in the `public` folder + +## Structure + +``` +. +├── web-app/ # Shared web-app source code +│ ├── package.json +│ ├── index.html +│ └── public/ # Images will be copied here during build +├── machine-specific/ +│ ├── machine1/ +│ │ ├── env/.env # Machine1's environment file +│ │ └── images/ # Machine1's images +│ │ ├── logo.png +│ │ └── banner.jpg +│ └── machine2/ +│ ├── env/.env # Machine2's environment file +│ └── images/ # Machine2's images +│ ├── logo.png +│ └── banner.jpg +└── build-helper.nix # Build script available on target machines +``` + +## How It Works + +### 1. Krops Deployment (krops.nix) + +When you deploy with krops, it copies to each target machine: +- `web-app` → `/var/src/web-app` (shared source code) +- `machine-specific/{name}/env/.env` → `/var/src/web-app-env` (machine-specific .env) +- `machine-specific/{name}/images/` → `/var/src/web-app-images/` (machine-specific images) + +### 2. Building on Target Machine + +After deployment, SSH into the target machine and run: + +```bash +build-web-app +``` + +This script: +1. Copies the machine-specific `.env` file to the web-app directory +2. Copies the machine-specific images to `web-app/public/` +3. Runs `npm run build` to build the web-app + +The build output will be in `/var/src/web-app/dist/` + +## Usage + +### Deploy to a single machine: +```bash +nix-build ./krops.nix -A machine1 && ./result +``` + +### Deploy to all machines: +```bash +nix-build ./krops.nix -A all && ./result +``` + +### Build the web-app on target machine: +```bash +ssh root@machine1.example.com +build-web-app +``` + +## Customization + +### Add a new machine: +1. Create directories: `machine-specific/machine3/env/` and `machine-specific/machine3/images/` +2. Add `.env` file and images for machine3 +3. Create `config/machine3/configuration.nix` +4. Add machine3 target in `krops.nix` + +### Update environment variables: +Edit the appropriate `.env` file in `machine-specific/{machine-name}/env/.env` + +### Update images: +Replace files in `machine-specific/{machine-name}/images/` + +After making changes, redeploy with krops. \ No newline at end of file diff --git a/build-helper.nix b/build-helper.nix new file mode 100644 index 0000000..b94f7e3 --- /dev/null +++ b/build-helper.nix @@ -0,0 +1,29 @@ +# Helper script for building the web-app on target machines +# This can be imported into the machine's configuration.nix + +{ pkgs }: + +pkgs.writeShellScriptBin "build-web-app" '' + set -e + + # Web-app sources are deployed to /var/src by krops + WEB_APP_DIR="/var/src/web-app" + ENV_FILE="/var/src/web-app-env" + IMAGES_DIR="/var/src/web-app-images" + + cd "$WEB_APP_DIR" + + # Copy machine-specific .env file + echo "Copying machine-specific .env file..." + cp "$ENV_FILE" .env + + # Copy machine-specific images to public folder + echo "Copying machine-specific images..." + cp -r "$IMAGES_DIR"/* public/ + + # Build the web-app + echo "Building web-app..." + ${pkgs.nodejs}/bin/npm run build + + echo "Build complete! Output in $WEB_APP_DIR/dist" +'' \ No newline at end of file diff --git a/web-app/index.html b/web-app/index.html new file mode 100644 index 0000000..2bfc772 --- /dev/null +++ b/web-app/index.html @@ -0,0 +1,10 @@ + + + + Web App + + +

Welcome to Web App

+ Logo + + \ No newline at end of file diff --git a/web-app/package.json b/web-app/package.json new file mode 100644 index 0000000..20a2855 --- /dev/null +++ b/web-app/package.json @@ -0,0 +1,8 @@ +{ + "name": "web-app", + "version": "1.0.0", + "description": "Example web application", + "scripts": { + "build": "echo 'Building web-app...' && mkdir -p dist && cp -r public dist/ && cp .env dist/" + } +} \ No newline at end of file diff --git a/web-app/public/.gitkeep b/web-app/public/.gitkeep new file mode 100644 index 0000000..e69de29