https://prefect.io logo
Title
a

aaron

02/03/2023, 1:13 AM
hi prefect community! when working with deployments using different infrastructure/storage blocks, is the recommended best practice to just build separate deployment.yamls for each use-case? or is there a way to conditionally apply blocks based on something like environment or workspace?
j

James Sopkin

02/03/2023, 3:50 PM
Hi @aaron my favorite way to conditionally apply blocks would be with GitHub actions! You can configure different jobs to use a different
deployment build
command based on which branch you are in. Otherwise there are many other CI/CD options you can use
a

aaron

02/03/2023, 5:01 PM
Thanks @James Sopkin! How would one conditionally apply blocks using pure Prefect? Is it possible to define multiple blocks in a single deployment file and use them conditionally? Using Github Actions is fine but what about a local env?
j

James Sopkin

02/03/2023, 5:19 PM
Hey Aaron, so here's an example that I used before
- if: github.ref == 'refs/heads/main'
        name: Build and apply Prefect deployment
        run: prefect deployment build $FILEPATH -n ${{ matrix.name }} ${{ matrix.schedule }} ${{ matrix.params }} -sb $STORAGE -ib $INFRA -q prod --apply
      - if: github.ref != 'refs/heads/main'
        name: Build and apply Prefect deployment
        run: prefect deployment build $FILEPATH -n ${{ matrix.name }} ${{ matrix.params }} -sb $STORAGE -ib $INFRA -q dev --apply
I would include logic to build out a different deployment for dev and prod and passed in parameters, storage, schedule and infra blocks
a

aaron

02/03/2023, 5:28 PM
This is very handy, thank you!
j

James Sopkin

02/03/2023, 5:30 PM
You’re welcome!