docker-build: # docker-in-docker: the runner uses docker from inside a docker container to execute the CI-jobs image: docker:20 # provides the docker toolset (but without an active daemon) stage: build rules: - changes: # only run CI when these files have changed - "*.py" - "Dockerfile" - ".gitlab-ci.yml" # services configure images that run during jobs linked to the image (above) services: - docker:dind # dind build on docker and starts up the dockerdaemon (docker itself doesn't do that), which is needed to call docker build etc. before_script: # docker login asks for the password to be passed through stdin for security - docker login -u $CI_REGISTRY_USER -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY script: # fetches the latest image from this projects registry to use as cache (not failing if image is not found) - docker pull $CI_REGISTRY_IMAGE:latest || true # build - > docker build --pull --cache-from $CI_REGISTRY_IMAGE:latest --label "org.opencontainers.image.title=$CI_PROJECT_TITLE" --label "org.opencontainers.image.url=$CI_PROJECT_URL" --label "org.opencontainers.image.created=$CI_JOB_STARTED_AT" --label "org.opencontainers.image.revision=$CI_COMMIT_SHA" --label "org.opencontainers.image.version=$CI_COMMIT_REF_NAME" --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA . # tag and push - docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHA $CI_REGISTRY_IMAGE:latest - docker push $CI_REGISTRY_IMAGE:latest