midr @ 8f37ab826eed4efcf1dbd883aac03780fa350a46

 1docker-build:
 2  image: docker:latest
 3  stage: build
 4  services:
 5    - docker:dind
 6  before_script:
 7    - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
 8  script:
 9    - |
10      if [[ "$CI_COMMIT_BRANCH" == "$CI_DEFAULT_BRANCH" ]]; then
11        tag=""
12        echo "Running on default branch '$CI_DEFAULT_BRANCH': tag = 'latest'"
13      else
14        tag=":$CI_COMMIT_REF_SLUG"
15        echo "Running on branch '$CI_COMMIT_BRANCH': tag = $tag"
16      fi      
17    - docker build --pull -t "$CI_REGISTRY_IMAGE${tag}" .
18    - docker push "$CI_REGISTRY_IMAGE${tag}"
19
20  rules:
21    - if: $CI_COMMIT_BRANCH
22      exists:
23        - Dockerfile