stages:
  - build
  - deploy

build:
  stage: build
  script:
    - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
    - docker build --pull -t "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG-$CI_PIPELINE_ID" -t "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG-latest" .
    - docker push "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG-$CI_PIPELINE_ID"
    - docker push "$CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG-latest"

deploy_dev:
  stage: deploy
  script:
    - ssh $DEV_USER@$DEV_HOST kubectl set image deployment/localization localization="$CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG-$CI_PIPELINE_ID"
  only:
    - dev

deploy_master:
  stage: deploy
  script:
    - ssh $PROD_USER@$PROD_HOST kubectl set image deployment/localization localization="$CI_REGISTRY_IMAGE:$CI_BUILD_REF_SLUG-$CI_PIPELINE_ID"
  only:
    - master
