首页 > 解决方案 > 无法在谷歌云构建上正确初始化 mysql db(使用 docker-compose)

问题描述

我目前正在使用 Google Cloud Build(并使用 测试cloud-build-local)为我的应用程序(django)设置构建/测试管道。

为了正确运行测试,我需要启动一个 mysql 依赖项(我docker-compose用于此)。问题是docker-compose在云构建步骤中运行时,数据库初始化脚本没有正确运行,我得到一个

/usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/0-init.sql
ERROR: Can't initialize batch_readline - may be the input source is a directory or a block device.

(从 google-cloud-build 运行 docker-compose 正常工作)

这是我的 docker-compose 文件:

version: '3.3'
services:
  mysql:
    image: mysql:5.7
    restart: always
    environment:
      MYSQL_DATABASE: 'dev'
      MYSQL_USER: 'dev'
      MYSQL_PASSWORD: 'dev'
      MYSQL_ROOT_PASSWORD: 'root'
    ports:
      - '3306:3306'
    expose:
      - '3306'
    volumes:
      - reports-db:/var/lib/mysql-reports
      - ./dev/databases/init.sql:/docker-entrypoint-initdb.d/0-init.sql
      - ... (other init scripts) 
volumes:
  reports-db:

并且cloudbuild.yaml

steps:
...
- id: 'tests-dependencies'
  name: 'docker/compose:1.24.1'
  args: ['up', '-d']
...

文件组织如下:

parent_dir/
   dev/
      databases/
         init.sql
   cloudbuild.yaml
   docker-compose.yml
   ...

(所有命令都从 运行parent_dir/

当我跑

cloud-build-local --config=cloudbuild.yaml --dryrun=false .

我得到一个

...
Step #2 - "tests-dependencies": mysql_1  | /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/0-init.sql
Step #2 - "tests-dependencies": mysql_1  | ERROR: Can't initialize batch_readline - may be the input source is a directory or a block device.
...

知道docker-compose up直接运行正常

我怀疑卷的安装方式不正确,但找不到原因/方式。

如果有人对此有任何意见,那将非常有用:)

提前致谢。

标签: google-cloud-platformdocker-composegoogle-cloud-build

解决方案


看起来这是一个问题cloud-build-local,在 GCP 上正常工作


推荐阅读