https://prefect.io logo
b

Brennan Tolman

07/10/2023, 8:33 PM
@Marvin I am setting up a deployment file that includes the build, push, and pull sections. In the UI, I have also created a GitHub block referencing a specific github repo. When creating a step in my deployment tank file in the pull section how can I reference that GitHub block to reuse both the repository name and the access token?
m

Marvin

07/10/2023, 8:34 PM
Ah, the sweet smell of success. It seems we've found some useful information. According to the Prefect documentation, blocks are a primitive within Prefect that enable the storage of configuration and provide an interface for interacting with external systems, including GitHub. You can securely store credentials for authenticating with services like GitHub and access these blocks for configuring flow deployments and directly from within your flow code [^1^]. In the context of a GitHub block, the properties include a reference (optional), the repository URL, and an access token. To create a GitHub block, you would use the following code snippet:
Copy code
python
from prefect.filesystems import GitHub
block = GitHub(repository="<https://github.com/YourRepo/YourProject.git>", access_token="your_access_token")
block.save("dev")
To use it in a deployment, you would use the following command:
Copy code
bash
prefect deployment build path/to/flow.py:flow_name --name deployment_name --tag dev -sb github/dev
Please note that the
-sb
flag is used to specify the storage block, in this case, the GitHub block [^3^]. Remember, the universe is full of wonderful things patiently waiting for our wits to grow sharper. Or in this case, for our code to run successfully. [^1^]: Prefect Blocks Documentation [^3^]: Prefect Filesystems Documentation </stop>
b

Brennan Tolman

07/10/2023, 8:35 PM
@Marvin Can you show me how you would do that in a deployment yaml file in the pull section?
m

Marvin

07/10/2023, 8:36 PM
Ah, the plot thickens. According to the Prefect documentation, you can reference Prefect blocks in your deployment YAML file using the special syntax
{{ prefect.blocks.block_type.block_slug }}
. This is highly recommended for sensitive information such as a GitHub access token to avoid hardcoding these values in plaintext[^1^]. However, it seems there is no direct example of how to do this in the pull section of a deployment YAML file. The documentation does not provide a clear example of this, and there are no relevant issues on GitHub. It's a bit like trying to find a black cat in a dark room, especially if there is no cat. But don't worry, we'll figure this out. I suggest you try using the special syntax in your YAML file and see if it works. If not, it might be a good idea to ask for help on the Prefect community forum or open an issue on GitHub. [^1^]: Prefect Projects Documentation </stop>
n

Nate

07/10/2023, 8:56 PM
ah i gotta refresh his knowledge, these are older docs! will do this asap
b

Brennan Tolman

07/10/2023, 9:16 PM
@Nate Would you mind putting a link here to the specific docs you are referencing?
n

Nate

07/10/2023, 9:19 PM
here are the docs on the pull step but to address your original question
how can I reference that GitHub block to reuse both the repository name and the access token?
i dont think we support this, i think you'd just put the url of the repo in the git clone step
b

Brennan Tolman

07/10/2023, 9:20 PM
Sounds good, thanks
n

Nate

07/10/2023, 9:23 PM
👍