name: Build and push image

on:
  push:
    branches:
      - master

jobs:
  docker-build:
    runs-on: [self-hosted, linux, x64, docker]
    env:
      IMAGE_NAME: cr.danosito.com/0xb00b5/0xb00b5-packmate

    steps:
      - name: Checkout
        uses: actions/checkout@v4
        with:
          submodules: recursive

      - name: Login to registry
        run: |
          echo "${{ vars.REGISTRY_PASSWORD }}" | docker login cr.danosito.com \
            -u "${{ vars.REGISTRY_USER }}" --password-stdin


      - name: Build image
        env:
          IMAGE_TAG: ${{ gitea.sha }}
        run: |
          docker build \
            -f docker/Dockerfile_app \
            -t "${IMAGE_NAME}:${IMAGE_TAG}" \
            -t "${IMAGE_NAME}:latest" \
            .

      - name: Push image
        env:
          IMAGE_TAG: ${{ gitea.sha }}
        run: |
          docker push "${IMAGE_NAME}:${IMAGE_TAG}"
          docker push "${IMAGE_NAME}:latest"
