如何在不同的构建阶段之间保留MySQL数据?
我已经将MysqL设置为服务,但是,从构建到部署阶段时,MysqL数据库为空,因此我无法找到任何信息.
示例gitlab-ci.yml:
image: PHP:latest
services:
- MysqL:5.6
stages:
- build
- deploy
build:
stage: build
script:
- [INSERT MysqL DATA]
allow_failure: false
artifacts:
when: on_success
paths:
- /var/lib/MysqL/
deploy:
stage: deploy
script:
- [MysqL DUMP]
dependencies:
- build
allow_failure: false
when: on_success
尽管在构建阶段成功插入了数据,但MysqL转储将为空.
each job is run in each job is run independently of the others,
including potentially running on different machines. And the services
are run locally on each runner. There’s no way for one job to access a
service on a different runner. On GitLab.com,we even recycle the
machine after each job runs so the services would all be destroyed.
@markpundsack
尽管已经存在7个月了,但该问题目前仍未解决.从MysqL获取数据的问题也是一个问题,因为服务无法装载卷(我不相信有任何计划可以添加此功能),因此数据被卡在MysqL容器内.
因此,您可以通过以下两种方式处理此问题:
>在同一工作中进行设置和测试
>创建一个已经添加了所有数据的sql docker(不好的做法,但是如果需要的话)
>在设置中创建转储并共享为工件,然后通过测试重新加载该数据
编辑:添加一条注释,将expire_in
组件用于工件可能是有用的,因为您不想存储一堆数据,您可能永远不需要.
编辑2:
经过研究后,我找到了gitlab的this.您可以执行以下操作:
services:
- MysqL
variables:
# Configure MysqL service (https://hub.docker.com/_/MysqL/)
MysqL_DATABASE: hello_world_test
MysqL_ROOT_PASSWORD: MysqL
connect:
image: MysqL
script:
- echo "SELECT 'OK';" | MysqL --user=root --password="$MysqL_ROOT_PASSWORD" --host=MysqL "$MysqL_DATABASE"
- SOME DATABASE DUMPING
artifacts:
when: on_success
paths:
- /var/lib/MysqL/