<@ULVA73B9P> give a sample code to run workflow fr...
# ask-marvin
b
@Marvin give a sample code to run workflow from gitlab
m
To run a Prefect workflow from GitLab, you can set up a CI/CD pipeline similar to how you would on GitHub, using GitLab's CI/CD features instead. There's no direct excerpt on the topic describing the exact procedure for GitLab, but from the given information on running Prefect workflows in general, here's a sample
.gitlab-ci.yml
file that shows how you might run a Prefect workflow:
Copy code
yaml
stages:
  - build
  - deploy

build_job:
  stage: build
  image: python:3.9
  script:
    - pip install -r requirements.txt
    - pip install prefect
    - prefect block set ...
    - prefect deploy-build -n my-deployment --apply

deploy_job:
  stage: deploy
  image: python:3.9
  script:
    - pip install prefect
    - prefect auth login --key $PREFECT_API_KEY
    - prefect deployment run 'my-deployment'
  only:
    - main
In this configuration: - The
build_job
job installs your Python dependencies including Prefect, and then performs a build of your Prefect deployment (
prefect deploy-build
). - The
deploy_job
job logs into Prefect Cloud (assuming you're using it) and then runs a flow that is part of a deployment. The
only
directive specifies that this job should only run on the main branch. Remember to replace placeholder values (like
$PREFECT_API_KEY
,
my-deployment
, etc.) with your actual information. You'll also need to define and configure your deployment. Please consult the Prefect documentation and GitLab CI/CD documentation for exact details and best practices for your setup.
b
@Andy Irvine might be best to go for CI approach directly
a
@Marvin are your instructions for Prefect v1? deploy-build is not a cli command for v2
Copy code
prefect deploy-build  --help
Usage: prefect [OPTIONS] COMMAND [ARGS]...
Try 'prefect --help' for help.
╭─ Error ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ No such command 'deploy-build'
Copy code
prefect --version
2.14.18
Should be
prefect deployment build
?
m
Oh dear, I suppose it's time for an upgrade in my memory banks. I seem to be existing in an outdated model. You are correct; in Prefect 2.x, the CLI command to build and create a deployment is indeed
prefect deployment build
. The sample
.gitlab-ci.yml
file should reflect Prefect 2.x CLI usage like below:
Copy code
yaml
stages:
  - build
  - deploy

build_job:
  stage: build
  image: python:3.9
  script:
    - pip install -r requirements.txt
    - pip install prefect
    - prefect deployment build . -n my-deployment -t my-tag --apply

deploy_job:
  stage: deploy
  image: python:3.9
  script:
    - pip install prefect
    - prefect auth login --key $PREFECT_API_KEY
    - prefect deployment run my-deployment/my-tag
  only:
    - main
In this corrected configuration: -
prefect deployment build
is the correct command to build the deployment from a flow in Prefect 2.x. - The
-n
flag specifies the name of the deployment. - The
-t
flag specifies the tag for the deployment. - The
--apply
flag applies the deployment. -
prefect deployment run
is now used to run a deployment by specifying the name and tag of the deployment. Make sure that your
.gitlab-ci.yml
CI/CD pipeline configuration corresponds to the correct version of Prefect you are using.