Paweł Biernat
09/26/2024, 11:47 AMMarvin
09/26/2024, 11:48 AMSecret
block. You can directly include credentials in your deployment configuration. Here's an example of configuring a pull
step in your prefect.yaml to use credentials securely:
yaml
pull:
- prefect.deployments.steps.git_clone:
repository: <https://bitbucket.org/org/repo.git>
access_token: "{{ prefect.blocks.secret.bitbucket-token }}"
In this scenario, credentials specified for the main repository do not automatically propagate to submodules. You must ensure that each submodule's repository has the necessary access tokens configured.
For more detailed guidance, check out the Prefect documentation on deployments and storage guide.Marvin
09/26/2024, 11:48 AMGitHubCredentials
, GitLabCredentials
, or BitbucketCredentials
, or directly using an access token. You can use a Secret block to securely store and use these credentials.
Example for Prefect 2.x:
pull:
- prefect.deployments.steps.git_clone:
repository: <https://bitbucket.org/org/repo.git>
access_token: "{{ prefect.blocks.secret.bitbucket-token }}"
For Prefect 3.x, the process is similar. It allows the use of credentials blocks or direct tokens to clone repositories, handling submodules with the provided credentials.
Example for Prefect 3.x:
pull:
- prefect.deployments.steps.git_clone:
repository: <https://github.com/org/repo.git>
credentials: "{{ prefect.blocks.github-credentials.my-credentials }}"
For more information, refer to the following documentation:
Prefect 2.x:
- https://docs-2.prefect.io/latest/guides/prefect-deploy/
- https://docs-2.prefect.io/latest/guides/deployment/storage-guide/
Prefect 3.x:
- https://docs-3.prefect.io/3.0/deploy/infrastructure-concepts/prefect-yamlPaweł Biernat
09/26/2024, 11:49 AMMarvin
09/26/2024, 11:49 AMgit_clone
steps if your repository has submodules. You can handle submodules within a single git_clone
step by including the necessary submodule initialization and updates.
Example for Prefect 2.x and 3.x:
pull:
- prefect.deployments.steps.run_shell_script:
script: |
git clone --recurse-submodules <https://github.com/org/repo.git>
cd repo
git submodule update --init --recursive
stream_output: true
Using the run_shell_script
step allows you to execute shell commands that clone the repository while initializing and updating its submodules in one go.
For more information on deployment steps and handling repositories with submodules, refer to the following documentation:
Prefect 2.x:
- https://docs-2.prefect.io/latest/guides/ci-cd/
- https://docs-2.prefect.io/latest/integrations/prefect-github/repository/
Prefect 3.x:
- https://docs-3.prefect.io/3.0/deploy/infrastructure-concepts/prefect-yaml
- https://docs-3.prefect.io/3.0/deploy/infrastructure-concepts/deploy-ci-cdPaweł Biernat
09/26/2024, 11:51 AMMarvin
09/26/2024, 11:51 AMprefect.yaml
example for both Prefect 2.x and 3.x that demonstrates how to pull a repository with submodules:
yaml
# prefect.yaml
name: my-deployment
description: An example deployment
# Specify the pull step
pull:
- prefect.deployments.steps.run_shell_script:
id: clone-repo
script: |
git clone --recurse-submodules <https://github.com/org/repo.git>
cd repo
git submodule update --init --recursive
stream_output: true
# Set the working directory
- prefect.deployments.steps.set_working_directory:
id: set-working-dir
directory: repo
# Define the flow run configuration
flow:
name: my-flow
entrypoint: repo/my_flow.py:flow
# Add any additional steps needed (build, push, etc.)
build:
- prefect.deployments.steps.run_shell_script:
id: install-dependencies
script: |
pip install -r repo/requirements.txt
stream_output: true
# Define the schedule (if any)
schedule:
interval: "@daily" # Run daily
This example deployment performs the following steps:
1. Clone the repository: The git clone --recurse-submodules
command clones the repository along with all its submodules.
2. Initialize and update submodules: The git submodule update --init --recursive
command makes sure that all submodules are initialized and updated.
3. Set the working directory: This step sets the working directory to the cloned repository.
4. Specify the flow entrypoint: Define the entrypoint for your flow within the repository.
5. Install dependencies: An additional step to install any required dependencies using a requirements.txt
file.
6. Define the schedule: You can set up a schedule for your flow runs. In this example, it runs daily.
You can adjust the script and paths according to your specific repository structure and requirements.
For more detailed explanations and examples, you can refer to:
- Prefect 2.x documentation: https://docs-2.prefect.io/latest/guides/prefect-deploy/
- Prefect 3.x documentation: https://docs-3.prefect.io/3.0/deploy/infrastructure-concepts/prefect-yamlPaweł Biernat
09/26/2024, 11:58 AMMarvin
09/26/2024, 11:58 AM.gitlab-ci.yml
configuration:
yaml
image: python:3.8
stages:
- deploy
deploy:
stage: deploy
script:
- pip install prefect
- BRANCH_NAME=$(echo $CI_COMMIT_REF_NAME | sed 's/\//-/g') # Replace '/' with '-' in branch names
- prefect deployment build -n "my-flow-$BRANCH_NAME" -p default-agent-pool --apply --skip-upload
only:
- branches # Adjust this according to your needs (e.g., only: [main, develop])
### Prefect Deployment YAML Example
This is a simple example `prefect.yaml`:
yaml
# prefect.yaml
name: my-deployment
description: An example deployment
# Specify the pull step
pull:
- prefect.deployments.steps.run_shell_script:
script: |
git clone --recurse-submodules <https://your-repo.git>
cd repo
git submodule update --init --recursive
stream_output: true
# Set the working directory
- prefect.deployments.steps.set_working_directory:
directory: repo
# Define the flow run configuration
flow:
name: my-flow
entrypoint: repo/my_flow.py:flow
# Add any additional steps needed (build, push, etc.)
build:
- prefect.deployments.steps.run_shell_script:
script: |
pip install -r repo/requirements.txt
stream_output: true
# Define the schedule (if any)
schedule:
interval: "@daily" # Run daily
### Explanation:
1. GitLab CI Configuration (.gitlab-ci.yml
):
- Image: Use a Python image to run your Prefect code.
- Stages: Define the stages of your CI/CD pipeline.
- Script:
- Install Prefect.
- Extract the branch name using $CI_COMMIT_REF_NAME
, and replace any slashes (/
) with hyphens (-
).
- Build the Prefect deployment with a name that includes the branch name.
- Adjust the only
condition to specify which branches you want to run this on.
2. Prefect Configuration (prefect.yaml
):
- Define the steps to pull, set the working directory, and configure the flow. This example handles cloning the repository along with its submodules, sets up the working directory, installs dependencies, and schedules flow execution.
This setup ensures that each deployment name will include the branch name from which it was deployed, providing better organization and tracking in Prefect.
For additional details, see:
- Prefect 2.x CI/CD guide: https://docs-2.prefect.io/latest/guides/ci-cd/
- Prefect 3.x CI/CD guide: https://docs-3.prefect.io/3.0/deploy/infrastructure-concepts/deploy-ci-cdPaweł Biernat
09/26/2024, 12:04 PMMarvin
09/26/2024, 12:05 PMprefect deploy
command, you may get prompted for various details if those details are not specified or missing in your prefect.yaml
file. The prefect.yaml
file should contain detailed configuration to avoid such prompts, but let me provide some clarity on how to ensure this.
### Prefect 3.x Configuration
1. Ensure all required fields are present in prefect.yaml
: Your prefect.yaml
file should include all necessary fields like name, schedule, and deployment configurations.
2. Check your prefect.yaml
syntax:
yaml
# prefect.yaml
name: my-flow-deployment
description: An example deployment
# Specify the pull step
pull:
- prefect.deployments.steps.run_shell_script:
script: |
git clone --recurse-submodules <https://your-repo.git>
cd repo
git submodule update --init --recursive
stream_output: true
# Set the working directory
- prefect.deployments.steps.set_working_directory:
directory: repo
# Define the flow run configuration
flow:
name: my-flow
entrypoint: repo/my_flow.py:flow
# Add any additional steps needed (build, push, etc.)
build:
- prefect.deployments.steps.run_shell_script:
script: |
pip install -r repo/requirements.txt
stream_output: true
# Define the schedule (if any)
schedule:
interval: "@daily" # Run daily
3. Use the --skip-prompt
flag: When deploying, you can use the --skip-prompt
flag to avoid interactive prompts if the necessary information is already included in the prefect.yaml
.
Example command:
sh
prefect deploy --skip-prompt
### Common Reasons for Prompts:
- Missing Fields: If essential fields like name
, schedule
, or flow entrypoint
are missing from the prefect.yaml
, Prefect will prompt for this information.
- Syntax Errors: Any syntactical issues in your prefect.yaml
might lead to prompts or errors. Ensure the indentation and structure are correct.
- Incorrect Field Names: Ensure that you use the correct field names as specified in the Prefect documentation.
### Documentation References:
- Prefect 3.x deployment guide: https://docs-3.prefect.io/3.0/deploy/infrastructure-concepts/prefect-yaml
- GitLab integration: https://docs-3.prefect.io/integrations/prefect-gitlab
Ensure your prefect.yaml
file covers all necessary configurations, and use the --skip-prompt
flag for a smoother deployment experience.Paweł Biernat
09/26/2024, 12:06 PMMarvin
09/26/2024, 12:06 PMprefect.yaml
file is present. These prompts occur when certain necessary details are missing or not specified in the prefect.yaml
.
### How to Avoid Prompts
To avoid interactive prompts, make sure all required fields are filled in the prefect.yaml
file. Here are the key sections you should ensure are completed:
1. Deployment Name and Description:
- `name`: The name of the deployment.
- `description`: A brief description of what the deployment does.
2. Flow Configuration:
- `flow`: The flow settings, including the flow's entry point.
3. Schedules (if any):
- `schedule`: Define the schedule for when the flow should run (e.g., using cron
or interval
).
4. Pull Instructions:
- `pull`: Steps to clone the repository and any submodules.
### Example of a Complete prefect.yaml
yaml
name: my-deployment
description: An example deployment
# Specify the pull step
pull:
- prefect.deployments.steps.run_shell_script:
id: clone-repo
script: |
git clone --recurse-submodules <https://your-repo.git>
cd repo
git submodule update --init --recursive
stream_output: true
# Set the working directory
- prefect.deployments.steps.set_working_directory:
id: set-working-dir
directory: repo
# Define the flow run configuration
flow:
name: my-flow
entrypoint: repo/my_flow.py:flow
# Add any additional steps needed (build, push, etc.)
build:
- prefect.deployments.steps.run_shell_script:
id: install-dependencies
script: |
pip install -r repo/requirements.txt
stream_output: true
# Define the schedule (if any)
schedule:
interval: "@daily" # Run daily
### Command to Deploy without Prompts
While there's no explicit --skip-prompt
flag, ensuring all required configurations are in the prefect.yaml
should prevent interactive prompts. Use the following command:
sh
prefect deploy
### Documentation References:
For detailed explanations, visit:
- Prefect deployment guide (2.x)
- Prefect deployment guide (3.x)
By ensuring that the prefect.yaml
is fully and correctly configured, you can reduce or eliminate the interactive prompts during deployment. If you encounter persistent prompts, it could be due to missing or incorrect configurations in the prefect.yaml
.