# SPDX-FileCopyrightText: 2025 Sarah Vaupel <sarah.vaupel@uniworx.de>
#
# SPDX-License-Identifier: AGPL-3.0-or-later

parameters:
  - name: releaseTag
    type: string
  - name: releaseEndpoint
    type: string
    default: 'devfra'
    values:
      - 'devfra'
      - 'prodfra'

jobs:
  - job: Release
    displayName: Release ${{ parameters.releaseTag }}
    container:
      image: devfra.azurecr.io/de.fraport.build/tools:1.1.0
      endpoint: devfra
    steps:

      # Download required artifacts from pipeline
      - task: DownloadPipelineArtifact@2
        displayName: Download FraDrive binaries
        inputs:
          artifactName: Build_backend
          patterns: 'Build_backend/bin/*'
          targetPath: '$(Build.Repository.LocalPath)'

      - task: Docker@2
        displayName: Login to container registry
        inputs:
          command: login
          containerRegistry: '${{ parameters.releaseEndpoint }}'
      - task: Bash@3
        displayName: Build FraDrive container
        inputs:
          targetType: inline
          script: |
            cp docker/fradrive/Dockerfile .
            docker build \
            --tag $(buildImageUpstream)/fradrive:$(Build.BuildNumber) \
            --tag $(buildImageUpstream)/fradrive:${{parameters.releaseTag}} \
            --build-arg FROM_IMG=devfra.azurecr.io/de.fraport.trusted/ubuntu \
            --build-arg FROM_TAG=20.04 \
            --build-arg PROJECT_DIR=$(Build.Repository.LocalPath) \
            --build-arg IN_CI=true \
            --build-arg IN_CONTAINER=true \
            --build-arg HTTPS_PROXY=http://proxy.frankfurt-airport.de:8080 \
            --build-arg HTTP_PROXY=http://proxy.frankfurt-airport.de:8080 \
            --build-arg NO_PROXY='localhost,127.0.0.1,*.docker.internal,*.azmk8s.io,devfra.azurecr.io,devfra.westeurope.data.azurecr.io' \
            --build-arg FRAPORT_NOPROXY=dev.azure.com,*.dev.azure.com,*.fraport.de,*.frankfurt-airport.de \
            .
      - task: Docker@2
        displayName: Push container to registry
        inputs:
          command: push
          repository: 'de.fraport.fradrive.build/fradrive'
          tags: '$(Build.BuildNumber),${{parameters.releaseTag}}'
      - task: Docker@2
        displayName: Logout from container registry
        inputs:
          command: logout
          containerRegistry: '${{ parameters.releaseEndpoint }}'