stages:
  - build
  - deploy

variables:
  USER_SUPPORT_MAILBOX: alpha-test@erasme.org
  SMTP_HOST: mail0.erasme.org
  SMTP_PORT: 25
  # ADDITIONAL_FEEDBACK_EMAILS: 

build_development:
  stage: build
  only:
    - development
  script:
    - export TAG=dev
    - export MAIL_SERVICE_BIND_PORT=3000
    - docker-compose build 
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker-compose push

build_release:
  stage: build
  only:
    - tags
  # except:
  #   - /^(?!master).+@/
  script:
    - export TAG=$(echo $CI_COMMIT_TAG | sed 's/v//g')
    - export MAIL_SERVICE_BIND_PORT=3000
    - docker-compose build
    - 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 MAIL_SERVICE_BIND_PORT=3001
    - export MAIL_SUBJECT_PREFIX=alpha
    - export NO_REPLY_MAIL_ADDRESS=no-reply@erasme.org
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker-compose pull
    - docker-compose --project-name service-email-${TAG} up -d --force-recreate
  environment:
    name: development

deploy_staging:
  stage: deploy
  only:
    - development
  when: manual
  script:
    - export TAG=staging
    - export MAIL_SERVICE_BIND_PORT=3101
    - export MAIL_SUBJECT_PREFIX=alpha
    - export NO_REPLY_MAIL_ADDRESS=no-reply@erasme.org
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - TAG=dev docker-compose pull
    - export REGISTRY_PATH=web-et-numerique/web-et-numerique-internet/data.grandlyon.com/web-portal/components/services/mailer
    - docker tag $CI_REGISTRY/$REGISTRY_PATH:dev $CI_REGISTRY/$REGISTRY_PATH:${TAG}
    - docker push $CI_REGISTRY/$REGISTRY_PATH:${TAG}
    - docker-compose --project-name service-email-${TAG} up -d --force-recreate
  environment:
    name: staging