Skip to content

Commit

Permalink
Merge branch 'main' into client-side-task-run-ids
Browse files Browse the repository at this point in the history
  • Loading branch information
desertaxle committed May 13, 2024
2 parents f3fab28 + c9e22de commit b63b6f8
Show file tree
Hide file tree
Showing 44 changed files with 797 additions and 1,378 deletions.
171 changes: 49 additions & 122 deletions docs/guides/dask-ray-task-runners.md

Large diffs are not rendered by default.

86 changes: 23 additions & 63 deletions docs/guides/deployment/storage-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,40 +28,15 @@ search:

# Where to Store Your Flow Code

When a flow runs, the execution environment needs access to its code.
Flow code is not stored in a Prefect server database instance or Prefect Cloud.
When deploying a flow, you have several flow code storage options.
When a deployment is run, the execution environment needs access to the flow code.
Flow code is not stored in a Prefect server instance or in Prefect Cloud.

This guide discusses storage options with a focus on deployments created with the interactive CLI experience or a `prefect.yaml` file.
If you'd like to create your deployments using Python code, see the discussion of flow code storage on the `.deploy` tab of [Deploying Flows to Work pools and Workers guide](/guides/prefect-deploy/#creating-work-pool-based-deployments).
You have several flow code storage options.

## Option 1: Local storage
This guide focusses on deployments created with the interactive CLI experience or a prefect.yaml file. If you'd like to create your deployments using Python code, see the discussion of flow code storage in the [`.deploy` section of Deploying Flows to Work pools and Workers guide](/guides/prefect-deploy/#creating-work-pool-based-deployments-with-deploy).

Local flow code storage is often used with a Local Subprocess work pool for initial experimentation.

To create a deployment with local storage and a Local Subprocess work pool, do the following:

1. Run `prefect deploy` from the root of the directory containing your flow code.
1. Select that you want to create a new deployment, select the flow code entrypoint, and name your deployment.
1. Select a *process* work pool.

You are then shown the location that your flow code will be fetched from when a flow is run.
For example:

<div class="terminal">
```bash
Your Prefect workers will attempt to load your flow from:
/my-path/my-flow-file.py. To see more options for managing your flow's code, run:
$ prefect init
```
</div>
When deploying a flow to production, you most likely want code to run with infrastructure-specific configuration.
The flow code storage options shown below are recommended for production deployments.
## Option 2: Git-based storage
## Option 1: Git-based storage

Git-based version control platforms are popular locations for code storage.
They provide redundancy, version control, and easier collaboration.
Expand All @@ -84,7 +59,6 @@ Would you like your workers to pull your flow code from its remote repository wh
? Is main the correct branch to pull your flow code from? [y/n] (y):
? Is this a private repository? [y/n]: y
```

</div>
In this example, the git repository is hosted on GitHub.
Expand All @@ -95,9 +69,7 @@ If the repository is private, you can enter a token to access your private repos
<div class="terminal">
```bash

? Please enter a token that can be used to access your private repository. This token will be saved as a Secret block via the Prefect API: "123_abc_this_is_my_token"

