58 lines
2.1 KiB
Bash
Executable File
58 lines
2.1 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# Build a publish directory: Linux binary (server) + _fresh for deployment. .env is not copied (publish dir is not recreated).
|
|
set -e
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
|
PUBLISH_DIR="$(cd "$SCRIPT_DIR/.." && pwd)/publish"
|
|
cd "$SCRIPT_DIR"
|
|
|
|
echo "Building Fresh app..."
|
|
deno task build
|
|
|
|
# So the compiled binary finds _fresh at runtime (not compile-time path)
|
|
echo "Patching server-entry to use FRESH_ROOT at runtime..."
|
|
sed -i 's|const root = join(import.meta.dirname, "..");|const root = Deno.env.get("FRESH_ROOT") ?? join(import.meta.dirname, "..");|' _fresh/server/server-entry.mjs
|
|
|
|
echo "Ensuring publish directory exists (parent of project)..."
|
|
mkdir -p "$PUBLISH_DIR"
|
|
|
|
echo "Compiling Linux binary (server)..."
|
|
deno compile -A --no-check --include ./_fresh/client --target x86_64-unknown-linux-gnu -o "$PUBLISH_DIR/server" bootstrap-serve.ts
|
|
|
|
echo "Copying _fresh into publish/..."
|
|
# Full _fresh (server + client assets) so the binary finds favicon, static files, etc.
|
|
cp -r _fresh "$PUBLISH_DIR/"
|
|
|
|
# Create systemd service file (install with: sudo cp ... /etc/systemd/system/ && sudo systemctl daemon-reload && sudo systemctl enable --now cyberhybridhub)
|
|
SERVICE_NAME="cyberhybridhub"
|
|
SERVICE_FILE="$PUBLISH_DIR/${SERVICE_NAME}.service"
|
|
cat > "$SERVICE_FILE" << EOF
|
|
[Unit]
|
|
Description=CyberHybridHub web app
|
|
After=network.target
|
|
|
|
[Service]
|
|
Type=simple
|
|
WorkingDirectory=$PUBLISH_DIR
|
|
Environment=PORT=80
|
|
ExecStart=$PUBLISH_DIR/server
|
|
Restart=on-failure
|
|
# Binding to port 80 typically requires root; run 'sudo systemctl start $SERVICE_NAME' when installing
|
|
|
|
[Install]
|
|
WantedBy=multi-user.target
|
|
EOF
|
|
chmod 644 "$SERVICE_FILE"
|
|
echo "Created $SERVICE_FILE"
|
|
|
|
echo "Installing and reinitializing systemd service..."
|
|
sudo cp "$SERVICE_FILE" "/etc/systemd/system/"
|
|
sudo systemctl daemon-reload
|
|
sudo systemctl stop "$SERVICE_NAME" 2>/dev/null || true
|
|
sudo systemctl enable --now "$SERVICE_NAME"
|
|
echo "Service $SERVICE_NAME is enabled and running (port 80)."
|
|
|
|
echo "Done. Contents of $PUBLISH_DIR:"
|
|
ls -la "$PUBLISH_DIR/"
|
|
ls -la "$PUBLISH_DIR/_fresh" 2>/dev/null || true
|