最近在公司搭建了一个新版的 gitlab,用到了新的 gitlab docker runner。
配置后端项目自动部署时踩了很多坑。特别 runner 在 docker in docker 中,需要单独挂载一个目录来存放源码。
最终还是用 Shell Executor 完成构建,Docker Executor 也一样。
看到 https://gitlab.com/gitlab-org/gitlab-ce/issues/41227 有所启发。
附上配置文件:
.gitlab-ci.yml
:
image: name: docker/compose:1.24.1 # update tag to whatever version you want to use. entrypoint: ["/bin/sh", "-c"] variables: DOCKER_DRIVER: overlay SHARED_PATH: /builds/$CI_PROJECT_PATH services: - docker:dind stages: - build before_script: # 定义在 job 执行之前的执行脚本 - echo "hello gitlab ci" - docker info - docker-compose --version job_dev: only: - dev stage: build script: - pwd - ls -al - mv -f docker-compose-ci.yml docker-compose.yml - cat "$CONFIG_INI" > "$(pwd)/app/config/config.ini" - mkdir -p ${SHARED_PATH} - cp -r ./* ${SHARED_PATH} - docker-compose build - docker-compose up --remove-orphans --no-deps -d
docker-compose-ci.yml
:
version: '3' services: web: build: context: . dockerfile: docker/python/Dockerfile image: 'tianji-api:0.1.0' ports: - '5048:6000' volumes: - /builds/tianji/web-api:/code/:rw environment: - BOILERPLATE_ENV=dev # dev scheduler: build: context: . dockerfile: docker/APScheduler/Dockerfile image: 'tianji-api-ap-scheduler:0.1.0' volumes: - /builds/tianji/web-api:/code/:rw
Gitlab Runner
:
config.toml
concurrent = 1 check_interval = 0 [session_server] session_timeout = 1800 [[runners]] name = "hz-test" url = "http://git.xxx.com/" token = "xxx" executor = "docker" [runners.custom_build_dir] [runners.docker] tls_verify = false image = "gitlab/dind:latest" privileged = true disable_entrypoint_overwrite = false oom_kill_disable = false disable_cache = false volumes = [ "/var/run/docker.sock:/var/run/docker.sock:rw", "/builds:/builds:rw", "/cache" ] shm_size = 0 [runners.cache] [runners.cache.s3] [runners.cache.gcs] [runners.custom] run_exec = "" [[runners]] name = "ubuntu-hz-shell" url = "http://git.xxx.com/" token = "xxx" executor = "shell" [runners.custom_build_dir] [runners.cache] [runners.cache.s3] [runners.cache.gcs] [runners.custom] run_exec = ""