1

我正在尝试将源打包为图像并由 Google Cloud Build 构建

这是我的码头文件:

FROM php
RUN cd ~ && curl -sS https://getcomposer.org/installer -o composer-setup.php
RUN cd ~ && php composer-setup.php --install-dir=/usr/local/bin --filename=composer
ADD ./mysource /app
WORKDIR /app
RUN cd /app && composer update --ignore-platform-reqs && composer install --ignore-platform-reqs
RUN cd /app && composer require laravel/horizon && php artisan vendor:publish --provider="Laravel\Horizon\HorizonServiceProvider"

结果构建失败并且日志显示:(顶部的最新日志)

Step #1: 
ERROR: build step 1 "gcr.io/cloud-builders/docker" failed: exit status 1
Finished Step #1
Step #1: The command '/bin/sh -c cd /app && composer update --ignore-platform-reqs && composer install --ignore-platform-reqs' returned a non-zero code: 1
Step #1: Script @php artisan package:discover handling the post-autoload-dump event returned with error code 1
Step #1: SQLSTATE[HY000] [2002] Connection refused 
Step #1: In PDOConnection.php line 46:
Step #1: SQLSTATE[HY000] [2002] Connection refused 
Step #1: In PDOConnection.php line 50:
Step #1: chema.tables where table_schema = forge and table_name = explorers) 
Step #1: SQLSTATE[HY000] [2002] Connection refused (SQL: select * from information_s 
Step #1: 
Step #1: In Connection.php line 664:
Step #1: 
Step #1: > @php artisan package:discover
Step #1: > Illuminate\Foundation\ComposerScripts::postAutoloadDump
Step #1: Generating optimized autoload files

我正在寻找类似bitbucket 管道中的服务,您可以在构建过程中使用它。我也提到了这里提出的问题,但这些回应并没有解决我的情况。

感谢任何想法

4

2 回答 2

0

根据https://github.com/GoogleCloudPlatform/community/issues/351#issuecomment-370056462

不幸的是,在构建阶段,CloudSQL 连接不可用。

于 2019-06-28T18:48:38.240 回答
0

只想为我的解决方案发布更新。结果我添加了一个 MySQL 容器并创建了一个特定的网络,并在所有其他步骤(容器)中指定了名称 --network <network_name>,因此以下步骤中的容器可以通过 mysql 容器的名称直接连接。

为了安全起见,我添加了一个容器作为缓冲区,以确保 mysql 容器有足够的时间来构建和构建。

steps:
- name: 'gcr.io/cloud-builders/docker'
  args: ['network','create','gcb_network']
- name: 'gcr.io/cloud-builders/docker'
  args: ['run','--name=mysql','-p','3306:3306','--network','gcb_network','--env','MYSQL_USER=<user>','--env','MYSQL_PASSWORD=<pwd>','--env','MYSQL_ROOT_PASSWORD=<user>','--env','MYSQL_DATABASE=<dbname>','-d','mysql/mysql-server:5.7']
- name: 'ubuntu'
  args: ['sleep','10']
  id: 'MYSQLDeferrer'
- name: 'gcr.io/cloud-builders/docker'
  args: ['build', '-t', 'gcr.io/<projectname>/<img_name>:latest','--network','gcb_network','-f','<path_to_docker_file>','.']
  waitFor:
    - 'MYSQLDeferrer'
  env:
  - 'DB_HOST='
  - 'DB_USERNAME='
  - 'DB_PASSWORD='
images: ['gcr.io/<projectname>/<img_name>']

根据您的设置,您可能/可能不需要环境。

于 2019-07-15T23:23:34.913 回答