Files
reseed-tools/.gitlab-ci.yml
2020-12-28 16:08:04 +01:00

76 lines
2.9 KiB
YAML

image: docker:19.03.12
stages:
- test
- docker
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_IMAGE: "registry:5000/reseed-tools"
# CI_LOCAL_REGISTRY_USER: registry
# CI_LOCAL_REGISTRY_PASSWORD: thisismyregistry
services:
- name: docker:19.03.12-dind
command:
- --insecure-registry
- myregistry:5000
- name: registry:2
alias: registry
# Login to job registry and publish registry
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
# Make sure we can build a docker image
# It's pushed to the pipeline-local registry which acts as a cache
build_docker:
stage: test
before_script:
- apk add --no-cache curl
script:
# Make sure we can connect to the registry service
- curl http://registry:5000/v2/
- 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
script:
- docker pull $CI_LOCAL_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
push_docker:
stage: docker
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:
- tags