Vlad S
05/09/2024, 4:04 PMMarvin
05/09/2024, 4:05 PMprefecthq/prefect:2-python3.11
, you can pass environment variables into the container. Specifically, you'll need to set the following environment variables:
- `PREFECT_API_URL`: Set this to the API URL of your Prefect Cloud instance, such as <https://api.prefect.cloud/api/accounts/<ACCOUNT-ID>/workspaces/<WORKSPACE-ID>>
. Replace <ACCOUNT-ID>
and <WORKSPACE-ID>
with your actual account and workspace IDs, which you can locate in the UI's dashboard URL.
- `PREFECT_API_KEY`: Use an active API key here.
Here's an example of how to set these environment variables before running a command to deploy your worker:
bash
export PREFECT_API_URL='<https://api.prefect.cloud/api/accounts/<ACCOUNT-ID>/workspaces/<WORKSPACE-ID>>'
export PREFECT_API_KEY='<YOUR-API-KEY>'
Afterwards, you can launch your worker with a command like the following, replacing necessary placeholders:
bash
gcloud run deploy prefect-worker --image=prefecthq/prefect:2-latest \
--set-env-vars PREFECT_API_URL=$PREFECT_API_URL,PREFECT_API_KEY=$PREFECT_API_KEY \
--service-account <YOUR-SERVICE-ACCOUNT-NAME> \
--no-cpu-throttling \
--min-instances 1 \
--args "prefect","worker","start","--install-policy","always","--with-healthcheck","-p","<WORK-POOL-NAME>","-t","cloud-run"
For your reference:
- GCP Worker Guide
- Settings Guide
Keep in mind, the Prefect Cloud API URL and API Key are sensitive pieces of information that should be kept secure and preferably managed through an appropriate secrets management service.