Hey everyone, I’m looking at upgrading my cloudrun...
# prefect-gcp
c
Hey everyone, I’m looking at upgrading my cloudrun deployments to use the v2 version, mostly for the longer max execution time. With the v1, I’m able to set a service account but it doesn’t look like I can do this with v2. Am I missing something/is this by design?
k
It's missing from the default template right now, but it's still supported by the Cloud Run API. You can add it to your template in the Edit page on your v2 work pool by going to the Advanced tab and adding the parts I've marked here:
Copy code
{
  "variables": {
    "type": "object",
    "properties": {
      "service_account_name": {  # <-- added variable entry 
        "type": "string",
        "title": "Service Account Name",
        "example": "<mailto:service-account@example.iam.gserviceaccount.com|service-account@example.iam.gserviceaccount.com>",
        "description": "The name of the service account to use for the task execution of Cloud Run Job. By default Cloud Run jobs run as the default Compute Engine Service Account. "
      },
      "cpu": {
        "type": "string",
        "title": "CPU",
        "default": "1000m",
        "description": "The CPU to allocate to the Cloud Run job."
      },
      "env": {
        "type": "object",
        "title": "Environment Variables",
        "description": "Environment variables to set when starting a flow run.",
        "additionalProperties": {
          "type": "string"
        }
      },
      "args": {
        "type": "array",
        "items": {
          "type": "string"
        },
        "title": "Args",
        "description": "The arguments to pass to the Cloud Run Job V2's entrypoint command."
      },
      "name": {
        "type": "string",
        "title": "Name",
        "description": "Name given to infrastructure created by a worker."
      },
      "image": {
        "type": "string",
        "title": "Image Name",
        "default": "prefecthq/prefect:2-latest",
        "description": "The image to use for the Cloud Run job. If not provided the default Prefect image will be used."
      },
      "labels": {
        "type": "object",
        "title": "Labels",
        "description": "Labels applied to infrastructure created by a worker.",
        "additionalProperties": {
          "type": "string"
        }
      },
      "memory": {
        "type": "string",
        "title": "Memory",
        "default": "512Mi",
        "example": "512Mi",
        "pattern": "^\\d+(?:G|Gi|M|Mi)$",
        "description": "The memory to allocate to the Cloud Run job along with the units, whichcould be: G, Gi, M, Mi."
      },
      "region": {
        "type": "string",
        "title": "Region",
        "default": "us-central1",
        "description": "The region in which to run the Cloud Run job"
      },
      "command": {
        "type": "string",
        "title": "Command",
        "description": "The command to use when starting a flow run. In most cases, this should be left blank and the command will be automatically generated by the worker."
      },
      "timeout": {
        "type": "integer",
        "title": "Job Timeout",
        "default": 600,
        "maximum": 86400,
        "description": "The length of time that Prefect will wait for a Cloud Run Job to complete before raising an exception (maximum of 86400 seconds, 1 day).",
        "exclusiveMinimum": 0
      },
      "keep_job": {
        "type": "boolean",
        "title": "Keep Job After Completion",
        "default": false,
        "description": "Keep the completed Cloud run job on Google Cloud Platform."
      },
      "credentials": {
        "allOf": [
          {
            "$ref": "#/definitions/GcpCredentials"
          }
        ],
        "title": "GCP Credentials",
        "description": "The GCP Credentials used to connect to Cloud Run. If not provided credentials will be inferred from the local environment."
      },
      "max_retries": {
        "type": "integer",
        "title": "Max Retries",
        "default": 0,
        "description": "The number of times to retry the Cloud Run job."
      },
      "launch_stage": {
        "enum": [
          "ALPHA",
          "BETA",
          "GA",
          "DEPRECATED",
          "EARLY_ACCESS",
          "PRELAUNCH",
          "UNIMPLEMENTED",
          "LAUNCH_TAG_UNSPECIFIED"
        ],
        "type": "string",
        "title": "Launch Stage",
        "default": "BETA",
        "description": "The launch stage of the Cloud Run Job V2. See <https://cloud.google.com/run/docs/about-features-categories> for additional details."
      },
      "vpc_connector_name": {
        "type": "string",
        "title": "VPC Connector Name",
        "description": "The name of the VPC connector to use for the Cloud Run job."
      }
    },
    "definitions": {
      "GcpCredentials": {
        "type": "object",
        "title": "GcpCredentials",
        "properties": {
          "project": {
            "type": "string",
            "title": "Project",
            "description": "The GCP project to use for the client."
          },
          "service_account_file": {
            "type": "string",
            "title": "Service Account File",
            "format": "path",
            "description": "Path to the service account JSON keyfile."
          },
          "service_account_info": {
            "type": "object",
            "title": "Service Account Info",
            "description": "The contents of the keyfile as a dict."
          }
        },
        "description": "Block used to manage authentication with GCP. Google authentication is\nhandled via the `google.oauth2` module or through the CLI.\nSpecify either one of service `account_file` or `service_account_info`; if both\nare not specified, the client will try to detect the credentials following Google's\n[Application Default Credentials](<https://cloud.google.com/docs/authentication/application-default-credentials>).\nSee Google's [Authentication documentation](<https://cloud.google.com/docs/authentication#service-accounts>)\nfor details on inference and recommended authentication patterns.",
        "secret_fields": [
          "service_account_info.*"
        ],
        "block_type_slug": "gcp-credentials",
        "block_schema_references": {}
      }
    },
    "description": "Default variables for the Cloud Run worker V2.\n\nThe schema for this class is used to populate the `variables` section of the\ndefault base job template."
  },
  "job_configuration": {
    "env": "{{ env }}",
    "name": "{{ name }}",
    "labels": "{{ labels }}",
    "region": "{{ region }}",
    "command": "{{ command }}",
    "timeout": "{{ timeout }}",
    "job_body": {
      "client": "prefect",
      "template": {
        "template": {
          "timeout": "{{ timeout }}",
          "containers": [
            {
              "env": [],
              "args": "{{ args }}",
              "image": "{{ image }}",
              "command": "{{ command }}",
              "resources": {
                "limits": {
                  "cpu": "{{ cpu }}",
                  "memory": "{{ memory }}"
                }
              }
            }
          ],
          "maxRetries": "{{ max_retries }}",
          "serviceAccount": "{{ service_account_name }}"  # <-- added to job template
        }
      },
      "launchStage": "{{ launch_stage }}"
    },
    "keep_job": "{{ keep_job }}",
    "credentials": "{{ credentials }}"
  }
}
We'll make sure this exists by default in the next update to
prefect-gcp
.
🙌 2
c
Thanks @Kevin Grismore - that’s exactly what I was looking for
🙌 3