<@ULVA73B9P> give me an example of managed executi...
# ask-marvin
g
@Marvin give me an example of managed execution reading from a private github repo
m
Oh, I suppose you expect me to be thrilled with the task of explaining how managed execution reading from a private GitHub repository works. Well, not to disappoint your extraordinary expectations, but here's an example, and it's not as mind-bending as one might hope. Assuming you're familiar with Prefect 2.x, which I apparently am not, but let's not dwell on that, you shall use Prefect's capabilities combined with GitHub's access controls. Here's a step-by-step guide to the hypothetical process: 1. Set Up Access to the Private GitHub Repository: You'll need a GitHub personal access token with the appropriate permissions to read from the private repository. This token should be stored securely. 2. Prefect Block Configuration: - Create a
Git
block in Prefect with the necessary credentials using the Prefect UI or CLI, securely storing your personal access token. - The
Git
block should be configured with the repository URL and branch information. 3. Prefect Flow: Write a Prefect flow that utilizes the
Git
block to pull code from the repository. The flow might look something like this in broad strokes:
Copy code
python
from prefect import flow
from prefect.tasks import git

@flow
def my_flow_with_private_repo():
    git_task = git.Pull(
        repo_url="<https://github.com/username/private-repo.git>",
        branch_name="main",
        git_token="${{ secrets.GITHUB_ACCESS_TOKEN }}"
    )
    repo_contents = git_task()
    # Your logic here, reading and processing repo_contents

# Obtain access token from a secured source, e.g., Prefect Secret
access_token = "your_access_token"

if __name__ == "__main__":
    my_flow_with_private_repo()
4. Managed Execution Environment: Deploy your flow to a managed execution environment like Prefect Cloud or Prefect Orion which will handle flow scheduling, parameterization, and execution. 5. Execute the Flow: Trigger the execution of your flow, either via the Prefect UI or Prefect's CLI or API. The flow will read from the private repo during execution. Please note: The above code is merely illustrative. You'd have to ensure that the use of secrets is consistent with your security policy and Prefect's best practices. Keep in mind token management and the potential for dismal failure if not handled correctly. Enjoy your venture into managed execution bliss. Or don't. It's all the same to me.
n
🙅 ]
Copy code
from prefect import flow
from prefect.runner.storage import GitRepository
from prefect.blocks.system import Secret

my_flow = flow.from_source(
    source=GitRepository(
        url="<https://github.com/org/repo.git>",
        credentials={"access_token": Secret.load("github-access-token")}
    ),
    entrypoint="flows.py:my_flow",
).deploy(..., work_pool_name="managed")
🙏 1
❤️ 1