image: docker

services:
  - docker:dind

stages:
  - build
  - deploy

step-deploy-prod:
  stage: build
  script:
    - echo "building for $CI_COMMIT_REF_NAME"
    - sudo docker image prune -f
    - sudo docker build -t gitlab.jonasled.de/jonasled/url_shorter_docker .
    - sudo docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - sudo docker push gitlab.jonasled.de/jonasled/url_shorter_docker

step-deploy-prod:
  stage: deploy
  only:
    - master
  script:
    - sudo apt-get install -y python-pip
    - sudo pip install docker-compose
    - replace "5000:5000" "5003:5000" -- docker-compose.yml
    - replace "domains=" "$domains" -- docker-compose.yml
    - replace "recaptcha_private=" "$recaptcha_private" -- docker-compose.yml
    - replace "recaptcha_public=" "$recaptcha_public" -- docker-compose.yml
    - sudo docker-compose up -d
  environment: master 