Something went wrong. Try again.
AtAuth
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133name: Deploy ATAuth to DO# CI/CD: Gitea Actions → DigitalOcean managed k8s
on: push: branches: [main] paths-ignore: - '*.md' - 'docs/**'
env: REGISTRY: registry.digitalocean.com/ghostmesh-registry IMAGE_NAME: atauth DEPLOYMENT: atauth NAMESPACE: atauth
jobs: test: name: Test Gateway runs-on: ubuntu-latest defaults: run: working-directory: gateway steps: - name: Checkout code uses: actions/checkout@v4
- name: Setup Node.js uses: actions/setup-node@v4 with: node-version: '20'
- name: Install dependencies run: npm ci
- name: Type check run: npm run typecheck
- name: Lint run: npm run lint
- name: Run tests run: npm run test:run
- name: Notify test failure if: failure() run: | SHORT_SHA=$(echo "${{ github.sha }}" | cut -c1-7) FIRST_LINE=$(echo "${{ github.event.head_commit.message }}" | head -1) MSG=$(jq -n --arg body "🧪 ${{ github.repository }}: tests FAILED @ ${SHORT_SHA} └ ${FIRST_LINE}" '{msgtype: "m.text", body: $body}') curl -sf -X PUT \ "${{ secrets.MATRIX_HOMESERVER_URL }}/_matrix/client/v3/rooms/${{ secrets.MATRIX_CICD_ROOM_ID }}/send/m.room.message/cicd-$(date +%s)-$$" \ -H "Authorization: Bearer ${{ secrets.MATRIX_ACCESS_TOKEN }}" \ -H "Content-Type: application/json" \ -d "$MSG" || true
build-and-deploy: name: Build, Push, Deploy runs-on: host needs: [test] steps: - name: Checkout code uses: actions/checkout@v4
- name: Set short SHA id: sha run: echo "short=$(echo ${{ github.sha }} | cut -c1-7)" >> "$GITHUB_OUTPUT"
- name: Notify build started env: COMMIT_MSG: ${{ github.event.head_commit.message }} run: | FIRST_LINE=$(echo "$COMMIT_MSG" | head -1) MSG=$(jq -n --arg body "🔨 ${{ github.repository }}: build started @ ${{ steps.sha.outputs.short }} ├ Commit: $FIRST_LINE └ Triggered by: ${{ github.actor }}" '{msgtype: "m.text", body: $body}') curl -sf -X PUT \ "${{ secrets.MATRIX_HOMESERVER_URL }}/_matrix/client/v3/rooms/${{ secrets.MATRIX_CICD_ROOM_ID }}/send/m.room.message/cicd-$(date +%s)-$$" \ -H "Authorization: Bearer ${{ secrets.MATRIX_ACCESS_TOKEN }}" \ -H "Content-Type: application/json" \ -d "$MSG" || true
- name: Login to DO Container Registry run: echo "${{ secrets.DO_REGISTRY_TOKEN }}" | docker login registry.digitalocean.com -u "${{ secrets.DO_REGISTRY_TOKEN }}" --password-stdin
- name: Build Docker image run: | docker build \ --platform linux/amd64 \ -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.sha.outputs.short }} \ -t ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest \ gateway/
- name: Push Docker image run: | docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.sha.outputs.short }} docker push ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest
- name: Deploy to DO Kubernetes run: | echo "${{ secrets.DO_KUBECONFIG }}" | base64 -d > /tmp/kubeconfig KUBECONFIG=/tmp/kubeconfig kubectl set image deployment/${{ env.DEPLOYMENT }} \ ${{ env.DEPLOYMENT }}=${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.sha.outputs.short }} \ -n ${{ env.NAMESPACE }} KUBECONFIG=/tmp/kubeconfig kubectl rollout status deployment/${{ env.DEPLOYMENT }} -n ${{ env.NAMESPACE }} --timeout=120s rm -f /tmp/kubeconfig
- name: Notify build result if: always() env: COMMIT_MSG: ${{ github.event.head_commit.message }} run: | if [ "${{ job.status }}" = "success" ]; then EMOJI="✅"; STATUS="deployed" else EMOJI="❌"; STATUS="FAILED" fi FIRST_LINE=$(echo "$COMMIT_MSG" | head -1) MSG=$(jq -n --arg body "${EMOJI} ${{ github.repository }}: ${STATUS} @ ${{ steps.sha.outputs.short }} └ $FIRST_LINE" '{msgtype: "m.text", body: $body}') curl -sf -X PUT \ "${{ secrets.MATRIX_HOMESERVER_URL }}/_matrix/client/v3/rooms/${{ secrets.MATRIX_CICD_ROOM_ID }}/send/m.room.message/cicd-$(date +%s)-$$" \ -H "Authorization: Bearer ${{ secrets.MATRIX_ACCESS_TOKEN }}" \ -H "Content-Type: application/json" \ -d "$MSG" || true
- name: Clean up Docker images if: always() run: | docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.sha.outputs.short }} 2>/dev/null || true docker rmi ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest 2>/dev/null || true