fix idempotency in app.sh, service.sh and nginx reload in cert handler

This commit is contained in:
2026-04-07 15:56:59 -04:00
parent fcc720ee7b
commit d2b9d0bce9
3 changed files with 57 additions and 26 deletions
+29 -14
View File
@@ -253,16 +253,22 @@ cmd_repo() {
}
cmd_files() {
local all_exist=true
for f in "docker/$APP/compose.yml" ".gitea/workflows/deploy-$APP.yml" "docker/nginx/conf.d/$APP.conf"; do
if [ -e "$REPO_ROOT/$f" ]; then
echo "Error: $f already exists."
exit 1
if [ ! -e "$REPO_ROOT/$f" ]; then
all_exist=false
break
fi
done
if [ "$all_exist" = true ]; then
echo " All files already exist, skipping."
return
fi
echo "==> Creating docker/$APP/compose.yml..."
mkdir -p "$REPO_ROOT/docker/$APP"
cat > "$REPO_ROOT/docker/$APP/compose.yml" <<EOF
if [ ! -e "$REPO_ROOT/docker/$APP/compose.yml" ]; then
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/hantim/$APP:latest
@@ -275,10 +281,14 @@ networks:
shared:
external: true
EOF
else
echo " docker/$APP/compose.yml already exists, skipping."
fi
echo "==> Creating .gitea/workflows/deploy-$APP.yml..."
mkdir -p "$REPO_ROOT/.gitea/workflows"
cat > "$REPO_ROOT/.gitea/workflows/deploy-$APP.yml" <<'OUTER'
if [ ! -e "$REPO_ROOT/.gitea/workflows/deploy-$APP.yml" ]; then
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:
@@ -299,10 +309,14 @@ jobs:
chmod 600 ~/.ssh/deploy_key
ssh -o StrictHostKeyChecking=yes -i ~/.ssh/deploy_key deploy@${{ vars.DEPLOY_HOST }} deploy-APP_PLACEHOLDER
OUTER
sed -i "s/APP_PLACEHOLDER/$APP/g" "$REPO_ROOT/.gitea/workflows/deploy-$APP.yml"
sed -i "s/APP_PLACEHOLDER/$APP/g" "$REPO_ROOT/.gitea/workflows/deploy-$APP.yml"
else
echo " .gitea/workflows/deploy-$APP.yml already exists, skipping."
fi
echo "==> Creating docker/nginx/conf.d/$APP.conf..."
cat > "$REPO_ROOT/docker/nginx/conf.d/$APP.conf" <<NGINX
if [ ! -e "$REPO_ROOT/docker/nginx/conf.d/$APP.conf" ]; then
echo "==> Creating docker/nginx/conf.d/$APP.conf..."
cat > "$REPO_ROOT/docker/nginx/conf.d/$APP.conf" <<NGINX
# Redirect HTTP to HTTPS, bare domain to www
server {
listen 80;
@@ -357,8 +371,9 @@ server {
}
}
NGINX
echo " Files created. Run 'git add' and commit when ready."
else
echo " docker/nginx/conf.d/$APP.conf already exists, skipping."
fi
}
cmd_cert() {