我似乎无法在 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
所指的图像只是安装了 bash的官方docker:1.10图像。
我的构建过程包括 3 个步骤:
npm install
在官方node:5镜像中运行和测试。现在,为了测试部署,我已经离开了这一步。- 构建一个包含代码的 docker 镜像
- 使用 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
我怀疑我没有正确设置或使用跑步者,但是除了非常简单的案例之外,我在文档中找不到太多东西,而且我对该工具的了解还不够,无法知道它是如何在引擎盖下组合在一起的.