image: ubuntu:xenial

stages:
  - build

build:
  stage: build
  script:
    - apt-get update && apt-get install -y docker.io make
    - make
    - if [ -z "${DOCKER_USER}" ]; then export DOCKER_USER=gitlab-ci-token; export DOCKER_PASSWORD=${CI_BUILD_TOKEN}; fi
    - if [ -n "${DOCKER_REGISTRY}" ]; then docker login -u $DOCKER_USER -p=$DOCKER_PASSWORD $DOCKER_REGISTRY; fi
    - if [ -n "${DOCKER_REGISTRY}" ]; then make docker-push; fi

image: ubuntu:xenial

stages:
  - build

build:
  stage: build
  script:
    - apt-get update && apt-get install -y docker.io make
    # We allow the user to control which Docker registry is used through the
    # env var DOCKER_REGISTRY. If it is not set then we assume we should use
    # the GitLab built-in Docker registry so we check if it is enabled.
    # CI_REGISTRY is only set when the GitLab Docker registry is enabled
    - if [ -z "${DOCKER_REGISTRY}"]; then if [ -n "${CI_REGISTRY}" ]; then export DOCKER_USER=gitlab-ci-token; export DOCKER_PASSWORD=${CI_BUILD_TOKEN}; export DOCKER_REGISTRY=${CI_REGISTRY_IMAGE}; fi; fi
    # if DOCKER_REGISTRY set, either explicitly by user or implicitly by GitLab
    # (see above) we login to repo, build images and push them
    - if [ -n "${DOCKER_REGISTRY}" ]; then docker login -u ${DOCKER_USER} -p=${DOCKER_PASSWORD} ${DOCKER_REGISTRY}; fi
    - if [ -n "${DOCKER_REGISTRY}" ]; then make -j && make docker-push; fi

Fix docker push for GitLab CI
Fix docker push for GitLab CI

We default to using the built-in Docker registry in GitLab if one isn't
explicitly provided.
