I'm trying to set up CI to build and apply deploym...
# prefect-community
k
I'm trying to set up CI to build and apply deployments via GitHub Actions, but the process fails after the login command:
Copy code
EOFError EOF when reading a line
Creating a profile for this Prefect Cloud login. Please specify a profile name: An exception occurred.
Error: Process completed with exit code 1.
I don't think it's possible for me to respond to a prompt like that via Actions. Is there a way around this?
1
I've tried creating and activating a profile and then logging in, but I get the same outcome
k
What are the commands you used on CI?
k
Copy code
jobs:
  deploy:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v3
      - name: Set up Python 3.9
        uses: actions/setup-python@v3
        with:
          python-version: 3.9
      - name: Dev dependencies
        run: |
          pip install prefect
      - name: Login to Prefect Cloud 2.0
        env:
          PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
        run: prefect cloud login --key $PREFECT_API_KEY --workspace <my-workspace>
      - name: Validate Prefect version
        run: prefect version
      - name: Authenticate to GCP
        uses: 'google-github-actions/auth@v0.7.1'
        with:
          workload_identity_provider: <my-workload-identity-provider>
          service_account: <my-service-account>
      - name: Create deployment file
        run: prefect deployment build ./flow.py:iowa_contribs -n demo-iowa -t demo -sb gcs/gcs-bucket-access
      - name: Run deployment
        run: prefect deployment apply deployment.yaml
k
on which command you got the error?
k
run: prefect cloud login --key $PREFECT_API_KEY --workspace <my-workspace>
I think specifically because it's prompting me to input a profile name
Copy code
Traceback (most recent call last):
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/prefect/cli/_utilities.py", line 41, in wrapper
    return fn(*args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 193, in wrapper
    return run_async_in_new_loop(async_fn, *args, **kwargs)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/prefect/utilities/asyncutils.py", line 140, in run_async_in_new_loop
    return anyio.run(partial(__fn, *args, **kwargs))
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/anyio/_core/_eventloop.py", line 70, in run
    return asynclib.run(func, *args, **backend_options)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 292, in run
    return native_run(wrapper(), debug=debug)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/asyncio/base_events.py", line 647, in run_until_complete
    return future.result()
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 287, in wrapper
    return await func(*args)
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/prefect/cli/cloud.py", line 293, in login
    cloud_profile_name = app.console.input(
  File "/opt/hostedtoolcache/Python/3.9.13/x64/lib/python3.9/site-packages/rich/console.py", line 2079, in input
    result = input()
EOFError: EOF when reading a line
Creating a profile for this Prefect Cloud login. Please specify a profile name: An exception occurred.
Error: Process completed with exit code 1.
hmm I think I have an idea
from looking here, I can set the
PREFECT_API_KEY
on the current profile, then login, and it'll exit without prompting me for a profile name
I'll give it a try
k
hmm it’s weird. Just to make sure, you replace
<my-workspace>
in here:
Copy code
prefect cloud login --key $PREFECT_API_KEY --workspace <my-workspace>
with the name of your workspace right?
k
yeah, anything with <> I just removed before posting
getting closer. looks like I need to set the API URL as well
yep. that works
you must
prefect config set PREFECT_API_KEY=<your-key>
and
prefect config set PREFECT_API_URL=<your-url>
in the CI job or the login will prompt for user input
k
interesting
not sure why
you shouldn’t need to do
prefect config set
k
when you try to login from the CLI, it checks all your profiles for the presence of an api key and url
if they're there, you'll just get a success message after the login. if not, it'll prompt you to create a profile then assign the key and workspace->url to that new profile
k
I see. I’m that it works for you. Thanks for the snippet
I’ll write this down to make it available to other users
k
thanks! I figured there might be documentation on CI steps coming soon anyway, I'm just impatient 😛
b
We had this same issue. Prefect 2.0 makes you create a profile when you log into the cloud, rather than use the default profile. This is what we did to set a profile name in Github Actions:
- name: run prefect
run: |-
echo 'my-profile' | prefect cloud login --key ${{ secrets.PREFECT_CLOUD_API_KEY }} -w "$PREFECT_WORKSPACE"
a
For CI you should instead set environment variables corresponding to your PREFECT_API_KEY and PREFECT_API_URL - with those two environment variables you won't have to login interactively and create a profile
🙏 1
b
Ok, thanks @Anna Geller. That's not ideal because then I need to hardcode the prefect account number and workspace id. It seems less error prone to let the CLI autogenerate the PREFECT_API_URL from my PREFECT_API_KEY. Is there a reason you are suggesting that we not use the CLI here? I already use the CLI in a bash script to create the work-queue, apply the deployment, and run an agent. Thanks for the help.
a
why hardcode? you should store those as your CI secrets
b
True. Not trying the nitpick the awesomeness of Prefect. My suggestion is that the CLI always have a non-interactive option. Sort of like the --quiet option on Google Cloud CLI (https://cloud.google.com/sdk/gcloud)
k
so if I'm understanding correctly, if we set the key and url env vars, we can skip the login command entirely?
a
yes exactly Kevin, no need for the login command with env vars
@Benny Warlick why do you think giving output is bad? we could for sure add some flag to not give any output but I believe it's always useful and even recommended to have more info about what has just been created or deployed, or not?
only the cloud login command is interactive, everything else just prints some info to the terminal which seems expected
k
ty anna, I tried this yesterday and it worked perfectly, no login needed
Copy code
- name: Run deployment
  env:
    PREFECT_API_KEY: ${{ secrets.PREFECT_API_KEY }}
    PREFECT_API_URL: ${{ secrets.PREFECT_API_URL }}
        run: prefect deployment apply my_flow-deployment.yaml
🙂
🎉 1
k
You can checkout this Discourse thread for other recipes for CI/CD in 2.0