```
</div>
Expand Down Expand Up @@ -133,7 +105,7 @@ If you want to configure a Secret block ahead of time, create the block via code
pull:
- prefect.deployments.steps.git_clone:
repository: https://bitbucket.org/org/my-private-repo.git
repository: https://gitlab.com/org/my-private-repo.git
access_token: "{{ prefect.blocks.secret.my-block-name }}"
```
Expand All @@ -143,7 +115,7 @@ Alternatively, you can create a Credentials block ahead of time and reference it
1. Install the Prefect-Github library with `pip install -U prefect-github`
1. Register the blocks in that library to make them available on the server with `prefect block register -m prefect_github`.
1. Create a GitHub Credentials block via code or the Prefect UI and reference it as shown above.
1. Create a GitHub Credentials block via code or the Prefect UI and reference it as shown:
```yaml
Expand All @@ -157,7 +129,7 @@ Alternatively, you can create a Credentials block ahead of time and reference it
1. Install the relevant library with `pip install -U prefect-bitbucket`
1. Register the blocks in that library with `prefect block register -m prefect_bitbucket`
1. Create a Bitbucket credentials block via code or the Prefect UI and reference it as shown above.
1. Create a Bitbucket credentials block via code or the Prefect UI and reference it as shown:
```yaml
Expand All @@ -171,7 +143,7 @@ Alternatively, you can create a Credentials block ahead of time and reference it
1. Install the relevant library with `pip install -U prefect-gitlab`
1. Register the blocks in that library with `prefect block register -m prefect_gitlab`
1. Create a GitLab credentials block via code or the Prefect UI and reference it as shown above.
1. Create a GitLab credentials block via code or the Prefect UI and reference it as shown:
```yaml
Expand All @@ -186,31 +158,21 @@ Alternatively, you can create a Credentials block ahead of time and reference it
You need to push your code manually or as part of your CI/CD pipeline.
This design decision is an intentional one to avoid confusion about the git history and push process.
## Option 3: Docker-based storage

Another popular way to store your flow code is to include it in a Docker image. The following work pools use Docker containers, so the flow code can be directly baked into the image:
## Option 2: Docker-based storage
- Docker
- Kubernetes
- Serverless cloud-based options
- AWS Elastic Container Service
- Azure Container Instances
- Google Cloud Run
- Push-based serverless cloud-based options (no worker required)
- AWS Elastic Container Service - Push
- Azure Container Instances - Push
- Google Cloud Run - Push
Another popular way to store your flow code is to include it in a Docker image.
All work pool options except Process and Prefect Managed work pools allow you to bake your code into a Docker image.
1. Run `prefect init` in the root of your repository and choose `docker` for the project name and answer the prompts to create a `prefect.yaml` file with a build step that will create a Docker image with the flow code built in. See the [Workers and Work Pools page of the tutorial](/tutorial/workers/) for more info.
1. Run `prefect deploy` from the root of your repository to create a deployment.
1. Upon deployment run the worker will pull the Docker image and spin up a container.
1. The flow code baked into the image will run inside the container.
1. When a deployment runs the worker pulls the Docker image and spins up a container.
1. The flow code baked into the image runs inside the container.
!!! tip "CI/CD may not require push or pull steps"
You don't need push or pull steps in the `prefect.yaml` file if using CI/CD to build a Docker image outside of Prefect.
Instead, the work pool can reference the image directly.

## Option 4: Cloud-provider storage
## Option 3: Cloud-provider storage

You can store your code in an AWS S3 bucket, Azure Blob Storage container, or GCP GCS bucket and specify the destination directly in the `push` and `pull` steps of your `prefect.yaml` file.

Expand All @@ -219,7 +181,7 @@ Below are the recipe options and the relevant portions of the `prefect.yaml` fil

=== "AWS S3 bucket"

Choose `s3` as the recipe and enter the bucket name when prompted.
Choose `s3Bucket` as the recipe and enter the bucket name when prompted.

```yaml
Expand Down Expand Up @@ -248,7 +210,7 @@ Below are the recipe options and the relevant portions of the `prefect.yaml` fil
1. Register the blocks in Prefect-AWS with `prefect block register -m prefect_aws`
1. Create a user with a role with read and write permissions to access the bucket. If using the UI, create an access key pair with *IAM->Users->Security credentials->Access keys->Create access key*. Choose *Use case->Other* and then copy the *Access key* and *Secret access key* values.
1. Create an AWS Credentials block via code or the Prefect UI. In addition to the block name, most users will fill in the *AWS Access Key ID* and *AWS Access Key Secret* fields.
1. Reference the block as shown in the push and pull steps above.
1. Reference the block as shown in the push and pull steps

=== "Azure Blob Storage container"

Expand Down Expand Up @@ -331,7 +293,7 @@ Alternatively, you can inject environment variables into your deployment like th
folder: '{{ $CUSTOM_FOLDER }}'
```
## Including and excluding files from storage
## Include or exclude files from storage
By default, Prefect uploads all files in the current folder to the configured storage location when you create a deployment.
Expand All @@ -344,15 +306,13 @@ When using a git repository, Docker image, or cloud-provider storage location, y
## Other code storage creation methods
In earlier versions of Prefect [storage blocks](/concepts/blocks/) were the recommended way to store flow code.
Storage blocks are still supported, but not recommended.
Storage blocks are deprecated.
As shown above, repositories can be referenced directly through interactive prompts with `prefect deploy` or in a `prefect.yaml`.
When authentication is needed, Secret or Credential blocks can be referenced, and in some cases created automatically through interactive deployment creation prompts.

## Next steps
When authentication is needed, Secret or Credential blocks can be referenced, and in some cases, created automatically through interactive deployment creation prompts.
You've seen options for where to store your flow code.
## Conclusion
We recommend using Docker-based storage or git-based storage for your production deployments.
You've seen options for storing your flow code.
For easier version control, we recommend using Docker-based storage or git-based storage for your production deployments.
Check out more [guides](/guides/) to reach your goals with Prefect.
31 changes: 16 additions & 15 deletions docs/integrations/prefect-aws/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pip install -U prefect-aws
```
</div>

