stages:
  - build
  - deploy

build_development:
  stage: build
  tags:
    - build
  only:
    - development
  script:
    - export TAG=dev
    - export APP_PORT=8090
    - export CONFIG_FILE_PATH=./config/config.json
    - docker-compose build --build-arg conf=dev admin-gui
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker-compose push

build_release:
  stage: build
  tags:
    - build
  only:
    - tags
  # except:
  #   - /^(?!master).+@/
  script:
    - export TAG=$(echo $CI_COMMIT_TAG | sed 's/v//g')
    - export APP_PORT=8090
    - export CONFIG_FILE_PATH=./config/config.json
    - docker-compose build --build-arg conf=prod admin-gui
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker-compose push

deploy_development:
  stage: deploy
  only:
    - development
  script:
    - export TAG=dev
    - export APP_PORT=8090
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker-compose pull
    - export CONFIG_FILE_PATH=./config/config-dev.json
    - docker-compose --project-name admin-gui-${TAG} up -d --force-recreate
  environment:
    name: development

deploy_staging:
  stage: deploy
  only:
    - development
  when: manual
  script:
    - export TAG=staging
    - export APP_PORT=8190
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - TAG=dev docker-compose pull
    - docker tag $CI_REGISTRY/refonte-data/admin-gui:dev $CI_REGISTRY/refonte-data/admin-gui:${TAG}
    - docker push $CI_REGISTRY/refonte-data/admin-gui:${TAG}
    - export CONFIG_FILE_PATH=./config/config-rec.json
    - docker-compose --project-name admin-gui-${TAG} up -d --force-recreate
  environment:
    name: staging
