7d5f0920b7
Dispatch now validates the command format and routes to a single deploy.sh that handles any app. This fixes first-deploy failures for new apps (dispatch no longer needs a static case list) and simplifies new-app.sh (no deploy script or dispatch update needed). Also adds input validation to new-app.sh, set -euo pipefail to deploy scripts, and dnf module reset before nodejs install.
73 lines
1.7 KiB
Bash
Executable File
73 lines
1.7 KiB
Bash
Executable File
#!/bin/bash
|
|
set -euo pipefail
|
|
|
|
if [ -z "${1:-}" ]; then
|
|
echo "Usage: ./scripts/new-app.sh <app-name>"
|
|
echo "Example: ./scripts/new-app.sh my-blog"
|
|
exit 1
|
|
fi
|
|
|
|
APP="$1"
|
|
|
|
if ! [[ "$APP" =~ ^[a-zA-Z0-9][a-zA-Z0-9._-]*$ ]]; then
|
|
echo "Error: app name must be alphanumeric (hyphens, dots, underscores allowed)."
|
|
exit 1
|
|
fi
|
|
|
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
|
|
|
if [ -d "$REPO_ROOT/docker/$APP" ]; then
|
|
echo "Error: docker/$APP already exists."
|
|
exit 1
|
|
fi
|
|
|
|
echo "Creating docker/$APP/compose.yml..."
|
|
mkdir -p "$REPO_ROOT/docker/$APP"
|
|
cat > "$REPO_ROOT/docker/$APP/compose.yml" <<EOF
|
|
services:
|
|
app:
|
|
image: git.timothykim.net/timothykim/$APP:latest
|
|
restart: unless-stopped
|
|
networks:
|
|
- shared
|
|
|
|
networks:
|
|
shared:
|
|
external: true
|
|
EOF
|
|
|
|
echo "Creating .gitea/workflows/deploy-$APP.yml..."
|
|
mkdir -p "$REPO_ROOT/.gitea/workflows"
|
|
cat > "$REPO_ROOT/.gitea/workflows/deploy-$APP.yml" <<'OUTER'
|
|
name: Deploy APP_PLACEHOLDER
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- 'docker/APP_PLACEHOLDER/**'
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Deploy via SSH
|
|
uses: appleboy/ssh-action@v1
|
|
with:
|
|
host: ${{ secrets.DEPLOY_HOST }}
|
|
username: deploy
|
|
key: ${{ secrets.DEPLOY_KEY }}
|
|
script: deploy-APP_PLACEHOLDER
|
|
OUTER
|
|
sed -i "s/APP_PLACEHOLDER/$APP/g" "$REPO_ROOT/.gitea/workflows/deploy-$APP.yml"
|
|
|
|
echo ""
|
|
echo "Done! Files created:"
|
|
echo " - docker/$APP/compose.yml"
|
|
echo " - .gitea/workflows/deploy-$APP.yml"
|
|
echo ""
|
|
echo "Next steps:"
|
|
echo " 1. Edit docker/$APP/compose.yml to fit your app"
|
|
echo " 2. Commit and push to deploy"
|
|
echo " 3. Configure the proxy host in Nginx Proxy Manager"
|