gpt4 book ai didi

docker - Gitlab CI 运行器配置与 docker 上的缓存

转载 作者:IT老高 更新时间:2023-10-28 21:20:47 25 4
gpt4 key购买 nike

我似乎无法在 gitlab CI 的作业之间获取缓存或工件。我怀疑这与我的配置有关,但我不确定是什么。我正在使用以下 docker-compose 配置在 docker 中运行 gitlab 和 gitlab-ci-multirunner。为简洁起见,我省略了数据库配置和一些环境变量:

version: '2'

services:
gitlab:
image: sameersbn/gitlab:8.5.1
links:
- redis:redisio
- postgresql:postgresql
ports:
- "10080:80"
- "10022:22"
environment:
...
volumes:
- gitlab_data:/home/git/data

gitlab-ci-runner:
restart: always
image: gitlab/gitlab-runner
volumes:
- gitlab_runner_config_data:/etc/gitlab-runner
- /var/run/docker.sock:/var/run/docker.sock
- /etc/nginx/ssl/gitlab.crt:/etc/gitlab-runner/certs/ca.crt
- /etc/ssh:/ssh
links:
- gitlab:gitlab

redis:
...
postgresql:
...


volumes:
postgresql_data:
redis_data:
gitlab_data:
gitlab_runner_config_data:

运行器配置(config.toml)为:

concurrent = 1

[[runners]]
name = "docker"
url = <public gitlab url>/ci
token = <gitlab token>
tls-ca-file = "/etc/gitlab-runner/certs/ca.crt"
executor = "docker"
[runners.docker]
image = "docker-bash"
volumes = ["/var/run/docker.sock:/var/run/docker.sock", "/cache"]

所指的docker-bash镜像只是官方的docker:1.10安装了 bash 的图像。

我的构建过程包括 3 个步骤:

  1. 运行npm install和官方node:5中的测试图片。目前,为了测试部署,我已经省略了这一步。
  2. 构建包含代码的 docker 镜像
  3. 使用 ansible,通过自定义构建的 ansible docker 镜像将构建的镜像部署到生产服务器。

.gitlab-ci.yml 文件如下所示:

variables:
FULL_IMAGE_TAG: deploy-$CI_BUILD_REF_NAME:$CI_BUILD_ID-$CI_BUILD_REF
IMAGE_FILE: deploy-$CI_BUILD_REF_NAME.tar.gz

cache:
paths:
- $IMAGE_FILE

build:
stage: build
script:
- docker build -t $FULL_IMAGE_TAG .
- docker save $FULL_IMAGE_TAG | gzip -cf - > $IMAGE_FILE
artifacts:
paths:
- $IMAGE_FILE

deploy:
stage: deploy
image: ansible-ssh
script:
- ls
- ansible-playbook -e image_file=$IMAGE_FILE -e branch=$CI_BUILD_REF_NAME -e full_image_name=$FULL_IMAGE_TAG deploy-playbook.yml
only:
- develop
- master

如您所见,压缩后的 docker 镜像在此处的缓存和工件部分都被引用,但实际上在部署步骤中不可用,其中 ansible 应该将其复制到远程计算机。我已经尝试包含一个 ls 命令,因此检查文件夹内容并且文件显然不存在,但它肯定是构建的,我可以从 gitlab UI 下载它。这是部署作业的日志:

gitlab-ci-multi-runner 1.0.4 (014aa8c)
Using Docker executor with image ansible-ssh ...
Pulling docker image ansible-ssh ...
WARNING: Cannot pull the latest version of image ansible-ssh : Error: image library/ansible-ssh not found
WARNING: Locally found image will be used instead.

Running on runner-59d43cf3-project-8-concurrent-0 via 381c2ea97744...
Fetching changes...
Removing artifacts.zip
Removing deploy-develop.tar.gz
HEAD is now at 6009bd0 test
Checking out 6009bd0f as develop...
HEAD is now at 6009bd0... test

$ ls
Dockerfile
deploy-playbook.yml
server
$ ansible-playbook -e image_file=$IMAGE_FILE -e branch=$CI_BUILD_REF_NAME -e full_image_name=$FULL_IMAGE_TAG deploy-playbook.yml
Using /etc/ansible/ansible.cfg as config file
1 plays in deploy-playbook.yml

PLAY ***************************************************************************

TASK [setup] *******************************************************************
ok: [deploy-host]

TASK [copy docker image] *******************************************************
task path: /builds/test/test/deploy-playbook.yml:44
fatal: [deploy-host]: FAILED! => {"changed": false, "failed": true, "msg": "could not find src=/builds/test/test/deploy-develop.tar.gz"}

NO MORE HOSTS LEFT *************************************************************
to retry, use: --limit @deploy-playbook.retry

PLAY RECAP *********************************************************************
deploy-host : ok=1 changed=0 unreachable=0 failed=1


ERROR: Build failed with: exit code 1

我怀疑我没有正确设置或使用运行者,但除了非常简单的案例之外,我在文档中找不到太多内容,而且我对该工具的了解不够充分,无法知道它是如何组合在一起的在引擎盖下。

最佳答案

缓存并非旨在在构建阶段之间传递文件。

来自 doc

cache : Define list of files that should be cached between subsequent runs

我认为您需要的实际上正在进行中:WIP: Download build artifacts from previous stages and restore them in context of the build (Technology Preview)

关于docker - Gitlab CI 运行器配置与 docker 上的缓存,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36185915/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com