【发布时间】:2021-07-18 13:27:14
【问题描述】:
我一直在尝试在 aws 上使用 docker runner 设置 gitlab ci。我设法让 runner 最终与 gitlab 合作。我遇到的问题是在构建阶段。我在构建阶段不断出错。 error during connect: Post http://docker:2375/v1.40/auth: dial tcp: lookup docker on 172.31.0.2:53: no such host 我正在尝试构建一个 python django 应用程序。如果我使用共享运行器,则整个过程都可以正常工作,并且我可以在容器注册表中看到新图像。
这是我的 gitlab-ci.yaml
image: python:latest
services:
- name: docker:dind
entrypoint: ["env", "-u", "DOCKER_HOST"]
command: ["dockerd-entrypoint.sh"]
stages:
- test
- compile
- build
- deploy
variables:
DOCKER_HOST: tcp://docker:2375
DOCKER_DRIVER: overlay2
DOCKER_TLS_CERTDIR: ""
MOUNT_POINT: /builds/$CI_PROJECT_PATH/mnt
before_script:
- docker info
- export IMAGE=$CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
- export WEB_IMAGE=$IMAGE:web
- export NGINX_IMAGE=$IMAGE:nginx
- apk add --no-cache openssh-client bash
- chmod +x ./setup_env.sh
- bash ./setup_env.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
unittests:
stage: test
before_script:
- python -m pip install --upgrade pip
- pip install -r app/pipeline-requirements.txt
script:
- python app/manage.py jenkins --enable-coverage
artifacts:
reports:
junit: app/reports/junit.xml
paths:
- "app/reports/*.xml"
expire_in: 30 days
when: on_success
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "qa"
migrations:
stage: compile
before_script:
- pip install -r app/pipeline-requirements.txt
script:
- python app/manage.py makemigrations
artifacts:
paths:
- "app/*/migrations/*.py"
expire_in: 1 day
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "qa"
build:
image:
name: docker/compose:1.25.4
entrypoint: [ "" ]
stage: build
before_script:
- export IMAGE=$CI_REGISTRY/$CI_PROJECT_NAMESPACE/$CI_PROJECT_NAME
- export WEB_IMAGE=$IMAGE:web
- export NGINX_IMAGE=$IMAGE:nginx
script:
- apk add --no-cache bash
- chmod +x ./setup_env.sh
- bash ./setup_env.sh
- docker login -u $CI_REGISTRY_USER -p $CI_JOB_TOKEN $CI_REGISTRY
- docker pull $IMAGE:web || true
- docker pull $IMAGE:nginx || true
- docker-compose -f docker-compose.ci.yml build
- docker push $IMAGE:web
- docker push $IMAGE:nginx
dependencies:
- migrations
only:
refs:
- merge_requests
variables:
- $CI_MERGE_REQUEST_TARGET_BRANCH_NAME == "qa"
config.toml
concurrent = 1
check_interval = 10
log_level = "debug"
[session_server]
session_timeout = 1800
[[runners]]
name = "aws-qa"
url = "https://gitlab.com/"
token = "xxx"
executor = "docker+machine"
listen_address="pipelines.domain.digital:8043"
limit = 10
pre_build_script = "export DOCKER_HOST=tcp://docker:2375"
environment = ["DOCKER_DRIVER=overlay2", "DOCKER_TLS_CERTDIR="]
[runners.custom_build_dir]
[runners.cache]
Type = "s3"
Shared = true
[runners.cache.s3]
ServerAddress = "s3.amazonaws.com"
AccessKey = "xxx"
SecretKey = "xxx"
BucketName = "domain-gitlab-runner"
BucketLocation = "eu-west-2"
[runners.cache.gcs]
[runners.cache.azure]
[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
tls_cert_path = ""
[runners.machine]
IdleCount = 0
MachineDriver = "amazonec2"
MachineName = "gitlab-docker-machine-%s"
MaxGrowthRate = 2
IdleTime = 60
MachineOptions = [
"amazonec2-access-key=xxx",
"amazonec2-secret-key=xxx",
"amazonec2-region=eu-west-2",
"amazonec2-vpc-id=vpc-xxx",
"amazonec2-subnet-id=subnet-xxx",
"amazonec2-zone=a",
"amazonec2-use-private-address=true",
"amazonec2-tags=runner-manager-name,gitlab-aws-autoscaler,gitlab,true,gitlab-runner-autoscale,true,project,pipelines",
"amazonec2-security-group=gitlab-loadbalancer-sec-group",
"amazonec2-instance-type=m4.2xlarge",
]
[[runners.machine.autoscaling]]
Periods = ["* * 9-17 * * mon-fri *"]
IdleCount = 2
IdleTime = 60
Timezone = "UTC"
[[runners.machine.autoscaling]]
Periods = ["* * * * * sat,sun *"]
IdleCount = 0
IdleTime = 60
Timezone = "UTC"
【问题讨论】:
标签: amazon-web-services gitlab-ci gitlab-ci-runner