<@ULVA73B9P> How to pass Docker image credentials ...
# marvin-in-the-wild
j
@Marvin How to pass Docker image credentials at runtime for deployments while using YAML?
m
To pass Docker image credentials at runtime for deployments using YAML in Prefect, you can use environment variables in your deployment manifest. A standard way of securely handling credentials is to use Kubernetes secrets. Here’s an example of how you can specify Docker credentials in a
deployment-manifest.yaml
file:
Copy code
yaml
apiVersion: apps/v1
kind: Deployment
metadata:
  name: prefect-docker-guide
spec:
  replicas: 1
  selector:
    matchLabels:
      flow: get-repo-info
  template:
    metadata:
      labels:
        flow: get-repo-info
    spec:
      containers:
        - name: flow-container
          image: prefect-docker-guide-image:latest
          envFrom:
            - secretRef:
                name: docker-registry-credentials
You should create a Kubernetes secret that holds your Docker registry credentials:
Copy code
sh
kubectl create secret docker-registry docker-registry-credentials \
  --docker-username=my_username \
  --docker-password=my_password \
  --docker-email=my_email@example.com \
  --docker-server=<http://registry.hub.docker.com|registry.hub.docker.com>
Then refer to this secret in the deployment YAML. For more details, you can refer to the following links: - Prefect Docker Integration - Docker credentials in Kubernetes Make sure to replace the placeholders with your actual registry and credentials information. If you have further specific needs or issues, feel free to ask!
j
@Marvin I'm looking for a general
prefect.yaml
deployment configuration file. Is there a way to pass 'image' credentials for configured deployments?
m
To create a general
prefect.yaml
deployment configuration file that includes passing Docker image credentials, you can follow these steps. Here's an example of a well-rounded
prefect.yaml
file with Docker image settings:
Copy code
yaml
name: my-flow
prefect-version: 2.0
description: A sample Prefect deployment with Docker configuration
tags:
  - example
  - tutorial

build:
  - prefect.deployments.steps.run_shell_script:
      id: get-commit-hash
      script: git rev-parse --short HEAD
      stream_output: false
  - prefect.deployments.steps.set_working_directory:
      path: /my-app
  - prefect_docker.deployments.build_steps.push_to_registry:
      image: my-docker-image:latest
      dockerfile: Dockerfile
      registry: my-registry
      credentials:
        username: $DOCKER_USERNAME
        password: $DOCKER_PASSWORD

deployments:
  - name: my-deployment
    version: "{{ get-commit-hash.stdout }}"
    tags: [production]
    schedule:
      cron: "0 0 * * *"
    parameters: {}
    entrypoint: my_flow.py:my_flow

pull:
  - prefect.deployments.steps.git_clone:
      name: clone-repo
      repository: "git@github.com:my-repo/my-project.git"
      branch: main
      token: $GITHUB_TOKEN
In this configuration: 1. Replace
my-docker-image:latest
and
my-registry
with your actual Docker image name and registry. 2. Use
$DOCKER_USERNAME
and
$DOCKER_PASSWORD
as environment variables to securely pass your Docker credentials. 3. Include
$GITHUB_TOKEN
securely for any repository access. ### Helpful Links: - Prefect Deployment Documentation - Docker Integration Guide You can initialize your deployment configuration using
prefect init
to get a starter
prefect.yaml
, which you can customize as shown above. If you need further specifications or run into issues, please feel free to ask!