### Register newly installed blocks types
### Register newly installed block types

Register the block types in the prefect-aws module to make them available for use.

Expand All @@ -28,10 +28,20 @@ prefect block register -m prefect_aws
```
</div>

Below we show how to create blocks with Python code.
## Examples

### Run flows on AWS ECS

Run flows on [AWS Elastic Container Service (ECS)](https://aws.amazon.com/ecs/) to dynamically scale your infrastructure.

See the [ECS guide](/ecs_guide/) for a walkthrough of using ECS in a hybrid work pool.

If you're using Prefect Cloud, [ECS push work pools](https://docs.prefect.io/latest/guides/deployment/push-work-pools/#__tabbed_1_1) provide all the benefits of ECS with a quick setup and no worker needed.

In the examples below, you create blocks with Python code.
Alternatively, each block can be created through the Prefect UI.

## Save credentials to an AWS Credentials block
### Save credentials to an AWS Credentials block

Use of most AWS services requires an authenticated session.
Prefect makes it simple to provide credentials via a AWS Credentials block.
Expand All @@ -58,7 +68,7 @@ Prefect is using the Boto3 library under the hood.
To find credentials for authentication, any data not provided to the block are sourced at runtime in the order shown in the [Boto3 docs](https://boto3.amazonaws.com/v1/documentation/api/latest/guide/credentials.html#configuring-credentials).
Prefect creates the session object using the values in the block and then, any missing values follow the sequence in the Boto3 docs.

See an example of using the `AwsCredentials` block with [AWS Secrets Manager](#aws-secrets-manager) with third-party services without storing credentials in the block itself in [this guide](/guides/secrets/).
See an example of using the `AwsCredentials` block with [AWS Secrets Manager](#aws-secrets-manager) with third-party services without storing credentials in the block itself in [this guide](https://docs.prefect.io/latest/guides/secrets/).

Here's how to load the saved credentials:

Expand All @@ -71,7 +81,7 @@ AwsCredentials.load("BLOCK-NAME-PLACEHOLDER")

The AWS Credentials block is often nested within other blocks, such as `S3Bucket` or `AwsSecret`, and provides authentication for those services.

## Read and write files to AWS S3
### Read and write files to AWS S3

Upload a file to an AWS S3 bucket and download the same file under a different file name.
The following code assumes that the bucket already exists:
Expand Down Expand Up @@ -105,7 +115,7 @@ if __name__ == "__main__":
s3_flow()
```

## Save secrets with AWS Secrets Manager
### Access secrets with AWS Secrets Manager

Write a secret to AWS Secrets Manager, read the secret data, delete the secret, and return the secret data.

Expand All @@ -128,15 +138,6 @@ if __name__ == "__main__":
secrets_manager_flow()
```

## Run flows on AWS ECS

Run flows on [AWS Elastic Container Service (ECS)](https://aws.amazon.com/ecs/) to dynamically scale your infrastructure.

See the [ECS guide](/ecs_guide/) for a walkthrough of using ECS in a hybrid work pool.

If you're using Prefect Cloud and your organization's security posture allows storing credentials in blocks, [ECS push work pools](https://docs.prefect.io/latest/guides/deployment/push-work-pools/#__tabbed_1_1) are a great option.
They provide all the benefits of ECS with a quick setup and no worker needed.

## Resources

For assistance using AWS, consult the [AWS documentation](https://docs.aws.amazon.com/) and, in particular, the [Boto3 documentation](https://boto3.amazonaws.com/v1/documentation/api/latest/index.html).
Expand Down

0 comments on commit b63b6f8

Please sign in to comment.