Skip to content

Commit

Permalink
Merge pull request #40 from navikt/quarto-support-folder
Browse files Browse the repository at this point in the history
Quarto support folder
  • Loading branch information
erikvatt authored Jan 11, 2024
2 parents a21f9f5 + 8af2405 commit 9d6bc5f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 71 deletions.
34 changes: 24 additions & 10 deletions dataverk_airflow/quarto_operator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def quarto_operator(
:param dag: DAG: owner DAG
:param name: str: Name of task
:param repo: str: Github repo
:param quarto: dict: Dict of Quarto configuration, needs the following values {"path": "path/to/index.qmd", "env": "dev/prod", "id":"uuid", "token": "quarto-token", "format": "html"}
:param quarto: dict: Dict of Quarto configuration, needs the following values {"path": "path/to/index.qmd", "folder": "path/to/folder", "env": "dev/prod", "id":"uuid", "token": "quarto-token", "format": "html"}
:param image: str: Dockerimage the pod should use
:param branch: str: Branch in repo, default "main"
:param email: str: Email of owner
Expand All @@ -59,24 +59,22 @@ def quarto_operator(

working_dir = None
try:
if quarto.get("path"):
working_dir = Path(quarto['path']).parent
else:
working_dir = Path(quarto['folder'])

if os.getenv("MARKEDSPLASSEN_HOST"):
host = os.getenv("MARKEDSPLASSEN_HOST")
elif quarto['env'] == "prod":
host = "datamarkedsplassen.intern.nav.no"
else:
host = "datamarkedsplassen.intern.dev.nav.no"

working_dir = Path(quarto['path']).parent
url = f"https://{host}/quarto/update/{quarto['id']}"
quarto_format = quarto.get('format', "html")

cmds = [
f"quarto render {Path(quarto['path']).name} --to {quarto_format} --execute --output index.html -M self-contained:True",
f"""curl --fail-with-body -X PUT -F [email protected] {url} -H "Authorization:Bearer {quarto['token']}" """
]
cmds = create_quarto_cmds(quarto, host)
except KeyError as err:
raise KeyError(
f"path, environment, id and token must be provided in the Quarto configuration. Missing {err}")
f"path or folder and environment, id and token must be provided in the Quarto configuration. Missing {err}")

allowlist.append(host)
allowlist.append("cdnjs.cloudflare.com")
Expand All @@ -91,3 +89,19 @@ def quarto_operator(

kwargs = {k: v for k, v in kwargs.items() if v is not None}
return kubernetes_operator(**kwargs)


def create_quarto_cmds(quarto: dict, host: str) -> list:
url = f"https://{host}/quarto/update/{quarto['id']}"

if quarto.get("path"):
quarto_format = quarto.get('format', "html")
return [
f"quarto render {Path(quarto['path']).name} --to {quarto_format} --execute --output index.html -M self-contained:True",
f"""curl --fail-with-body -X PUT -F [email protected] {url} -H "Authorization:Bearer {quarto['token']}" """
]
else:
return [
f"quarto render --execute --output-dir output",
f"knatch {quarto['id']} {quarto['folder']}/output {quarto['token']} --host {host}"
]
77 changes: 16 additions & 61 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ pathlib = "^1.0.1"
python = "^3.8,<3.12"
apache-airflow-providers-slack = "^8.1.0"
exceptiongroup = "^1.1.3"
knatch = "^1.0.1"

[tool.poetry.group.test.dependencies]
pyaml = "^23.9.7"
Expand Down

0 comments on commit 9d6bc5f

Please sign in to comment.