Add web-app with machine-specific builds
Implements per-machine customization for web-app deployment: - Shared web-app source code deployed to all machines - Machine-specific .env files and images - Build helper script to assemble and build on target machines 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
c6d226778d
commit
a84ebea315
5 changed files with 134 additions and 0 deletions
87
DEPLOYMENT-GUIDE.md
Normal file
87
DEPLOYMENT-GUIDE.md
Normal file
|
|
@ -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.
|
||||
29
build-helper.nix
Normal file
29
build-helper.nix
Normal file
|
|
@ -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"
|
||||
''
|
||||
10
web-app/index.html
Normal file
10
web-app/index.html
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
<!DOCTYPE html>
|
||||
<html>
|
||||
<head>
|
||||
<title>Web App</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Welcome to Web App</h1>
|
||||
<img src="public/logo.png" alt="Logo">
|
||||
</body>
|
||||
</html>
|
||||
8
web-app/package.json
Normal file
8
web-app/package.json
Normal file
|
|
@ -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/"
|
||||
}
|
||||
}
|
||||
0
web-app/public/.gitkeep
Normal file
0
web-app/public/.gitkeep
Normal file
Loading…
Add table
Add a link
Reference in a new issue