stages:
  - release

variables:
  TAGS: ""

release-image:
  image: docker:24.0.6
  stage: release
  rules:
    - if: '$TAGS'
  before_script:
    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
  script:
    - if [ -z "$TAGS" ]; then export TAGS=$(cat tags.txt); fi
    - |
      for tag in $TAGS; do
        export IMAGE_TAG=$CI_REGISTRY_IMAGE:$tag
        echo $IMAGE_TAG
        sed "s/latest/$tag/g" Dockerfile > Dockerfile.tmp
        docker build . --pull -f Dockerfile.tmp -t $IMAGE_TAG
        docker push $IMAGE_TAG
      done