fix new-app: retry build trigger, clean up temp nginx conf, add remove-app script
This commit is contained in:
@@ -27,6 +27,7 @@ NGINXCONF
|
|||||||
certbot certonly --webroot -w /opt/hantim/docker/nginx/certbot/www \
|
certbot certonly --webroot -w /opt/hantim/docker/nginx/certbot/www \
|
||||||
--non-interactive --agree-tos --register-unsafely-without-email \
|
--non-interactive --agree-tos --register-unsafely-without-email \
|
||||||
--cert-name "$APP" -d "$APP" -d "www.$APP"
|
--cert-name "$APP" -d "$APP" -d "www.$APP"
|
||||||
|
rm -f "/opt/hantim/docker/nginx/conf.d/$APP.conf"
|
||||||
echo "Certificate issued for $APP"
|
echo "Certificate issued for $APP"
|
||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|||||||
+7
-1
@@ -276,11 +276,17 @@ git push
|
|||||||
# --- Trigger initial build ---
|
# --- Trigger initial build ---
|
||||||
|
|
||||||
echo "==> Triggering initial build for $APP..."
|
echo "==> Triggering initial build for $APP..."
|
||||||
TRIGGER_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
# Wait for template repo to be ready (Gitea generates content asynchronously)
|
||||||
|
for i in $(seq 1 60); do
|
||||||
|
TRIGGER_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
-X POST "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \
|
-X POST "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \
|
||||||
-H "Authorization: token $GITEA_TOKEN" \
|
-H "Authorization: token $GITEA_TOKEN" \
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d "{\"content\": \"$(echo -n "initial deploy" | base64)\", \"message\": \"trigger initial build\"}")
|
-d "{\"content\": \"$(echo -n "initial deploy" | base64)\", \"message\": \"trigger initial build\"}")
|
||||||
|
[ "$TRIGGER_CODE" != "404" ] && break
|
||||||
|
echo " Waiting for repo to be ready..."
|
||||||
|
sleep 2
|
||||||
|
done
|
||||||
|
|
||||||
if [ "$TRIGGER_CODE" = "201" ]; then
|
if [ "$TRIGGER_CODE" = "201" ]; then
|
||||||
echo " Build triggered."
|
echo " Build triggered."
|
||||||
|
|||||||
Executable
+82
@@ -0,0 +1,82 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
GITEA_URL="https://git.timothykim.net"
|
||||||
|
GITEA_ORG="hantim"
|
||||||
|
|
||||||
|
if [ -z "${1:-}" ]; then
|
||||||
|
echo "Usage: ./scripts/remove-app.sh <domain>"
|
||||||
|
echo " Example: ./scripts/remove-app.sh hcsuzuki.net"
|
||||||
|
echo ""
|
||||||
|
echo "Removes: local files (compose, workflow, nginx conf), Gitea repo."
|
||||||
|
echo "Does NOT remove: DNS records, SSL certs."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
APP="$1"
|
||||||
|
REPO_ROOT="$(cd "$(dirname "$0")/.." && pwd)"
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
# --- Check dependencies ---
|
||||||
|
|
||||||
|
if ! command -v bw &>/dev/null; then
|
||||||
|
echo "Error: Bitwarden CLI (bw) is not installed."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Get Gitea API token from Bitwarden ---
|
||||||
|
|
||||||
|
if bw status 2>/dev/null | grep -q '"status":"unauthenticated"'; then
|
||||||
|
echo "Log in to Bitwarden:"
|
||||||
|
bw login
|
||||||
|
fi
|
||||||
|
|
||||||
|
if bw status 2>/dev/null | grep -q '"status":"locked"'; then
|
||||||
|
BW_SESSION=$(bw unlock --raw)
|
||||||
|
export BW_SESSION
|
||||||
|
fi
|
||||||
|
|
||||||
|
bw sync --session "${BW_SESSION:-}"
|
||||||
|
GITEA_TOKEN=$(bw get notes hantim-new-app-script --session "${BW_SESSION:-}")
|
||||||
|
|
||||||
|
# --- Delete Gitea repo ---
|
||||||
|
|
||||||
|
echo "==> Deleting Gitea repo $GITEA_ORG/$APP..."
|
||||||
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
||||||
|
-X DELETE "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP" \
|
||||||
|
-H "Authorization: token $GITEA_TOKEN")
|
||||||
|
|
||||||
|
if [ "$HTTP_CODE" = "204" ]; then
|
||||||
|
echo " Deleted."
|
||||||
|
elif [ "$HTTP_CODE" = "404" ]; then
|
||||||
|
echo " Repo does not exist, skipping."
|
||||||
|
else
|
||||||
|
echo " Warning: unexpected response (HTTP $HTTP_CODE)."
|
||||||
|
fi
|
||||||
|
|
||||||
|
# --- Remove local files ---
|
||||||
|
|
||||||
|
echo "==> Removing local files..."
|
||||||
|
REMOVED=()
|
||||||
|
|
||||||
|
for f in "docker/$APP" ".gitea/workflows/deploy-$APP.yml" "docker/nginx/conf.d/$APP.conf"; do
|
||||||
|
if [ -e "$REPO_ROOT/$f" ]; then
|
||||||
|
git -C "$REPO_ROOT" rm -rf "$f"
|
||||||
|
REMOVED+=("$f")
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
if [ ${#REMOVED[@]} -gt 0 ]; then
|
||||||
|
echo "==> Committing and pushing..."
|
||||||
|
cd "$REPO_ROOT"
|
||||||
|
git commit -m "remove $APP"
|
||||||
|
git push
|
||||||
|
else
|
||||||
|
echo " No local files to remove."
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo "Done. DNS records and SSL certs were left in place."
|
||||||
Reference in New Issue
Block a user