当前位置: 首页 > 知识库问答 >
问题:

如何使用带有构建触发器的容器注册表灵活地自动部署google app engine

向杜吟
2023-03-14

我在用GitHub保存我的项目。使用PHP storm,我将我的脚本推到GitHub Repo。

<?php

Echo 'this is sample project';

?>
runtime: php
env: flex

runtime_config:
 document_root: web

manual_scaling:
 instances: 1

handlers:

- url: .*
 script: index.php

composer.json

{
   "require": {
       "php": "7.1.*"
   }
}

Dockerfile

# Docker: Google App Engine

FROM gcr.io/google-appengine/php

使用Google云平台容器注册表构建触发器。创建了一个构建触发器。我拿到了下面的日志

starting build "4d51b494-5f7d-48e5-a2a2-6d7d6a9318a9"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/project-id/r/github-test
* branch 5f9ac268123a3cfef5876034f2933eb83b34cd6d -> FETCH_HEAD
HEAD is now at 5f9ac26 v 1
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
Sending build context to Docker daemon 87.04kB

Step 1/1 : FROM gcr.io/google-appengine/php
latest: Pulling from google-appengine/php
Digest: sha256:578584d281828af48df03b85dcdcfd5792e8eb2916567497b56468b
Status: Downloaded newer image for gcr.io/google-appengine/php:latest
[91m# Executing 3 build triggers...
[0mStep 1/1 : COPY . $APP_DIR
Step 1/1 : RUN chown -R www-data.www-data $APP_DIR
---> Running in c9d98191fa2b
Step 1/1 : RUN /build-scripts/composer.sh
---> Running in ec2b02e5f0d1
[91m+ DEFAULT_PHP_VERSION=7.1
+ '[' -f /app/composer.json ']'
[0m[91m+ '[' -n '' ']'
+ CMD='php /build-scripts/detect_php_version.php /app/composer.json'
[0m[91m++ su www-data -c 'php /build-scripts/detect_php_version.php /app/composer.json'
[0mPHP_VERSION: 7.1
[91m+ PHP_VERSION=7.1
+ echo 'PHP_VERSION: 7.1'
+ '[' 7.1 == exact ']'
+ '[' 7.1 '!=' 5.6 ']'
+ '[' 7.1 '!=' 7.0 ']'
+ '[' 7.1 '!=' 7.1 ']'
+ '[' 7.1 == 5.6 ']'
+ '[' 7.1 == 7.0 ']'
+ COMPOSER_GITHUB_OAUTH_TOKEN=
+ [[ -n '' ]]
+ unset COMPOSER_GITHUB_OAUTH_TOKEN
+ rm -rf /app/vendor
[0m[91m+ php -d auto_prepend_file= /build-scripts/install_extensions.php /app/composer.json /opt/php/lib/conf.d/extensions.ini 7.1
[0m[91m+ '[' -n '' ']'
+ NOSCRIPT=--no-scripts
+ cd /app
+ su -m www-data -c 'php -d auto_prepend_file='\'''\'' /usr/local/bin/composer install --no-scripts --no-dev --prefer-dist --optimize-autoloader --no-interaction --no-ansi --no-progress'
[0m[91mLoading composer repositories with package information
[0m[91mUpdating dependencies
[0m[91mNothing to install or update
[0m[91mWriting lock file
Generating optimized autoload files
[0m ---> 1c5b266fe5ef
Removing intermediate container 473f7595359f
Removing intermediate container c9d98191fa2b
Removing intermediate container ec2b02e5f0d1
Successfully built 1c5b266fe5ef
Successfully tagged gcr.io/project-id/github-test:5f9ac268123a3cfef5876034f2933eb83b34cd6d
PUSH
Pushing gcr.io/project-id/github-test:5f9ac268123a3cfef5876034f2933eb83b34cd6d
The push refers to a repository [gcr.io/project-id/github-test]
09e0b63e8b63: Preparing
9ab9de3bae7c: Preparing
7ca730235cb1: Preparing
bca74f739283: Preparing
83430675961e: Preparing
c4b086b9d099: Preparing
acf227e1b2a5: Preparing
40de2f738e9e: Preparing
0ef981ddb200: Preparing
73acc0dfea4b: Preparing
825db9ad6441: Preparing
23088c61aa93: Preparing
122586f0e47f: Preparing
357a1f7d4b42: Preparing
d7fe08acdf1d: Preparing
cd1b43d6d268: Preparing
23b7338cf1fe: Preparing
9301d4a8f319: Preparing
2126b271c428: Preparing
c4b086b9d099: Waiting
acf227e1b2a5: Waiting
40de2f738e9e: Waiting
0ef981ddb200: Waiting
73acc0dfea4b: Waiting
825db9ad6441: Waiting
23088c61aa93: Waiting
122586f0e47f: Waiting
357a1f7d4b42: Waiting
d7fe08acdf1d: Waiting
cd1b43d6d268: Waiting
23b7338cf1fe: Waiting
9301d4a8f319: Waiting
2126b271c428: Waiting
83430675961e: Layer already exists
bca74f739283: Layer already exists
c4b086b9d099: Layer already exists
40de2f738e9e: Layer already exists
acf227e1b2a5: Layer already exists
0ef981ddb200: Layer already exists
73acc0dfea4b: Layer already exists
825db9ad6441: Layer already exists
122586f0e47f: Layer already exists
23088c61aa93: Layer already exists
357a1f7d4b42: Layer already exists
d7fe08acdf1d: Layer already exists
cd1b43d6d268: Layer already exists
23b7338cf1fe: Layer already exists
9301d4a8f319: Layer already exists
2126b271c428: Layer already exists
09e0b63e8b63: Pushed
7ca730235cb1: Pushed
9ab9de3bae7c: Pushed
5f9ac268123a3cfef5876034f2933eb83b34cd6d: digest: sha256:c604792b8b384e1186b55d11a1d04e8e06051e3f3083c25bd13668dcf size: 4285
DONE
 # Docker: Google App Engine
   FROM gcr.io/google-appengine/php
   gcloud app deploy -image-url=gcr.io/project-id/github-test
starting build "43508598-4542-4e1c-a9e7-d29343878202"

FETCHSOURCE
Initialized empty Git repository in /workspace/.git/
From https://source.developers.google.com/p/project-id/r/github-test
* branch ea7511b88ad5c59736037c37685ea699b5c0 -> FETCH_HEAD
HEAD is now at ea7511b v 1
BUILD
Already have image (with digest): gcr.io/cloud-builders/docker
Sending build context to Docker daemon 87.04kB

Error response from daemon: Dockerfile parse error line 7: Unknown instruction: GCLOUD
ERROR
ERROR: build step "gcr.io/cloud-builders/docker@sha256:59e98ecdfe9229f080085953611ffb708a0df5b7f37a253ec" failed: exit status 1

共有1个答案

麻学博
2023-03-14

尝试一个cloudbuild.yaml文件,如下所示:

steps:
# Build the Docker image.
- name: gcr.io/cloud-builders/docker
  args: ['build', '-t', 'gcr.io/$PROJECT_ID/app', '.']
# Push it to GCR.
- name: gcr.io/cloud-builders/docker
  args: ['push', 'gcr.io/$PROJECT_ID/app']
# Deploy your Flex app from the image in GCR.
- name: gcr.io/cloud-builders/gcloud
  args: ['app', 'deploy', 'app.yaml', '--image-url=gcr.io/$PROJECT_ID/app']
# Note that this build pushes this image.
images: ['gcr.io/$PROJECT_ID/app']

将此文件添加到您的存储库中,并配置一个构建触发器,当您推到分支时,该触发器将执行该文件。

 类似资料:
  • 主要内容:部署注册表容器注册表是一个存储和内容交付系统,它存储他们的Docker(它是用于运行应用程序的预定义图像的数据库)。 部署注册表 可以使用以下命令部署注册表: 步骤(1): 首先,使用SSH(Secure Shell)登录到您的GitLab服务器。 步骤(2): 现在使用以下命令启动注册表容器: 将第一部分指定为主机端口,将第二部分指定为容器内的端口。 当Docker重新启动时,标志会自动重新启动注册表。

  • 如何使用python cloudbuild库从SourceRepo正确传递数据来运行构建触发器? 更新1: 我有一个构建触发器设置,我试图通过改变替换和回购分支来运行该触发器 更新2: 实际代码结果: 回溯(最后一次调用):文件“/layers/google.python.pip/pip/lib/python3.9/site packages/google/api_core/grpc_helper

  • 我有一个Kubernetes的工作实例: 如何编写图像名称,使其始终从我自己的命名空间中提取。 我想这样设置: 但它没有说它无法提取图像

  • 我正在尝试弄清楚如何确定是什么导致构建从脚本化Jenkinsfile中运行。原因是我在docker容器中有一个脚本,我想在cron作业中运行它,所以当cron作业触发时,我只希望它运行容器,但当我推送更改时,我希望它检查代码、重建容器、运行静态代码分析、运行测试等。在cron运行中不需要所有这些。 我如何能得到原因?我尝试了< code > current build . get causes()

  • 在LXD容器中,应用程序应该如何编写脚本/自动部署? 例如,在LXD容器中部署应用程序的最佳方法是使用bash脚本(它部署应用程序)?如何通过在主机上执行命令在容器内执行此bash脚本? 有没有任何工具/方法可以以类似于Docker食谱的方式做到这一点?

  • 我编写了docker-compose.yml文件来创建以下容器: null 我想要一个docker-compose文件来旋转必要的容器,公开所需的端口并互连依赖的容器。目标是让我使用来自Docker Hub的官方合流图像。我的docker-compose文件如下所示: 现在,当我运行时,将创建并启动所有这些容器。但是架构注册表容器将立即退出。提供以下输出: 我搜索了这个问题,但没有帮助。我尝试了各