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.
This commit is contained in:
parent
2229717860
commit
ca5b78b561
3 changed files with 88 additions and 6 deletions
4
.gitignore
vendored
4
.gitignore
vendored
|
|
@ -11,6 +11,10 @@ lnbits-extensions
|
|||
# Copy example-krops.nix to krops.nix and customize
|
||||
krops.nix
|
||||
|
||||
# User-specific build configuration
|
||||
# Copy example-build-local.nix to build-local.nix and customize
|
||||
build-local.nix
|
||||
|
||||
# Machine-specific configurations (user creates these)
|
||||
# Keep example-machine as a template
|
||||
config/machines/*
|
||||
|
|
|
|||
|
|
@ -11,11 +11,12 @@ This setup builds the web-app **locally** with machine-specific configuration, t
|
|||
|
||||
When you first clone this repository, you need to set up your local configuration:
|
||||
|
||||
### 1. Create your krops.nix
|
||||
### 1. Create your configuration files
|
||||
|
||||
```bash
|
||||
# Copy the example template
|
||||
# Copy the example templates
|
||||
cp example-krops.nix krops.nix
|
||||
cp example-build-local.nix build-local.nix
|
||||
```
|
||||
|
||||
### 2. Create your first machine configuration
|
||||
|
|
@ -29,20 +30,38 @@ cp -r config/machines/example-machine config/machines/my-machine
|
|||
# - Add your hardware-configuration.nix (from nixos-generate-config)
|
||||
```
|
||||
|
||||
### 3. Update krops.nix
|
||||
### 3. Create machine-specific web-app assets (if deploying web-app)
|
||||
|
||||
Edit `krops.nix` and:
|
||||
```bash
|
||||
mkdir -p machine-specific/my-machine/env
|
||||
mkdir -p machine-specific/my-machine/images
|
||||
|
||||
# Add your .env file and images
|
||||
# See machine-specific/example-machine/ for reference
|
||||
```
|
||||
|
||||
### 4. Update krops.nix and build-local.nix
|
||||
|
||||
**In `krops.nix`:**
|
||||
- Replace `example-machine` with your machine name
|
||||
- Update the SSH target (`root@your-host`)
|
||||
- Add to the `inherit` list and `all` script
|
||||
|
||||
### 4. Deploy!
|
||||
**In `build-local.nix`:**
|
||||
- Replace `example-machine` with your machine name
|
||||
- Add to the `all` build script
|
||||
|
||||
### 5. Build and deploy!
|
||||
|
||||
```bash
|
||||
# Build web-app locally (if using web-app)
|
||||
nix-build ./build-local.nix -A my-machine && ./result/bin/build-my-machine
|
||||
|
||||
# Deploy to target machine
|
||||
nix-build ./krops.nix -A my-machine && ./result
|
||||
```
|
||||
|
||||
**Note:** Your `krops.nix` and machine configs in `config/machines/*` are gitignored. You can safely pull updates without overwriting your local configuration.
|
||||
**Note:** Your `krops.nix`, `build-local.nix`, and machine configs in `config/machines/*` are gitignored. You can safely pull updates without overwriting your local configuration.
|
||||
|
||||
## Structure
|
||||
|
||||
|
|
|
|||
59
example-build-local.nix
Normal file
59
example-build-local.nix
Normal file
|
|
@ -0,0 +1,59 @@
|
|||
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!"
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue