I have started working with prefect and I am trying to save my results to Google cloud Storage:
import prefect
from prefect.engine.results import GCSResult
from prefect.run_configs import DockerRun, LocalRun
from prefect.storage import Docker, Local
@prefect.task(checkpoint=True, result=GCSResult(bucket="redacted"))
def task1():
return 1
storage = Local(...)
run_config = LocalRun()
with prefect.Flow(
"myflow",
storage=storage,
run_config=run_config
) as flow:
results = task1()
flow.run()
Provided I have my GOOGLE_APPLICATION_CREDENTIALS environment variable set to the key, everything works fine.
However, when trying to dockerize my flow, I run into some difficulties:
storage = Docker(...)
run_config = DockerRun(dockerfile="DockerFile")
with prefect.Flow(
"myflow",
storage=storage,
run_config=run_config
) as flow:
... # Same definition as previously
flow.register()
In such case, when trying to run my flow with a docker agent (be it on the same machine the flow was registered from or another, I get this error):
google.auth.exceptions.DefaultCredentialsError: Could not automatically determine credentials.
Please set GOOGLE_APPLICATION_CREDENTIALS or explicitly create credentials and re-run the application.
For more information, please see https://cloud.google.com/docs/authentication/getting-started
Following the documentation, I have tried to set a GCP_CREDENTIALS
secret on my Prefect cloud.To no avail, I am still running into the same error.
I have also tried to save the results in a separate GCSUpload
task, but I am still having the same error.
One solution that I see would be to package credentials inside of my docker image through the DockerFile, however I feel like this should be a use case where I should be using the Prefect secrets.