name: Docker Image CI

on:
  push:
    branches: ['main']
  pull_request:

env:
  REGISTRY: git.dc09.ru  # Change to your registry (e.g., forgejo.example.com)
  GITHUB_TOKEN: ${{ secrets.FORGEJO_PASSWORD }}
  GITHUB_API_URL: https://git.dc09.ru
  GITHUB_BASE_REF: git.dc09.ru
  GITHUB_SERVER_URL: https://git.dc09.ru
  DOCKERHUB_TOKEN: ${{ secrets.FORGEJO_PASSWORD }}
  DOCKER_TOKEN: ${{ secrets.FORGEJO_PASSWORD }}
  FORGEJO_URL: https://git.dc09.ru

jobs:
  build-and-push:
    runs-on: ubuntu-latest
    strategy:
      matrix:
        images:
          - dockerfile: 'Dockerfile.openj9'
            image_name: 'openj9'
            context: './'
          - dockerfile: 'Dockerfile.piped'
            image_name: 'piped'
            context: './'
          # Add more images as needed

    steps:
      - name: Checkout repository
        uses: actions/checkout@v4

      - name: Log in to the Container registry
        uses: docker/login-action@v3
        with:
          registry: git.dc09.ru
          username: ${{ secrets.FORGEJO_USERNAME }}
          password: ${{ secrets.FORGEJO_PASSWORD }}
          token: ${{ secrets.FORGEJO_PASSWORD }}
          opts.auth: ${{ secrets.FORGEJO_PASSWORD }}
      - name: Printenv
        run: env | sort
      - name: Extract metadata (tags, labels)
        id: meta
        uses: docker/metadata-action@v5
        with:
          context: git
          images: |
            git.dc09.ru/${{ env.GITHUB_REPOSITORY_OWNER }}/${{ matrix.images.image_name }}
          tags: |
            type=ref,event=branch
            type=ref,event=pr
            type=semver,pattern={{version}}
            type=semver,pattern={{major}}.{{minor}}
          github-token: ${{ secrets.FORGEJO_PASSWORD }}
          github-server: https://git.dc09.ru


      - name: Build and push Docker image
        uses: docker/build-push-action@v5
        with:
          context: ${{ matrix.images.context }}
          file: ${{ matrix.images.dockerfile }}
          push: ${{ github.event_name == 'push' }}
          tags: ${{ steps.meta.outputs.tags }}
          labels: ${{ steps.meta.outputs.labels }}