name: Docker Deployment

on:
  push:
    branches:
      - main

jobs:
  docker:
    runs-on: ubuntu-latest

    steps:
      - name: Checkout code
        uses: actions/checkout@v6

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v3

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v3
    
      - name: Debug secrets
        run: |
          echo "USERNAME=$GIT_USERNAME"
          echo "TOKEN_LENGTH=${#GIT_TOKEN}"
        env:
          GIT_USERNAME: ${{ secrets.GIT_USERNAME }}
          GIT_TOKEN: ${{ secrets.GIT_TOKEN }}

      - name: Login to Gitea Registry
        uses: docker/login-action@v3
        with:
          registry: http://52.156.106.39.nip.io
          username: ${{ secrets.GIT_USERNAME }}
          password: ${{ secrets.GIT_TOKEN }}

      - name: Build and Push Docker Image
        uses: docker/build-push-action@v5
        with:
          context: .
          push: true
          tags: |
            52.156.106.39.nip.io/${{ secrets.GIT_USERNAME }}/todo-nodejs-vx:latest
            52.156.106.39.nip.io/${{ secrets.GIT_USERNAME }}/todo-nodejs-vx:${{ github.run_number }}