Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions goblet.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,13 @@
"artifact_tag": {
"type": "string"
},
"cloudbuild_cache": {
"enum": [
"KANIKO",
"DOCKER_LATEST"
],
"type": "string"
},
"environmentVariables": {
"patternProperties": {
"^.+$": {
Expand All @@ -94,6 +101,15 @@
"dockerfile": {
"type": "string"
},
"eventarc": {
"properties": {
"serviceAccount": {
"description": "eventarc@{PROJECT}.iam.gserviceaccount.com",
"type": "string"
}
},
"type": "object"
},
"function_name": {
"type": "string"
},
Expand All @@ -106,6 +122,15 @@
"redis": {
"$ref": "https://raw.githubusercontent.com/goblet/goblet/main/utils/schema/references/redis.v1.json#/schemas/Instance"
},
"scheduler": {
"properties": {
"serviceAccount": {
"description": "scheduler@{PROJECT}.iam.gserviceaccount.com",
"type": "string"
}
},
"type": "object"
},
"securityDefinitions": {
"properties": {
"firebase": {
Expand Down
72 changes: 57 additions & 15 deletions goblet/backends/cloudrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,23 +180,11 @@ def create_build(self, client, source=None, name="goblet"):
if build_tags:
images += list(map(lambda tag: f"{registry}:{tag}", build_tags.split(",")))

steps = self._get_cloudbuild_steps(images)

req_body = {
"source": {"storageSource": source["storageSource"]},
"steps": [
{
"name": "gcr.io/cloud-builders/docker",
"args": [
"build",
"--network=cloudbuild",
]
+ list(map(lambda image: ["-t", image], images))
+ [
"--cache-from",
registry,
".",
],
}
],
"steps": steps,
"images": images,
**build_configs,
}
Expand Down Expand Up @@ -249,6 +237,60 @@ def _checksum(self):
except KeyError:
return 0

def _get_cloudbuild_steps(self, images):
cloudbuild_cache = self.config.deploy.get("cloudbuild_cache", "DOCKER_LATEST")
if cloudbuild_cache == "DOCKER_LATEST":
steps = [
{
"name": "gcr.io/cloud-builders/docker",
"entrypoint": "bash",
"args": ["-c", f"docker pull {images[0]} || exit 0"],
},
{
"name": "gcr.io/cloud-builders/docker",
"args": [
"build",
"--network=cloudbuild",
]
+ list(map(lambda image: ["-t", image], images))
+ [
"--cache-from",
images[0],
".",
],
},
]
elif cloudbuild_cache == "KANIKO":
steps = [
{
"name": "gcr.io/kaniko-project/executor:latest",
"args": [
f"--destination={images[0]}",
"--cache=true",
f"--cache-ttl={24*365*3}h",
],
},
{
"name": "gcr.io/cloud-builders/docker",
"entrypoint": "bash",
"args": [
"-c",
f"docker pull {images[0]}"
+ " && ".join(
[""]
+ [
f"docker tag {images[0]} {build_tag_image}"
for build_tag_image in images[1:]
]
),
],
},
]
else:
raise Exception(f"Invalid cloudbuild_cache option {cloudbuild_cache}")

return steps

def update_config(self, infra_configs=[], write_config=False, stage=None):
config_updates = {}
for infra_config in infra_configs:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"generation": "1",
"createTime": "2023-10-11T21:29:36.879768Z",
"updateTime": "2023-10-11T21:29:36.879768Z",
"creator": "mauricio.martinez@premise.com",
"lastModifier": "mauricio.martinez@premise.com",
"creator": "creator@goblet.com",
"lastModifier": "modifier@goblet.com",
"ingress": "INGRESS_TRAFFIC_ALL",
"launchStage": "GA",
"template": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
"generation": "1",
"createTime": "2023-10-11T21:29:36.879768Z",
"updateTime": "2023-10-11T21:29:36.879768Z",
"creator": "mauricio.martinez@premise.com",
"lastModifier": "mauricio.martinez@premise.com",
"creator": "creator@goblet.com",
"lastModifier": "modifier@goblet.com",
"launchStage": "GA",
"template": {
"scaling": {
Expand Down Expand Up @@ -70,8 +70,8 @@
"generation": "1",
"createTime": "2023-10-11T21:29:36.879768Z",
"updateTime": "2023-10-11T21:29:36.879768Z",
"creator": "mauricio.martinez@premise.com",
"lastModifier": "mauricio.martinez@premise.com",
"creator": "creator@goblet.com",
"lastModifier": "modifier@goblet.com",
"launchStage": "GA",
"template": {
"scaling": {
Expand Down
Loading