From c816c3128f8c2695978d4cfde3b469844b0b2102 Mon Sep 17 00:00:00 2001 From: Jeff Emmett Date: Wed, 1 Apr 2026 02:13:25 -0700 Subject: [PATCH] Add CI/CD pipeline (Gitea Actions) Build + push to registry + deploy + smoke test with auto-rollback. Co-Authored-By: Claude Opus 4.6 --- .gitea/workflows/ci.yml | 65 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 .gitea/workflows/ci.yml diff --git a/.gitea/workflows/ci.yml b/.gitea/workflows/ci.yml new file mode 100644 index 0000000..c5768e3 --- /dev/null +++ b/.gitea/workflows/ci.yml @@ -0,0 +1,65 @@ +# Gitea Actions CI/CD — Static Site (no tests, build + deploy only) +# Copy to: /.gitea/workflows/ci.yml +# Replace: lunar-calendar, /opt/websites/lunar-calendar, https://lunarcal.jeffemmett.com/ + +name: CI/CD + +on: + push: + branches: [main] + +env: + REGISTRY: gitea.jeffemmett.com + IMAGE: gitea.jeffemmett.com/jeffemmett/lunar-calendar + +jobs: + deploy: + runs-on: ubuntu-latest + container: + image: docker:cli + steps: + - name: Setup tools + run: apk add --no-cache git openssh-client curl + + - name: Checkout + run: git clone --depth 1 --branch ${{ github.ref_name }} http://token:${{ github.token }}@server:3000/${{ github.repository }}.git . + + - name: Set image tag + run: | + SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-8) + echo "IMAGE_TAG=${SHORT_SHA}" >> $GITHUB_ENV + + - name: Build and push image + run: | + docker build -t ${{ env.IMAGE }}:${{ env.IMAGE_TAG }} -t ${{ env.IMAGE }}:latest . + echo "${{ secrets.REGISTRY_TOKEN }}" | docker login ${{ env.REGISTRY }} -u ${{ secrets.REGISTRY_USER }} --password-stdin + docker push ${{ env.IMAGE }}:${{ env.IMAGE_TAG }} + docker push ${{ env.IMAGE }}:latest + + - name: Deploy + run: | + mkdir -p ~/.ssh + echo "${{ secrets.DEPLOY_SSH_KEY }}" | base64 -d > ~/.ssh/deploy_key + chmod 600 ~/.ssh/deploy_key + ssh -o StrictHostKeyChecking=no -i ~/.ssh/deploy_key root@${{ secrets.DEPLOY_HOST }} " + cd /opt/websites/lunar-calendar + cat .last-deployed-tag 2>/dev/null > .rollback-tag || true + echo '${{ env.IMAGE_TAG }}' > .last-deployed-tag + docker pull ${{ env.IMAGE }}:${{ env.IMAGE_TAG }} + IMAGE_TAG=${{ env.IMAGE_TAG }} docker compose up -d --no-build + " + + - name: Smoke test + run: | + sleep 10 + HTTP_CODE=$(curl -sS -o /dev/null -w "%{http_code}" --max-time 15 https://lunarcal.jeffemmett.com/ 2>/dev/null || echo "000") + if [ "$HTTP_CODE" != "200" ]; then + echo "Smoke test failed — rolling back" + ROLLBACK_TAG=$(ssh -o StrictHostKeyChecking=no -i ~/.ssh/deploy_key root@${{ secrets.DEPLOY_HOST }} "cat /opt/websites/lunar-calendar/.rollback-tag 2>/dev/null") + if [ -n "$ROLLBACK_TAG" ]; then + ssh -o StrictHostKeyChecking=no -i ~/.ssh/deploy_key root@${{ secrets.DEPLOY_HOST }} \ + "cd /opt/websites/lunar-calendar && IMAGE_TAG=$ROLLBACK_TAG docker compose up -d --no-build" + fi + exit 1 + fi + echo "Smoke test passed"