标签:runner 相关 editing template restore rac date 调试 ted
docker in docker
的方式,即在具有特权模式的 Docker 中使用 Docker,通过 gitlab-runner 使用 docker 的来构建项目,完成打包,测试,发布等任务。这样 gitlab-runner 只是需要 Dockerfile 即可,可方便日后使用其他 CI/CD 工具。同时本地调试也十分方便docker run -d --name gitlab-runner --restart always -v /srv/gitlab-runner/config:/etc/gitlab-runner -v /var/run/docker.sock:/var/run/docker.sock gitlab/gitlab-runner:latest
docker exec -it gitlab-runner bash
gitlab-runner register
进行注册,按照提示和文档说明一步步填写即可sudo gitlab-runner register --non-interactive --url "https://gitlab.com/" --registration-token "PROJECT_REGISTRATION_TOKEN" --executor "docker" --docker-image alpine:latest --description "docker-runner" --tag-list "docker,aws" --run-untagged="true" --locked="false" --access-level="not_protected"
/etc/gitlab-runner/config.toml
中添加 privileged 标记,这样可以在容器中使用 docker 的一些功能[[runners]]
executor = "docker"
[runners.docker]
privileged = true
[[runners]]
name = "docker-runner"
url = "http://192.168.99.100:8900/"
token = "zLBu8yXEFPGKaaasZopn"
executor = "docker"
clone_url = "http://192.168.99.100:8900/"
[runners.custom_build_dir]
[runners.docker]
tls_verify = false
image = "apline:latest"
privileged = true
disable_entrypoint_overwrite = false
oom_kill_disable = false
disable_cache = false
volumes = ["/cache"]
shm_size = 0
在.gitlab-ci.yml
文件中使用方式
Shell | Usage |
---|---|
bash/sh | $variable |
windows batch | %variable% |
PowerShell | $env:variable |
Dockerfile 中使用变量参考:https://docs.docker.com/engine/reference/builder/#arg
FROM mcr.microsoft.com/dotnet/core/sdk:2.2-stretch
ARG AppKey
ARG Source
WORKDIR /src
COPY ["A1/A1.csproj", "A1/"]
RUN dotnet restore "A1/A1.csproj"
COPY . .
WORKDIR /src/A1
RUN dotnet pack "A1" -c Release -o /app
WORKDIR /app
RUN dotnet nuget push *.nupkg -k ${AppKey} -s ${Source}
# This file is a template, and might need editing before it works on your project.
build-master:
# Official docker image.
image: docker:latest
stage: build
services:
- docker:dind
before_script:
# - docker login -u "$CI_REGISTRY_USER" -p "$CI_REGISTRY_PASSWORD" $CI_REGISTRY
- docker --version
- echo $NugetAppKey
- echo $NugetSource
script:
- docker build --build-arg AppKey=$NugetAppKey --build-arg Source=$NugetSource -t A1:latest .
only:
- master
time="2019-07-19T01:20:27Z" level=error msg="failed to dial gRPC: cannot connect to the Docker daemon. Is ‘docker daemon‘ running on this host?: dial tcp: lookup docker on 100.100.2.136:53: no such host"
,这个需要配置 runner,让容器跑在privileged
模式,参考 https://docs.gitlab.com/runner/executors/docker.html#use-docker-in-docker-with-privileged-modeclone_url
。文档:https://docs.gitlab.com/runner/configuration/advanced-configuration.html#the-runners-section 示例:[[runners]]
name = "ruby-2.1-docker"
url = "https://CI/"
token = "TOKEN"
limit = 0
executor = "docker"
builds_dir = ""
shell = ""
environment = ["ENV=value", "LC_ALL=en_US.UTF-8"]
clone_url = "http://gitlab.example.local"
标签:runner 相关 editing template restore rac date 调试 ted
原文地址:https://www.cnblogs.com/xxred/p/11548251.html