Wilson Bilkovich
08/29/2021, 7:17 PMWilson Bilkovich
08/29/2021, 7:18 PM- name: PREFECT__CONTEXT__SECRETS__GITHUB_TOKEN
value: "redacted"
in the agent deployment env config, but no secret named ‘github_token’ seems to be available when flows runKevin Kho
"PREFECT__CLOUD__USE_LOCAL_SECRETS" = "true"
Wilson Bilkovich
08/30/2021, 12:43 AMKevin Kho
Wilson Bilkovich
08/30/2021, 12:53 AMValueError: Secrets should only be retrieved during a Flow run, not while building a Flow.
Wilson Bilkovich
08/30/2021, 12:54 AMKevin Kho
my_secret_value = Secret("MYSECRET").get()
outside the flow?Wilson Bilkovich
08/30/2021, 1:01 AMWilson Bilkovich
08/30/2021, 1:01 AM+ exec prefect execute flow-run
[2021-08-30 01:01:06+0000] INFO - prefect.GitHub | Downloading flow from GitHub storage - repo: 'Addepar/comparch-ng', path: 'addemart/src/addemart/__main__.py', ref: 'wlb/prefect-demo'
Local Secret "github_token" was not found.
Traceback (most recent call last):
File "/opt/conda/bin/prefect", line 8, in <module>
sys.exit(cli())
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 829, in __call__
return self.main(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 782, in main
rv = self.invoke(ctx)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1259, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 1066, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/opt/conda/lib/python3.8/site-packages/click/core.py", line 610, in invoke
return callback(*args, **kwargs)
File "/opt/conda/lib/python3.8/site-packages/prefect/cli/execute.py", line 96, in flow_run
raise exc
File "/opt/conda/lib/python3.8/site-packages/prefect/cli/execute.py", line 73, in flow_run
flow = storage.get_flow(flow_data.name)
File "/opt/conda/lib/python3.8/site-packages/prefect/storage/github.py", line 94, in get_flow
client = self._get_github_client()
File "/opt/conda/lib/python3.8/site-packages/prefect/storage/github.py", line 161, in _get_github_client
access_token = Secret(self.access_token_secret).get()
File "/opt/conda/lib/python3.8/site-packages/prefect/client/secrets.py", line 140, in get
raise ValueError(
ValueError: Local Secret "github_token" was not found.
Wilson Bilkovich
08/30/2021, 1:02 AMclient = prefect.Client()
token = os.environ.get("PREFECT__CONTEXT__SECRETS__GITHUB_TOKEN", Secret("github_token").get())
client.set_secret(name="github_token", value=token)
Kevin Kho
Kevin Kho
Kevin Kho
Wilson Bilkovich
08/30/2021, 1:17 AMWilson Bilkovich
08/30/2021, 1:23 AM--env PREFECT_FOO_BAZ="value"
to the agent startup commandWilson Bilkovich
08/30/2021, 1:23 AMKevin Kho
Wilson Bilkovich
08/30/2021, 1:28 AMWilson Bilkovich
08/30/2021, 1:28 AMWilson Bilkovich
08/30/2021, 1:29 AMdef _worker_env() -> Dict[str, str]:
env = {
"EXTRA_PIP_PACKAGES": "prefect[kubernetes,github] dask-kubernetes",
"MYSQL_HOST": "redacted",
"ON_AWS": "1",
"POSTGRES_HOST": "redacted",
"PREFECT__CLOUD__USE_LOCAL_SECRETS": "true",
"PREFECT__CONTEXT__SECRETS__GITHUB_TOKEN": "redacted",
"TZ": "UTC",
}
return env
Wilson Bilkovich
08/30/2021, 1:30 AMKevin Kho
--env PREFECT__CONTEXT__SECRETS__GITHUB_TOKEN=xxxx
should work. I can give it a try later on a Kubernetes agent.Kevin Kho
Kevin Kho
Wilson Bilkovich
08/30/2021, 3:30 AMWilson Bilkovich
08/30/2021, 3:31 AMWilson Bilkovich
08/30/2021, 1:04 PMWilson Bilkovich
08/30/2021, 1:05 PM+ exec prefect execute flow-run
[2021-08-30 03:36:31+0000] INFO - prefect.GitHub | Downloading flow from GitHub storage - repo: 'Addepar/comparch-ng', path: 'addemart/src/addemart/__main__.py', ref: 'wlb/prefect-demo'
[2021-08-30 03:36:31+0000] INFO - prefect.GitHub | Flow successfully downloaded. Using commit: 1823a38bf6e1140a4fe10173e39e4a30363a8ce4
No module named 'addemart'
Traceback (most recent call last):
File "/opt/conda/bin/prefect", line 8, in <module>
sys.exit(cli())
...
File "/opt/conda/lib/python3.8/site-packages/prefect/storage/github.py", line 128, in get_flow
return extract_flow_from_file(
File "/opt/conda/lib/python3.8/site-packages/prefect/utilities/storage.py", line 88, in extract_flow_from_file
exec(contents, exec_vals)
File "<string>", line 31, in <module>
ModuleNotFoundError: No module named 'addemart'
Wilson Bilkovich
08/30/2021, 1:06 PMaddemart
is the name of the module that registers and runs the flows. Normally it would be `pip install`’d from the checkout dir.Wilson Bilkovich
08/30/2021, 1:06 PMKevin Kho
addemart
on the Dask workers? How do you download it?Wilson Bilkovich
08/30/2021, 2:50 PMWilson Bilkovich
08/30/2021, 2:50 PMpip install --editable ${CURDIR}[dev,test]
Wilson Bilkovich
08/30/2021, 2:51 PMpip install .
would do it on a worker I thinkWilson Bilkovich
08/30/2021, 2:51 PMsetup.py
Kevin Kho
GitHub
storage only pulls the Flow file and not other files that get imported. You might need Docker storage to hold that dependency and to pip install .
when building the Docker container. Git
storage pulls the whole repo but it is not intended to be pip installed
like that. It’s more for holding .sql
files or .yaml
files your flow may use.
I think the flow is running Python process already and you’d need to restart it to have the pip install
take effect right?Wilson Bilkovich
08/30/2021, 2:56 PMWilson Bilkovich
08/30/2021, 2:59 PMWilson Bilkovich
08/30/2021, 3:00 PMpullSecrets
? The Agent? Or is that Dask's KubeCluster handling that?Kevin Kho