image: docker:19.03.12

variables:
  DOCKER_TLS_CERTDIR: "/certs"
  IMAGE_VER: 1.4.0

services:
  - docker:19.03.12-dind

before_script:
  - docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY

build:
  stage: build
  script:
    - docker pull $CI_REGISTRY_IMAGE:latest || true
    - docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$IMAGE_VER --tag $CI_REGISTRY_IMAGE:latest .
    - docker push $CI_REGISTRY_IMAGE:$IMAGE_VER
    - docker push $CI_REGISTRY_IMAGE:latest
