name: Build docker image

env:
  PACKAGE_NAME: backend
  PACKAGE_TAG: latest

run-name: ${{ github.actor }} is building the docker image

on:
  push:
#    tags:
#      - v**
    branches:
      - main
      - master

jobs:
    build_docker_image:
        runs-on: ubuntu-latest

        steps:
          - name: Checking out repository
            uses: actions/checkout@v4

          - name: Login to Goliath Container Registry
            uses: docker/login-action@v3
            with:
              registry: ${{ vars.PACKAGE_REPOSITORY }}
              username: ${{ secrets.PACKAGE_USER }}
              password: ${{ secrets.PACKAGE_PASS }}

          - name: Setup PHP
            uses: "shivammathur/setup-php@v2"

          - name: Setup Node.js 20.x
            uses: actions/setup-node@v4
            with:
              node-version: 20.x

          - name: Initializing packages
            run: |
              pushd src
              npm install
              composer install
              popd

          - name: Compiling assets
            run: |
              pushd src
              npm run build
              popd

          - name: Set up Docker Buildx
            uses: docker/setup-buildx-action@v3

          - name: Create Docker Buildx contex
            run: docker buildx create --name goliath; docker buildx use goliath; docker buildx inspect --bootstrap;

          - name: Building docker image
            run: |
              docker buildx build . \
                --file build/nginx/Dockerfile \
                --platform linux/amd64,linux/arm64 \
                --tag ${{ vars.PACKAGE_REPOSITORY }}/${{ vars.PACKAGE_ORGANIZATION }}/${{ env.PACKAGE_NAME }}:${{ env.PACKAGE_TAG }} \
                --provenance=false \
                --sbom=false \
                --push
