Gitlab CI/CD: 新的 runner 尚未连接
Gitlab CI/CD: New runner has not been connected yet
我是 Gitlab CI/CD 的新手,我已经非常仔细地阅读了它的文档,了解如何使用 .gitlab-ci.yml
文件创建新的 CI/CD 进程。正如我发现的那样,为了 Continuous Deployment(也称为 CD),需要在我的 linux 服务器上注册一个新的 gitlab-runner。
说明
这是我的 .gitlab-ci.yml
文件:
stages:
- build
- deploy
docker-build:
image: docker:stable
services:
- docker:dind
stage: build
only:
refs:
- ci-test
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
- echo $CI_REGISTRY_IMAGE
- echo $CI_COMMIT_SHORT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
deploy:
image: docker:stable
stage: deploy
services:
- docker:dind
only:
refs:
- ci-test
when: manual
except:
changes:
- "*.md"
script:
- docker build --pull -t $CI_REGISTRY_IMAGE$CI_COMMIT_SHORT_SHA .
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
这是我的 Dockerfile:
version: '3'
services:
app:
# build: .
environment:
- DEFAULT_DATABASE_HOST=${DEFAULT_DATABASE_HOST}
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
# command: uwsgi --http :8000 --socket /socket/api.sock --chmod-socket=666 --module _base.wsgi --master --processes 5 --threads 2
command: uwsgi --http :8000 --module _base.wsgi --master --processes 5 --threads 2
# command: python manage.py runserver 0.0.0.0:8000
depends_on:
- redis
ports:
- 8000:8000
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
restart: on-failure
network_mode: host
redis:
image: redis:6.0-alpine
volumes:
- /var/lib/redis/redis.dump:
ports:
- 6379:6379
#
celery-beat:
environment:
- DEFAULT_DATABASE_HOST=${DEFAULT_DATABASE_HOST}
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
command: celery -A _base beat -l info
depends_on:
- redis
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
celery-worker-default:
environment:
- DEFAULT_DATABASE_HOST=172.17.0.1
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
command: celery -A _base worker -l INFO -Q clearsight-default --concurrency 1 -n clearsight-default
depends_on:
- redis
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
celery-worker-aws:
environment:
- DEFAULT_DATABASE_HOST=172.17.0.1
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
command: celery -A _base worker -l INFO -Q clearsight-aws --concurrency 1 -n clearsight-default
depends_on:
- redis
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
watchtower:
image: containrrr/watchtower:1.3.0
container_name: watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ~/.docker/config.json:/config.json
restart: always
command: --interval 60
问题
我已经尝试了 CI 管道,它与共享运行器一起正常工作:
所以,我认为CI方面没有任何问题。因此,我在服务器中注册了一个新的 gitlab-runner
(docker+machine) 并且可以在存储库 CI/CD runners 中看到它,但是如下图所示,它未连接!
问题如何解决运行器问题并使运行器连接到作业?
在 运行 执行 gitlab-runner verify
命令后问题已解决。
~ ➤ gitlab-runner -h # shows the help and other commands of gitlab-runner
NAME:
gitlab-runner - a GitLab Runner
USAGE:
gitlab-runner [global options] command [command options] [arguments...]
VERSION:
13.11.0 (7f7a4bb0)
AUTHOR:
GitLab Inc. <support@gitlab.com>
COMMANDS:
exec execute a build locally
list List all configured runners
run run multi runner service
register register a new runner
install install service
uninstall uninstall service
start start service
stop stop service
restart restart service
status get status of a service
run-single start single runner
unregister unregister specific runner
verify verify all registered runners
artifacts-downloader download and extract build artifacts (internal)
artifacts-uploader create and upload build artifacts (internal)
cache-archiver create and upload cache artifacts (internal)
cache-extractor download and extract cache artifacts (internal)
cache-init changed permissions for cache paths (internal)
health-check check health for a specific address
read-logs reads job logs from a file, used by kubernetes executor (internal)
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--cpuprofile value write cpu profile to file [$CPU_PROFILE]
--debug debug mode [$DEBUG]
--log-format value Choose log format (options: runner, text, json) [$LOG_FORMAT]
--log-level value, -l value Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
--help, -h show help
--version, -v print the version
现在可以正常工作了:
感谢@WytrzymałyWiktor 对 this post 的评论。除了他的评论,我没有发现任何有用的东西。
P.S执行完以上步骤后,您可能需要运行gitlab-runner start
才能解决您的问题!
对于那些在 Docker 下使用 GitLab Runner 的人。使用上面@MostafaGhadimi 提供的等效命令来验证您的新实例:
docker exec <container name> /bin/sh -c "gitlab-runner verify"
对我来说 sudo gitlab-runner verify
有效。第二个要执行的命令是 sudo gitlab-runner run
。对于自定义runner,手动执行runner很重要。
我是 Gitlab CI/CD 的新手,我已经非常仔细地阅读了它的文档,了解如何使用 .gitlab-ci.yml
文件创建新的 CI/CD 进程。正如我发现的那样,为了 Continuous Deployment(也称为 CD),需要在我的 linux 服务器上注册一个新的 gitlab-runner。
说明
这是我的 .gitlab-ci.yml
文件:
stages:
- build
- deploy
docker-build:
image: docker:stable
services:
- docker:dind
stage: build
only:
refs:
- ci-test
before_script:
- docker login -u $CI_REGISTRY_USER -p $CI_REGISTRY_PASSWORD $CI_REGISTRY
script:
- docker build --pull -t $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA .
- echo $CI_REGISTRY_IMAGE
- echo $CI_COMMIT_SHORT_SHA
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
deploy:
image: docker:stable
stage: deploy
services:
- docker:dind
only:
refs:
- ci-test
when: manual
except:
changes:
- "*.md"
script:
- docker build --pull -t $CI_REGISTRY_IMAGE$CI_COMMIT_SHORT_SHA .
- docker tag $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA $CI_REGISTRY_IMAGE:latest
- docker push $CI_REGISTRY_IMAGE:$CI_COMMIT_SHORT_SHA
- docker push $CI_REGISTRY_IMAGE:latest
这是我的 Dockerfile:
version: '3'
services:
app:
# build: .
environment:
- DEFAULT_DATABASE_HOST=${DEFAULT_DATABASE_HOST}
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
# command: uwsgi --http :8000 --socket /socket/api.sock --chmod-socket=666 --module _base.wsgi --master --processes 5 --threads 2
command: uwsgi --http :8000 --module _base.wsgi --master --processes 5 --threads 2
# command: python manage.py runserver 0.0.0.0:8000
depends_on:
- redis
ports:
- 8000:8000
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
restart: on-failure
network_mode: host
redis:
image: redis:6.0-alpine
volumes:
- /var/lib/redis/redis.dump:
ports:
- 6379:6379
#
celery-beat:
environment:
- DEFAULT_DATABASE_HOST=${DEFAULT_DATABASE_HOST}
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
command: celery -A _base beat -l info
depends_on:
- redis
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
celery-worker-default:
environment:
- DEFAULT_DATABASE_HOST=172.17.0.1
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
command: celery -A _base worker -l INFO -Q clearsight-default --concurrency 1 -n clearsight-default
depends_on:
- redis
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
celery-worker-aws:
environment:
- DEFAULT_DATABASE_HOST=172.17.0.1
- DEFAULT_DATABASE_NAME=${DEFAULT_DATABASE_NAME}
- DEFAULT_DATABASE_USER=${DEFAULT_DATABASE_USER}
- DEFAULT_DATABASE_PASSWORD=${DEFAULT_DATABASE_PASSWORD}
- DEBUG=${DEBUG}
- DJANGO_SETTINGS_MODULE=_base.settings
- CELERY_BROKER_URL=redis://redis:6379/0
command: celery -A _base worker -l INFO -Q clearsight-aws --concurrency 1 -n clearsight-default
depends_on:
- redis
image: ${CLEARSIGHT_IMAGE_NAME}:${CLEARSIGHT_IMAGE_TAG}
watchtower:
image: containrrr/watchtower:1.3.0
container_name: watchtower
volumes:
- /var/run/docker.sock:/var/run/docker.sock
- ~/.docker/config.json:/config.json
restart: always
command: --interval 60
问题 我已经尝试了 CI 管道,它与共享运行器一起正常工作:
所以,我认为CI方面没有任何问题。因此,我在服务器中注册了一个新的 gitlab-runner
(docker+machine) 并且可以在存储库 CI/CD runners 中看到它,但是如下图所示,它未连接!
问题如何解决运行器问题并使运行器连接到作业?
在 运行 执行 gitlab-runner verify
命令后问题已解决。
~ ➤ gitlab-runner -h # shows the help and other commands of gitlab-runner
NAME:
gitlab-runner - a GitLab Runner
USAGE:
gitlab-runner [global options] command [command options] [arguments...]
VERSION:
13.11.0 (7f7a4bb0)
AUTHOR:
GitLab Inc. <support@gitlab.com>
COMMANDS:
exec execute a build locally
list List all configured runners
run run multi runner service
register register a new runner
install install service
uninstall uninstall service
start start service
stop stop service
restart restart service
status get status of a service
run-single start single runner
unregister unregister specific runner
verify verify all registered runners
artifacts-downloader download and extract build artifacts (internal)
artifacts-uploader create and upload build artifacts (internal)
cache-archiver create and upload cache artifacts (internal)
cache-extractor download and extract cache artifacts (internal)
cache-init changed permissions for cache paths (internal)
health-check check health for a specific address
read-logs reads job logs from a file, used by kubernetes executor (internal)
help, h Shows a list of commands or help for one command
GLOBAL OPTIONS:
--cpuprofile value write cpu profile to file [$CPU_PROFILE]
--debug debug mode [$DEBUG]
--log-format value Choose log format (options: runner, text, json) [$LOG_FORMAT]
--log-level value, -l value Log level (options: debug, info, warn, error, fatal, panic) [$LOG_LEVEL]
--help, -h show help
--version, -v print the version
现在可以正常工作了:
感谢@WytrzymałyWiktor 对 this post 的评论。除了他的评论,我没有发现任何有用的东西。
P.S执行完以上步骤后,您可能需要运行gitlab-runner start
才能解决您的问题!
对于那些在 Docker 下使用 GitLab Runner 的人。使用上面@MostafaGhadimi 提供的等效命令来验证您的新实例:
docker exec <container name> /bin/sh -c "gitlab-runner verify"
对我来说 sudo gitlab-runner verify
有效。第二个要执行的命令是 sudo gitlab-runner run
。对于自定义runner,手动执行runner很重要。