77 lines
2.9 KiB
YAML
77 lines
2.9 KiB
YAML
image: docker:19.03.12
|
|
|
|
stages:
|
|
- docker_setup
|
|
- docker_test
|
|
- docker_push
|
|
|
|
variables:
|
|
# When using dind service, we need to instruct docker to talk with
|
|
# the daemon started inside of the service. The daemon is available
|
|
# with a network connection instead of the default
|
|
# /var/run/docker.sock socket. Docker 19.03 does this automatically
|
|
# by setting the DOCKER_HOST in
|
|
# https://github.com/docker-library/docker/blob/d45051476babc297257df490d22cbd806f1b11e4/19.03/docker-entrypoint.sh#L23-L29
|
|
#
|
|
# The 'docker' hostname is the alias of the service container as described at
|
|
# https://docs.gitlab.com/ee/ci/docker/using_docker_images.html#accessing-the-services.
|
|
#
|
|
# Specify to Docker where to create the certificates, Docker will
|
|
# create them automatically on boot, and will create
|
|
# `/certs/client` that will be shared between the service and job
|
|
# container, thanks to volume mount from config.toml
|
|
DOCKER_TLS_CERTDIR: "/certs"
|
|
# Use TLS https://docs.gitlab.com/ee/ci/docker/using_docker_build.html#tls-enabled
|
|
DOCKER_HOST: tcp://docker:2376
|
|
|
|
# Support caching images between jobs
|
|
CI_LOCAL_REGISTRY_NAME: "localhost:5000"
|
|
CI_LOCAL_REGISTRY_IMAGE: "localhost:5000/reseed-tools"
|
|
|
|
services:
|
|
- name: docker:19.03.12-dind
|
|
command:
|
|
- --insecure-registry
|
|
- localhost:5000
|
|
|
|
# Login to job registry and publish registry
|
|
before_script:
|
|
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
|
|
|
|
start_registry:
|
|
stage: docker_setup
|
|
script:
|
|
- docker run -d -p 5000:5000 registry:2
|
|
|
|
# Make sure we can build a docker image
|
|
# It's pushed to the pipeline-local registry which acts as a cache
|
|
build_docker:
|
|
stage: docker_test
|
|
script:
|
|
# Make sure we can connect to the registry service
|
|
- docker pull $CI_REGISTRY_IMAGE:latest || true
|
|
- docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA --tag $CI_LOCAL_REGISTRY_IMAGE:latest .
|
|
- docker push $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
|
- docker push $CI_LOCAL_REGISTRY_IMAGE:latest
|
|
|
|
test_pull_local_docker:
|
|
stage: docker_push
|
|
script:
|
|
- docker pull $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
|
|
|
|
push_docker:
|
|
stage: docker_push
|
|
script:
|
|
- docker pull $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA || true
|
|
- docker tag $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
|
- docker tag $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
|
|
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
|
- docker push $CI_REGISTRY_IMAGE:latest
|
|
# - docker pull $CI_REGISTRY_IMAGE:latest || true
|
|
# - docker build --cache-from $CI_REGISTRY_IMAGE:latest --tag $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG --tag $CI_REGISTRY_IMAGE:latest .
|
|
# - docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_TAG
|
|
# - docker push $CI_REGISTRY_IMAGE:latest
|
|
only:
|
|
- master
|
|
- tags
|