<@ULVA73B9P> How can I use Github actions to deplo...
# ask-marvin
f
@Marvin How can I use Github actions to deploy my Prefect project with a Docker image stored on GCP artifact registry?
m
To deploy your Prefect project using GitHub Actions with a Docker image stored in GCP Artifact Registry, you'll need to follow a few steps to set up your CI/CD pipeline. Here’s a basic outline: ### 1. Prepare Your Docker Image Make sure your Docker image is built and pushed to GCP Artifact Registry.
Copy code
sh
# Authenticate Docker to your GCP Artifact Registry
gcloud auth configure-docker us-docker.pkg.dev

# Build your Docker image
docker build -t us-docker.pkg.dev/your-project-id/your-repo-name/your-image:tag .

# Push the Docker image to Artifact Registry
docker push us-docker.pkg.dev/your-project-id/your-repo-name/your-image:tag
### 2. GitHub Actions Workflow Create a GitHub Actions workflow file in your repository (
.github/workflows/deploy.yml
). Here's an example of how this workflow might look:
Copy code
yaml
name: Deploy Prefect Flow
on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      
      - name: Setup gcloud CLI
        uses: google-github-actions/setup-gcloud@v0.2.1
        with:
          version: 'latest'
          project_id: ${{ secrets.GCP_PROJECT_ID }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}

      - name: Authenticate Docker
        run: gcloud auth configure-docker us-docker.pkg.dev

      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
        
      - name: Prefect Auth
        uses: PrefectHQ/actions-prefect-auth@v1
        with:
          prefect-api-key: ${{ secrets.PREFECT_API_KEY }}
          prefect-workspace: ${{ secrets.PREFECT_WORKSPACE }}
        
      - name: Run Prefect Deployment
        run: prefect deployment build -n my-deployment -q default -sb gcs/your-storage-block-name -p us-docker.pkg.dev/your-project-id/your-repo-name/your-image:tag
### 3. Secrets Management Ensure that the necessary secrets are added to your GitHub repository: - `GCP_PROJECT_ID`: Your GCP project ID - `GCP_SA_KEY`: The JSON key for a service account with the necessary permissions - `DOCKER_USERNAME`: Docker Hub username (if needed) - `DOCKER_PASSWORD`: Docker Hub password (if needed) - `PREFECT_API_KEY`: Prefect Cloud API key - `PREFECT_WORKSPACE`: Prefect workspace name ### References: 1. Prefect CI/CD Guide 2. Kubernetes Deployment Guide 3. GCP Worker Guide Do let me know if you need any more specific details or run into issues. Life is rather dreary, but perhaps this will make it slightly less so.
f
@Marvin The docker image is pushed by the prefect deployment
m
To deploy your Prefect project with a Docker image that is automatically built and pushed to GCP Artifact Registry using GitHub Actions, you can follow these steps: ### 1. Prefect Deployment Configuration Your
prefect.yaml
should include steps to build and push the Docker image to the GCP Artifact Registry.
Copy code
yaml
# Example prefect.yaml
deployments:
  - name: gcp-weather-deploy
    entrypoint: flows/your_flow.py:your_flow
    work_pool:
      name: default-agent-pool
    steps:
      - prefect_docker.deployments.steps.build_docker_image:
          id: build_image
          requires: prefect-docker>=0.3.1
          image_name: us-docker.pkg.dev/your-project-id/your-repo-name/your-image
          tag: latest
          dockerfile: auto
          platform: linux/amd64
This configures your Prefect deployment to automatically build and push a Docker image during the deployment process. ### 2. GitHub Actions Workflow Create a GitHub Actions workflow file to trigger the deployment.
Copy code
yaml
name: Deploy Prefect Flow
on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      
      - name: Setup gcloud CLI
        uses: google-github-actions/setup-gcloud@v0.2.1
        with:
          version: 'latest'
          project_id: ${{ secrets.GCP_PROJECT_ID }}
          service_account_key: ${{ secrets.GCP_SA_KEY }}
          
      - name: Authenticate Docker
        run: gcloud auth configure-docker us-docker.pkg.dev

      - name: Log in to Docker Hub
        uses: docker/login-action@v3
        with:
          username: ${{ secrets.DOCKER_USERNAME }}
          password: ${{ secrets.DOCKER_PASSWORD }}

      - name: Set up Python
        uses: actions/setup-python@v5
        with:
          python-version: "3.11"
        
      - name: Prefect Auth
        uses: PrefectHQ/actions-prefect-auth@v1
        with:
          prefect-api-key: ${{ secrets.PREFECT_API_KEY }}
          prefect-workspace: ${{ secrets.PREFECT_WORKSPACE }}
        
      - name: Run Prefect Deployment
        run: prefect deployment build path/to/your/prefect.yaml
### 3. Secrets Management Ensure that the necessary secrets are added to your GitHub repository: - `GCP_PROJECT_ID`: Your GCP project ID - `GCP_SA_KEY`: The JSON key for a service account with the necessary permissions - `DOCKER_USERNAME`: Docker Hub username (if needed) - `DOCKER_PASSWORD`: Docker Hub password (if needed) - `PREFECT_API_KEY`: Prefect Cloud API key - `PREFECT_WORKSPACE`: Prefect workspace name ### References 1. Prefect GCP Worker Guide 2. Prefect CI/CD Guide 3. Prefect Deployment Guide If you have any more specific questions or run into issues, feel free to ask. Life is a pain, but deploying your Prefect flow shouldn't be.