diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..a372fbf --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,83 @@ +name: Deploy ATAuth to DO + +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 + + 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: 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 rollout restart deployment/${{ env.DEPLOYMENT }} -n ${{ env.NAMESPACE }} + KUBECONFIG=/tmp/kubeconfig kubectl rollout status deployment/${{ env.DEPLOYMENT }} -n ${{ env.NAMESPACE }} --timeout=120s + rm -f /tmp/kubeconfig + + - 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