Fabio Machado
09/18/2024, 8:18 PMMarvin
09/18/2024, 8:18 PMpython
   from prefect.filesystems import DockerRegistry
   from prefect.blocks.system import Secret
   # Save your credentials as secrets
   user_secret = Secret(value="your-username")
   password_secret = Secret(value="your-password")
   # Create a DockerRegistry block with your DockerHub credentials
   docker_registry_block = DockerRegistry(
       username=user_secret,
       password=password_secret,
       registry_url="<https://index.docker.io/v1/>"
   )
   docker_registry_block.save(name="my-dockerhub-credentials", overwrite=True)loadpython
   from prefect import flow
   from prefect.filesystems import DockerRegistry
   from prefect.blocks.system import Secret
   @flow
   def my_flow():
       # Load the DockerRegistry block
       docker_registry_block = DockerRegistry.load("my-dockerhub-credentials")
       
       # Use the credentials as needed
       username = docker_registry_block.username.get()
       password = docker_registry_block.password.get()
       print(f"Using DockerHub credentials - Username: {username}")
   if __name__ == "__main__":
       my_flow()Fabio Machado
09/18/2024, 8:24 PMFabio Machado
09/18/2024, 8:26 PMMarvin
09/18/2024, 8:26 PMDockerRegistrypython
   from prefect.deployments import Deployment
   from prefect.infrastructure import DockerContainer
   from prefect.infrastructure.docker import DockerRegistry
   from prefect import flow
   @flow
   def my_flow():
       print("Flow is running!")
   # Load the DockerRegistry block
   docker_registry_block = DockerRegistry.load("my-dockerhub-credentials")
   # Define the DockerContainer infrastructure
   docker_container = DockerContainer(
       image="my-docker-image:latest",
       registry_url=docker_registry_block.registry_url,
       registry_username=docker_registry_block.username.get(),
       registry_password=docker_registry_block.password.get(),
   )
   # Create a deployment with the defined Docker configuration
   deployment = Deployment.build_from_flow(
       flow=my_flow,
       name="my-docker-deployment",
       infrastructure=docker_container,
       skip_build=False,  # This will build and push the image
   )
   # Apply the deployment
   deployment.apply()python
   if __name__ == "__main__":
       from prefect.client import OrionClient
       client = OrionClient()
       deployment.run(client)DockerRegistryDockerRegistry