Skip to content

Instantly share code, notes, and snippets.

@guerzon
Created September 4, 2020 08:19
Show Gist options
  • Save guerzon/3844df5399b28493136c940e0b5fbecd to your computer and use it in GitHub Desktop.
Save guerzon/3844df5399b28493136c940e0b5fbecd to your computer and use it in GitHub Desktop.
Configuration file for a Docker gitlab runner
concurrent = 10
check_interval = 0
[session_server]
session_timeout = 1800
[[runners]]
name = "Docker runner"
url = "https://gitlab.localdomain.local/"
token = "tOkeNh3r3-"
executor = "docker"
[runners.custom_build_dir]
[runners.cache]
[runners.cache.s3]
[runners.cache.gcs]
[runners.docker]
tls_verify = false
image = "docker:19.03.12"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
@fgiudici95
Copy link

Hi,
I have a question: how do you manage to use docker commands with a gitlab runner with docker as executor?

@guerzon
Copy link
Author

guerzon commented Sep 7, 2020

Hello,

Here is a stripped-down version of my .gitlab-ci.yml:

image: docker:19.03.12

variables:
  DOCKER_HOST: tcp://docker:2375/
  DOCKER_DRIVER: overlay2
  DOCKER_TLS_CERTDIR: ""
  REPO_NAME: "webapp"
  REGION: "ap-southeast-1"

services:
  - name: docker:19.03.12-dind
    entrypoint: ["env", "-u", "DOCKER_HOST"]
    command: ["dockerd-entrypoint.sh"]

stages:
  - build

build:
  stage: build
  script:
    - apk add --no-cache python3 py-pip
    - pip install awscli
    - $(aws ecr get-login --no-include-email --region "${REGION}")
    - echo "Building image for ${CI_COMMIT_TAG}"
    - docker build -t ${REPO_REGISTRY_URL}/${REPO_NAME}:${CI_COMMIT_TAG} -t ${REPO_REGISTRY_URL}/${REPO_NAME}:latest .
    - echo "Pushing image..."
    - docker push ${REPO_REGISTRY_URL}/${REPO_NAME}:${CI_COMMIT_TAG}
    - docker push ${REPO_REGISTRY_URL}/${REPO_NAME}:latest

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment