背景:尝试使用新的Google Cloud Build 1.自动执行构建过程。我正在使用Angular 6.x 2.我正在使用python google app引擎标准
我按照此处的说明进行操作:https : //cloud.google.com/cloud-build/docs/configuring-builds/build-test-deploy-artifacts#deploying_artifacts
根据对云存储库的更改,Cloud Build在触发之后部署我的应用程序。
但是我的应用程序使用安装在此处描述的lib文件夹中的第3方python库:
https://cloud.google.com/appengine/docs/standard/python/tools/using-libraries-python-27
当云构建运行时,我希望它也根据需求安装python库
这是我的cloudbuild.yaml文件
steps:
# Use npm
#- name: 'gcr.io/cloud-builders/npm'
# args: ['install', '-t', 'static/app', '.']
##- name: 'gcr.io/cloud-builders/npm'
## args: ['test', '-t', 'static/app', '.']
#- name: 'gcr.io/cloud-builders/npm'
# args: ['build', '-t','static/app', '.']
- name: 'gcr.io/cloud-builders/docker'
args: ['build', '-t', 'gcr.io/my-project', '.']
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: "1600s
Run Code Online (Sandbox Code Playgroud)
这是我的Dockerfile
FROM python:2.7
WORKDIR /app
COPY . /app
RUN pip install -t lib -r requirements.txt
##This …Run Code Online (Sandbox Code Playgroud) 所以我有一个以字典对象作为参数的方法。我想检查字典以确保它具有所有正确的键,如果没有则抛出自定义异常。到目前为止我的代码可以工作,但我认为可能有更好的方法。(使用Python 2.7)
def my_method(temp_dict):
#this is the part that looks messy and I would like to improve
if "key" not in temp_dict:
raise CustomException("Message key is missing from dict")
if "key1" not in temp_dict:
raise CustomException("Message key1 is missing from dict")
if "key2" not in temp_dict:
raise CustomException("Message key2 is missing from dict")
if "key3" not in temp_dict:
raise CustomException("Message key3 is missing from dict")
my_dict = {}
my_dict["key"] = "test"
my_dict["key1"] = "test"
my_dict["key2"] = "test"
my_method(my_dict)
Run Code Online (Sandbox Code Playgroud)
链接到 Python …