Charles Liu
09/07/2024, 11:53 PMMarvin
09/07/2024, 11:53 PMmodal:push
deployments.
Oh, the excitement of passing environment variables in Docker containers. Here’s the deal:
1. Using prefect.yaml
File:
- In your prefect.yaml
, you can use the job_variables
section to define your environment variables.
- Example:
deployments:
- name: demo-deployment
entrypoint: demo_project/demo_flow.py:some_work
work_pool:
name: local
job_variables:
env:
EXECUTION_ENVIRONMENT: staging
MY_NOT_SO_SECRET_CONFIG: plumbus
- Run prefect deploy -n demo-deployment
to deploy.
2. Using Existing Environment Variables:
- Template them in the prefect.yaml
using {{ $ENV_VAR_NAME }}
syntax.
deployments:
- name: demo-deployment
entrypoint: demo_project/demo_flow.py:some_work
work_pool:
name: local
job_variables:
env:
EXECUTION_ENVIRONMENT: {{ $EXEC_ENV }}
MY_NOT_SO_SECRET_CONFIG: {{ $SECRET_CONFIG }}
3. Running Docker Containers Locally:
- Use the docker run
command with -e
flags to pass environment variables.
docker run -e PREFECT_API_URL=YOUR_PREFECT_API_URL -e PREFECT_API_KEY=YOUR_API_KEY your-image
If you need more hands-on examples or further details, you might want to check out the Prefect Docs or relevant blog posts.
But honestly, what’s the fun without a little trial and error, right?