From 8a30405d18ec5e259e82c87e883ead1f96b9c05e Mon Sep 17 00:00:00 2001 From: Timothy Kim Date: Mon, 16 Mar 2026 18:09:23 -0400 Subject: [PATCH] add hantim.net --- .gitea/workflows/deploy-hantim.net.yml | 18 ++++++++++ docker/hantim.net/compose.yml | 11 ++++++ docker/nginx/conf.d/hantim.net.conf | 48 ++++++++++++++++++++++++++ scripts/new-app.sh | 21 +++++++++-- 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 .gitea/workflows/deploy-hantim.net.yml create mode 100644 docker/hantim.net/compose.yml create mode 100644 docker/nginx/conf.d/hantim.net.conf diff --git a/.gitea/workflows/deploy-hantim.net.yml b/.gitea/workflows/deploy-hantim.net.yml new file mode 100644 index 0000000..c1fa30d --- /dev/null +++ b/.gitea/workflows/deploy-hantim.net.yml @@ -0,0 +1,18 @@ +name: Deploy hantim.net + +on: + push: + branches: [main] + paths: + - 'docker/hantim.net/**' + +jobs: + deploy: + runs-on: ubuntu-latest + steps: + - name: Deploy via SSH + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_SSH_KEY }}" > ~/.ssh/deploy_key + chmod 600 ~/.ssh/deploy_key + ssh -o StrictHostKeyChecking=accept-new -i ~/.ssh/deploy_key deploy@${{ vars.DEPLOY_HOST }} deploy-hantim.net diff --git a/docker/hantim.net/compose.yml b/docker/hantim.net/compose.yml new file mode 100644 index 0000000..98e55c4 --- /dev/null +++ b/docker/hantim.net/compose.yml @@ -0,0 +1,11 @@ +services: + app: + image: git.timothykim.net/hantim/hantim.net:latest + restart: unless-stopped + container_name: hantim_net + networks: + - shared + +networks: + shared: + external: true diff --git a/docker/nginx/conf.d/hantim.net.conf b/docker/nginx/conf.d/hantim.net.conf new file mode 100644 index 0000000..f86ed26 --- /dev/null +++ b/docker/nginx/conf.d/hantim.net.conf @@ -0,0 +1,48 @@ +# Redirect HTTP to HTTPS, bare domain to www +server { + listen 80; + listen [::]:80; + server_name hantim.net www.hantim.net; + + location /.well-known/acme-challenge/ { + root /var/www/certbot; + } + + location / { + return 301 https://www.hantim.net$request_uri; + } +} + +# Redirect bare HTTPS domain to www +server { + listen 443 ssl; + listen [::]:443 ssl; + http2 on; + server_name hantim.net; + + ssl_certificate /etc/letsencrypt/live/hantim.net/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/hantim.net/privkey.pem; + + return 301 https://www.hantim.net$request_uri; +} + +# Main site +server { + listen 443 ssl; + listen [::]:443 ssl; + http2 on; + server_name www.hantim.net; + + ssl_certificate /etc/letsencrypt/live/hantim.net/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/hantim.net/privkey.pem; + + add_header Strict-Transport-Security "max-age=63072000; preload" always; + + location / { + proxy_pass http://hantim_net:80; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } +} diff --git a/scripts/new-app.sh b/scripts/new-app.sh index 06f7d19..aab49dd 100755 --- a/scripts/new-app.sh +++ b/scripts/new-app.sh @@ -276,10 +276,27 @@ git push # --- Trigger initial build --- echo "==> Triggering initial build for $APP..." -curl -sf -X POST "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \ +TRIGGER_CODE=$(curl -s -o /dev/null -w "%{http_code}" \ + -X POST "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \ -H "Authorization: token $GITEA_TOKEN" \ -H "Content-Type: application/json" \ - -d "{\"content\": \"$(echo -n "initial deploy" | base64)\", \"message\": \"trigger initial build\"}" > /dev/null + -d "{\"content\": \"$(echo -n "initial deploy" | base64)\", \"message\": \"trigger initial build\"}") + +if [ "$TRIGGER_CODE" = "201" ]; then + echo " Build triggered." +elif [ "$TRIGGER_CODE" = "422" ]; then + # File already exists — update it to trigger a new build + EXISTING_SHA=$(curl -s "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \ + -H "Authorization: token $GITEA_TOKEN" | jq -r '.sha') + curl -s -o /dev/null -X PUT "$GITEA_URL/api/v1/repos/$GITEA_ORG/$APP/contents/.deploy-trigger" \ + -H "Authorization: token $GITEA_TOKEN" \ + -H "Content-Type: application/json" \ + -d "{\"content\": \"$(echo -n "redeploy $(date +%s)" | base64)\", \"sha\": \"$EXISTING_SHA\", \"message\": \"trigger rebuild\"}" + echo " Build re-triggered (file already existed)." +else + echo " Warning: Could not trigger build (HTTP $TRIGGER_CODE). Check manually:" + echo " $GITEA_URL/$GITEA_ORG/$APP/actions" +fi # --- Verify ---