Skip to content

Instantly share code, notes, and snippets.

@thomasleveil
Last active March 6, 2019 21:27
Show Gist options
  • Save thomasleveil/d65b41db149c497e778e66586a80c31c to your computer and use it in GitHub Desktop.
Save thomasleveil/d65b41db149c497e778e66586a80c31c to your computer and use it in GitHub Desktop.
Gitlab CI config for building Dockerfile
image: dockergit:latest
before_script:
- docker version
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
stages:
- build
#- test
- publish
docker-build:
stage: build
script:
- docker pull "$CI_REGISTRY_IMAGE:latest" ||true
- docker build
--cache-from "$CI_REGISTRY_IMAGE:latest"
--label org.label-schema.schema-version="1.0"
--label org.label-schema.vcs-url=$CI_PROJECT_URL
--label org.label-schema.vcs-ref=$CI_COMMIT_SHA
--label org.label-schema.version=$(git describe --tags)
--label org.label-schema.build-date=$(date -u +"%Y-%m-%dT%H:%M:%S.%2NZ")
--label org.label-schema.vendor="My company"
--label org.label-schema.name="My project name"
-t "$CI_PROJECT_NAME:${CI_COMMIT_SHA}-${CI_PIPELINE_IID}"
.
docker-publish:
stage: publish
script:
- docker tag "$CI_PROJECT_NAME:${CI_COMMIT_SHA}-${CI_PIPELINE_IID}" "$CI_REGISTRY_IMAGE:latest"
- docker tag "$CI_PROJECT_NAME:${CI_COMMIT_SHA}-${CI_PIPELINE_IID}" "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"
- docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker push "$CI_REGISTRY_IMAGE:latest"
- docker push "$CI_REGISTRY_IMAGE:$CI_COMMIT_REF_NAME"
# Gitlab CI Runner conf
concurrent = 4
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "my runner name"
url = "https://gitlab.com"
token = "xxxxxxxxxxxxxxxxxxxxxxxx"
executor = "docker"
[runners.docker]
tls_verify = false
image = "ubuntu:xenial"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]
shm_size = 0
network_mode = "host"
[runners.cache]
# deploy a Gitlab CI Runner
version: '3'
services:
runner:
image: gitlab/gitlab-runner@sha256:c0cca9c7c2352aaa78546614b1fc5501bf56e962601f5700c7703fa5882eaf88
restart: always
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ./config:/etc/gitlab-runner
healthcheck:
test: pgrep -c gitlab-runner
# docker build -t dockergit .
FROM docker:stable
RUN apk add git
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment