如何自动部署谷歌应用程序引擎灵活使用容器注册与生成触发器 [英] How to auto deploy google app engine flexible using Container Registry with Build Trigger
问题描述
我使用GitHub来保存我的项目。使用PHP风暴我推送脚本到GitHub回购。
我使用Google App引擎的灵活环境应用程序。每当我推到我的GitHub回购。
最新的脚本将自动部署到Google App Engine灵活环境PHP项目。因此,我在GCP容器注册表中创建了构建触发器。
这里是我的PHP示例使用Docker文件的项目
web / index.php
$ b
<?php
回声'这是示例项目';
?>
App.yaml
运行时:php
env:flex
$ b $ runtime_config:
document_root:web
$ b manual_scaling:
实例:1
处理程序:
- url:。*
script:index.php
Composer.json
{
require:{
php:7.1。*
}
}
$ b Dockerfile
#Docker:Google App Engine
从gcr.io/google-appengine/php
使用Google云端平台容器注册表构建触发器。创建构建触发器。我得到了以下日志
生成记录器
开始构建4d51b494-5f7d-48e5-a2a2-6d7d6a9318a9
FETCHSOURCE
在/workspace/.git/中初始化空的Git存储库
从https:// source .developers.google.com / p / project-id / r / github-test
*分支5f9ac268123a3cfef5876034f2933eb83b34cd6d - > FETCH_HEAD
HEAD现在在5f9ac26 v 1
BUILD
已经有图像(含摘要):gcr.io/cloud-builders/docker
发送构建上下文到Docker守护进程87.04kB
第1/1步:FROM gcr.io/google-appengine/php
最新消息:从google-appengine / php
中提取摘要:sha256:578584d281828af48df03b85dcdcfd5792e8eb2916567497b56468b
状态:下载了较新的gcr.io/google-appengine/php:latest
[91m#执行3个构建触发器...
[0m步骤1/1:COPY。 $ APP_DIR
步骤1/1:RUN chown -R www-data.www-data $ APP_DIR
--->运行于c9d98191fa2b
第1/1步:运行/build-scripts/composer.sh
--->运行于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']'$ b $ '''''''='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 = - 无脚本
+ 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 [91mOading composer repositories with package information
[0m [91mUpdating dependencies
[0m [91m无需安装或更新
[ 0m [91m文件锁定文件
生成优化的自动加载文件
[0m ---> 1c5b266fe5ef
删除中间容器473f7595359f
删除中间容器c9d98191fa2b
删除中间容器ec2b02e5f0d1
成功构建1c5b266fe5ef
成功标记为gcr.io/project-id/github-test: 5f9ac268123a3cfef5876034f2933eb83b34cd6d
PUSH
推送gcr.io/project-id/github-test:5f9ac268123a3cfef5876034f2933eb83b34cd6d
推送指存储库[gcr.io/project-id/github-test]
09e0b63e8b63:准备
9ab9de3bae7c:准备
7ca730235cb1:准备
bca74f739283:准备
83430675961e:准备
c4b086b9d099:准备
acf227e1b2a5:准备
40de2f738e9e:准备
0ef981ddb200:准备
73acc0dfea4b:准备
825db9ad6441:准备
23088c61aa93:准备
122586f0e47f:准备
357a1f7d4b42:准备
d7fe08acdf1d :准备
cd1b43d6d268:准备
23b7338cf1fe:准备
9301d4a8f319:准备
2126b271c428:准备
c4b086b9d099:等待
acf227e1b2a5:等待
40de2f738e9e:等待
0ef981ddb200:等待
73acc0dfea4b:等待
825db9ad6441:等待
23088c61aa93:等待
122586f0e47f:等待
357a1f7d4b42:等待
d7fe08acdf1d:等待
cd1b43d6d268:等待
23b7338cf1fe:等待
9301d4a8f319:等待
2126b271c428:等待
83430675961e:图层已存在
bca74f739283:图层已存在
c4b086b9d099:图层已存在
40de2f738e9e:图层已存在
acf227e1b2a5:图层已存在
0ef981ddb200:图层已存在
73acc0dfea4b:图层已存在
825db9ad6441:图层已存在
122586f0e47f:图层已存在
23088c61aa93:图层已存在
357a1f7d4b42:图层已存在
d7fe08acdf1d:图层已存在
cd1b43d6d268:图层已存在
23b7338cf1fe:图层已存在
9301d4a8f319:图层已存在
2126b27 1c428:层已经存在
09e0b63e8b63:推
7ca730235cb1:推
9ab9de3bae7c:推
5f9ac268123a3cfef5876034f2933eb83b34cd6d:消化:SHA256:c604792b8b384e1186b55d11a1d04e8e06051e3f3083c25bd13668dcf大小:4285
DONE
我想将容器映像部署到GAE FE,所以我改变了我的docker文件。
Dockerfile
#Docker:Google App Engine
FROM gcr.io/google-appengine/php
gcloud app deploy -image-url = gcr.io / project-id / github-test
我得到了这个问题
开始构建43508598-4542-4e1c-a9e7 -d29343878202
FETCHSOURCE
在/workspace/.git/中初始化空的Git存储库
从https://source.developers.google.com/p/project-id/ r / github-test
* branch ea7511b88ad5c59736037c37685ea699b5c0 - > FETCH_HEAD
HEAD现在在ea7511b v 1
BUILD
已经有图像(带有摘要):gcr.io/cloud-builders/docker
发送构建上下文到Docker守护进程87.04kB
来自守护进程的错误响应:Dockerfile解析错误第7行:未知指令:GCLOUD
错误
错误:构建步骤gcr.io/cloud-builders/docker@sha256:59e98ecdfe9229f080085953611ffb708a0df5b7f37a253ec 失败:退出状态1
我不知道在哪里使用gcloud app deploy -image url 。
帮助我如何使用git和构建触发器来在Container Registry中部署映像url
使用类似这样的方法尝试 cloudbuild.yaml
文件:
步骤:
#构建Docker镜像。
- name:gcr.io/cloud-builders/docker
args:['build','-t','gcr.io/$PROJECT_ID/app','。']
#把它推到GCR。
- name:gcr.io/cloud-builders/docker
args:['push','gcr.io/$PROJECT_ID/app']
#从图像中部署您的Flex应用程序在GCR。
- name:gcr.io/cloud-builders/gcloud
args:['app','deploy','app.yaml','--image-url = gcr.io / $ PROJECT_ID / app']
#请注意,此版本会推送此图片。
images:['gcr.io/$PROJECT_ID/app']
添加此文件到你的仓库并配置一个生成触发器,当你推送到你的分支时执行它。
I'm using GitHub to keep my projects. Using PHP storm I m pushing my script to GitHub repo.
I m using Google App engine flexible environment application. Whenever I push to my GitHub repo. The latest script will auto deploy to Google App Engine Flexible Environment PHP project.So, I Created Build Trigger in GCP Container Registry.
Here are My PHP sample projects with Docker file
web/index.php
<?php
Echo 'this is sample project';
?>
App.yaml
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
Using Google Cloud Platform Container Registry Build trigger.Created a build trigger. I got the below logs
Build Logger
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
I want to deploy container image to GAE FE, So, I changed my docker file like this
Dockerfile
# Docker: Google App Engine
FROM gcr.io/google-appengine/php
gcloud app deploy -image-url=gcr.io/project-id/github-test
I got this issues
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
I don’t know where to use the gcloud app deploy -image url.
Help me how to gcloud app deploy image url in Container Registry using git and build triggers
Try a cloudbuild.yaml
file with something like this:
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']
Add this file to your repository and configure a build trigger that executes that when you push to your branch.
这篇关于如何自动部署谷歌应用程序引擎灵活使用容器注册与生成触发器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!