stages:
  - build_test
  - deploy_to_test

variables:
  DOCKER_DRIVER: overlay2

build_test:
  stage: build_test
  image: docker:stable
  services:
    - docker:dind
  script:
    - docker login -u "gitlab-ci-token" -p ${CI_JOB_TOKEN} ${CI_REGISTRY}
    - docker build -t ${CI_REGISTRY_IMAGE}:${CI_PIPELINE_ID} .
    - docker push ${CI_REGISTRY_IMAGE}:${CI_PIPELINE_ID}
  environment:
    name: ${CI_COMMIT_REF_NAME}
    url: https://xvideos.com
  only:
    - testX
  tags:
    - buidl1-dind

deploy_to_test:
  stage: deploy_to_test
  image: docker:stable
  script:
  - wget https://storage.googleapis.com/kubernetes-release/release/v1.14.3/bin/linux/amd64/kubectl && chmod +x ./kubectl
  - sed 's|_PROJECT_|'"${CI_PROJECT_NAME}"'|g; s|_NS_|'"${CI_ENVIRONMENT_NAME}"'|g' Docker/manifests/app.yml.tpl > app.yml; cat app.yml
  - wget https://github.com/garethr/kubeval/releases/download/0.7.3/kubeval-linux-amd64.tar.gz && tar xvf kubeval-linux-amd64.tar.gz && ./kubeval app.yml
  - ./kubectl apply -f app.yml
  environment:
    name: ${CI_COMMIT_REF_NAME}
    url: http://guru.test
  only:
  - test
  tags:
  - buidl1-dind
