如何使用bazel部署到Appengine flexible,使用非容器化工件部署Google Cloud?

时间:2019-05-04 07:59:46

标签: python-3.x bazel google-cloud-build

我的项目结构如下:

.
├── app
│   ├── BUILD
│   ├── entry.py
│   ├── forms.py
│   ├── __init__.py
│   ├── jinja_custom_filter.py
│   ├── models.py
│   ├── __pycache__
│   ├── static
│   ├── templates
│   ├── utils.py
│   └── views.py
├── app.db
├── app.yaml
├── BUILD
├── cloudbuild.yaml
├── config.py
├── __init__.py
├── LICENSE
├── manage.py
├── requirements.txt
├── run.py
└── WORKSPACE

4 directories, 20 files

项目使用烧瓶,sqlalchemy(请参见下文)

一个人如何使用Google Cloud Builder部署到非容器化部署选项中的Appengine?只是神器?

这是我的cloudbuild.yaml?:

# In this directory, run the following command to build this builder.
# $ gcloud builds submit


steps:
#  Fetch source.
#- name: "docker.io/library/python:3.6.8"
#  args: ['pip', 'install', '-t', '/workspace/lib', '-r', '/workspace/requirements.txt']
#- name: 'gcr.io/cloud-builders/git'
#  args: ['clone', '--single-branch', '--branch=develop', 'https://github.com/codecakes/<myproject>_gae.git', '<myproject>_gae']
# Build the Bazel builder and output the version we built with.
#- name: 'gcr.io/cloud-builders/docker'
#  args: ['build', '--tag=gcr.io/$PROJECT_ID/deploy:latest', '.']
  # Build the targets.
#- name: 'gcr.io/$PROJECT_ID/bazel'
- name: 'gcr.io/cloud-builders/bazel'
  args: ['build', '--spawn_strategy=standalone', '//app:entry', '--copt', '--force_python=PY3', '--color=yes', '--curses=yes', '--jobs=10', '--loading_phase_threads=HOST_CPUS', '--aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements', '--output_groups=pyversioninfo', '--verbose_failures']
  dir: '.'
- name: 'gcr.io/cloud-builders/bazel'
#  args: ['run', '--spawn_strategy=standalone', '//:run', '--copt',  '--verbose_failures=true', '--show_timestamps=true', '--python_version=PY3', '--build_python_zip', '--sandbox_debug', '--color=yes', '--curses=yes', '--jobs=10', '--loading_phase_threads=HOST_CPUS', '--aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements', '--output_groups=pyversioninfo']
  args: ['build', '--spawn_strategy=standalone', ':run', '--copt',  '--aspects=@bazel_tools//tools/python:srcs_version.bzl%find_requirements', '--verbose_failures=true', '--show_timestamps=true', '--python_version=PY3', '--build_python_zip', '--sandbox_debug', '--color=yes', '--curses=yes', '--jobs=10', '--loading_phase_threads=HOST_CPUS']
  dir: '.'

artifacts:
  objects:
    location: 'gs://<myproject>/'
    paths: ['cloudbuild.yaml']
#images: ['gcr.io/$PROJECT_ID/deploy:latest']

然后我做 sudo gcloud builds submit --config cloudbuild.yaml ./ 这给了我


ID                                    CREATE_TIME                DURATION  SOURCE                                                                                   IMAGES  STATUS
d4dfd7dd-0f77-49d1-ac4c-4e3a1c84e3ea  2019-05-04T07:52:13+00:00  1M32S     gs://<myproject>_cloudbuild/source/1556956326.46-3f4abd9a558440d8ba669b3d55248de6.tgz  -       SUCCESS

然后我做

sudo gcloud app deploy app.yaml --user-output-enabled --account=<myemail>

这给了我:

Updating service [default] (this may take several minutes)...failed.                                                                                                           
ERROR: (gcloud.app.deploy) Error Response: [3] Docker image asia.gcr.io/<myproject>/appengine/default.20190502t044929:latest was either not found, or is not in Docker V2 format.  Please visit https://cloud.google.com/container-registry/docs/ui 

我的工作区文件是:

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@bazel_tools//tools/build_defs/repo:git.bzl", "git_repository")

# Use the git repository
git_repository(
    name = "bazel_for_gcloud_python",
    remote = "https://github.com/weisi/bazel_for_gcloud_python.git",
    branch="master",
)

# https://github.com/bazelbuild/rules_python
git_repository(
    name = "io_bazel_rules_python",
    remote = "https://github.com/bazelbuild/rules_python.git",
    # NOT VALID!  Replace this with a Git commit SHA.
    branch= "master",
)

# Only needed for PIP support:
load("@io_bazel_rules_python//python:pip.bzl", "pip_repositories")

pip_repositories()

load("@io_bazel_rules_python//python:pip.bzl", "pip_import")

# This rule translates the specified requirements.txt into
# @my_deps//:requirements.bzl, which itself exposes a pip_install method.
pip_import(
   name = "my_deps",
   requirements = "//:requirements.txt",
)

# Load the pip_install symbol for my_deps, and create the dependencies'
# repositories.
load("@my_deps//:requirements.bzl", "pip_install")
pip_install()

和app.yaml:

runtime: custom
#vm: true
env: flex
entrypoint: gunicorn -b :$PORT run:app

runtime_config:
  # You can also specify 2 for Python 2.7
  python_version: 3

handlers:
- url: /$
  secure: always
  script: auto
- url: /.*$
  static_dir: app/static
  secure: always

# This sample incurs costs to run on the App Engine flexible environment.
# The settings below are to reduce costs during testing and are not appropriate
# for production use. For more information, see:
# https://cloud.google.com/appengine/docs/flexible/python/configuring-your-app-with-app-yaml
manual_scaling:
  instances: 1
resources:
  cpu: 1
  memory_gb: 0.5
  disk_size_gb: 10

包装

alembic==0.8.4
Babel==2.2.0
blinker==1.4
coverage==4.0.3
decorator==4.0.6
defusedxml==0.4.1
Flask==0.10.1
Flask-Babel==0.9
Flask-Login==0.3.2
Flask-Mail==0.9.1
Flask-Migrate==1.7.0
Flask-OpenID==1.2.5
flask-paginate==0.4.1
Flask-Script==2.0.5
Flask-SQLAlchemy==2.1
Flask-WhooshAlchemy==0.56
Flask-WTF==0.12
flipflop==1.0
future==0.15.2
guess-language==0.2
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.8
Mako==1.0.3
MarkupSafe==0.23
pbr==1.8.1
pefile==2016.3.28
PyInstaller==3.2
python-editor==0.5
python3-openid==3.0.9
pytz==2015.7
six==1.10.0
speaklater==1.3
SQLAlchemy==1.0.11
sqlalchemy-migrate==0.10.0
sqlparse==0.1.18
Tempita==0.5.2
Werkzeug==0.11.3
Whoosh==2.7.0
WTForms==2.1

1 个答案:

答案 0 :(得分:0)

据我了解,与Google Cloud开发人员交谈后,您必须使用dockerfile允许Google Cloud构建使用容器将其图像推送到应用程序引擎的构建。

See my own work around