feat: add cloudbuild.yaml generation for new apps
This commit is contained in:
@ -50,6 +50,14 @@ func cmdNew(cmd *cobra.Command, args []string) {
|
||||
}
|
||||
})
|
||||
|
||||
ifNotExists(path.Join(appPath, "cloudbuild.yaml"), func(p string) error {
|
||||
if v, err := tmpl.get("cloudbuild.yaml"); err == nil {
|
||||
return ioutil.WriteFile(p, v, 0644)
|
||||
} else {
|
||||
return err
|
||||
}
|
||||
})
|
||||
|
||||
// Create app config folder and add relevant files
|
||||
|
||||
appConfigPath := path.Join(appPath, "config")
|
||||
|
File diff suppressed because one or more lines are too long
42
internal/serv/tmpl/cloudbuild.yaml
Normal file
42
internal/serv/tmpl/cloudbuild.yaml
Normal file
@ -0,0 +1,42 @@
|
||||
steps:
|
||||
# Build image with tag 'latest'
|
||||
- name: "gcr.io/cloud-builders/docker"
|
||||
args:
|
||||
[
|
||||
"build",
|
||||
"--tag",
|
||||
"gcr.io/$PROJECT_ID/{% app_name_slug %}:latest",
|
||||
"--build-arg",
|
||||
"GO_ENV=production",
|
||||
".",
|
||||
]
|
||||
|
||||
# Push new image to Google Container Registry
|
||||
- name: "gcr.io/cloud-builders/docker"
|
||||
args: ["push", "gcr.io/$PROJECT_ID/{% app_name_slug %}:latest"]
|
||||
|
||||
# Deploy image to Cloud Run
|
||||
- name: "gcr.io/cloud-builders/gcloud"
|
||||
args:
|
||||
[
|
||||
"run",
|
||||
"deploy",
|
||||
"data",
|
||||
"--image",
|
||||
"gcr.io/$PROJECT_ID/{% app_name_slug %}:latest",
|
||||
"--add-cloudsql-instances",
|
||||
"$PROJECT_ID:$REGION:{% app_name_slug %}_production",
|
||||
"--region",
|
||||
"$REGION",
|
||||
"--platform",
|
||||
"managed",
|
||||
"--update-env-vars",
|
||||
"GO_ENV=production,SG_DATABASE_HOST=/cloudsql/$PROJECT_ID:$REGION:{% app_name_slug %}_production,SECRETS_FILE=prod.secrets.yml",
|
||||
"--port",
|
||||
"8080",
|
||||
"--service-account",
|
||||
"$SERVICE_ACCOUNT",
|
||||
"--allow-unauthenticated",
|
||||
"--verbosity",
|
||||
"debug",
|
||||
]
|
Reference in New Issue
Block a user