diff --git a/docs/canonicalk8s/.gitignore b/docs/canonicalk8s/.gitignore index 25a54f038..da6f688f1 100644 --- a/docs/canonicalk8s/.gitignore +++ b/docs/canonicalk8s/.gitignore @@ -1,6 +1,5 @@ /*env*/ .sphinx/venv/ -.sphinx/requirements.txt .sphinx/warnings.txt .sphinx/.wordlist.dic .sphinx/.doctrees/ diff --git a/docs/canonicalk8s/.readthedocs.yaml b/docs/canonicalk8s/.readthedocs.yaml index c6319b57f..6f30701e6 100644 --- a/docs/canonicalk8s/.readthedocs.yaml +++ b/docs/canonicalk8s/.readthedocs.yaml @@ -18,23 +18,26 @@ build: # If there are no changes (git diff exits with 0) we force the command to return with 183. # This is a special exit code on Read the Docs that will cancel the build immediately. - | + git fetch --unshallow || true if [ "$READTHEDOCS_VERSION_TYPE" = "external" ] && git diff --quiet origin/main -- docs/ .readthedocs.yaml; then exit 183; fi - + ls # Build documentation in the docs/ directory with Sphinx sphinx: builder: dirhtml - configuration: docs/canonicalk8s/conf.py + configuration: docs/canonicalk8s/conf-rtd.py # If using Sphinx, optionally build your docs in additional formats such as PDF -formats: - - pdf +# formats: +# - pdf # Optionally declare the Python requirements required to build your docs python: install: - requirements: docs/canonicalk8s/.sphinx/requirements.txt + + diff --git a/docs/canonicalk8s/.sphinx/requirements.txt b/docs/canonicalk8s/.sphinx/requirements.txt new file mode 100644 index 000000000..f7ac84204 --- /dev/null +++ b/docs/canonicalk8s/.sphinx/requirements.txt @@ -0,0 +1,23 @@ +# DO NOT MODIFY THIS FILE DIRECTLY! +# +# This file is generated automatically. +# Add custom requirements to the custom_required_modules +# array in the custom_conf.py file and run: +# make clean && make install +GitPython +canonical-sphinx-extensions +furo +linkify-it-py +myst-parser +pyspelling +sphinx +sphinx-autobuild +sphinx-copybutton +sphinx-design +sphinx-notfound-page +sphinx-tabs +sphinxcontrib-jquery +sphinxcontrib-svg2pdfconverter[CairoSVG] +sphinxcontrib.kroki +sphinxext-opengraph +watchfiles diff --git a/docs/canonicalk8s/Makefile.sp b/docs/canonicalk8s/Makefile.sp index 4dbfba2bd..6b98451f5 100644 --- a/docs/canonicalk8s/Makefile.sp +++ b/docs/canonicalk8s/Makefile.sp @@ -9,7 +9,7 @@ SPHINXDIR = .sphinx SPHINXOPTS ?= -c . -d $(SPHINXDIR)/.doctrees -j auto SPHINXBUILD ?= sphinx-build -SOURCEDIR = src +SOURCEDIR = . METRICSDIR = ./metrics BUILDDIR = ../_build VENVDIR = $(SPHINXDIR)/venv diff --git a/docs/canonicalk8s/conf-rtd.py b/docs/canonicalk8s/conf-rtd.py new file mode 100644 index 000000000..05d127f0d --- /dev/null +++ b/docs/canonicalk8s/conf-rtd.py @@ -0,0 +1,254 @@ +import sys +import os +import requests +from urllib.parse import urlparse +from git import Repo, InvalidGitRepositoryError +import time +import ast +import yaml + +sys.path.append('./') +from custom_conf import * +sys.path.append('.sphinx/') +from build_requirements import * + +# Configuration file for the Sphinx documentation builder. +# You should not do any modifications to this file. Put your custom +# configuration into the custom_conf.py file. +# If you need to change this file, contribute the changes upstream. +# +# For the full list of built-in configuration values, see the documentation: +# https://www.sphinx-doc.org/en/master/usage/configuration.html + +############################################################ +### Extensions +############################################################ + +extensions = [ + 'sphinx_design', + 'sphinx_copybutton', + 'sphinxcontrib.jquery', +] + +# Only add redirects extension if any redirects are specified. +if AreRedirectsDefined(): + extensions.append('sphinx_reredirects') + +# Only add myst extensions if any configuration is present. +if IsMyStParserUsed(): + extensions.append('myst_parser') + + # Additional MyST syntax + myst_enable_extensions = [ + 'substitution', + 'deflist', + 'linkify' + ] + myst_enable_extensions.extend(custom_myst_extensions) + +# Only add Open Graph extension if any configuration is present. +if IsOpenGraphConfigured(): + extensions.append('sphinxext.opengraph') + +extensions.extend(custom_extensions) +extensions = DeduplicateExtensions(extensions) + +### Configuration for extensions + +# Used for related links +if not 'discourse_prefix' in html_context and 'discourse' in html_context: + html_context['discourse_prefix'] = html_context['discourse'] + '/t/' + +# The URL prefix for the notfound extension depends on whether the documentation uses versions. +# For documentation on documentation.ubuntu.com, we also must add the slug. +url_version = '' +url_lang = '' + +# Determine if the URL uses versions and language +if 'READTHEDOCS_CANONICAL_URL' in os.environ and os.environ['READTHEDOCS_CANONICAL_URL']: + url_parts = os.environ['READTHEDOCS_CANONICAL_URL'].split('/') + + if len(url_parts) >= 2 and 'READTHEDOCS_VERSION' in os.environ and os.environ['READTHEDOCS_VERSION'] == url_parts[-2]: + url_version = url_parts[-2] + '/' + + if len(url_parts) >= 3 and 'READTHEDOCS_LANGUAGE' in os.environ and os.environ['READTHEDOCS_LANGUAGE'] == url_parts[-3]: + url_lang = url_parts[-3] + '/' + +# Set notfound_urls_prefix to the slug (if defined) and the version/language affix +if slug: + notfound_urls_prefix = '/' + slug + '/' + url_lang + url_version +elif len(url_lang + url_version) > 0: + notfound_urls_prefix = '/' + url_lang + url_version +else: + notfound_urls_prefix = '' + +notfound_context = { + 'title': 'Page not found', + 'body': '

Sorry, but the documentation page that you are looking for was not found.

\n\n

Documentation changes over time, and pages are moved around. We try to redirect you to the updated content where possible, but unfortunately, that didn\'t work this time (maybe because the content you were looking for does not exist in this version of the documentation).

\n

You can try to use the navigation to locate the content you\'re looking for, or search for a similar page.

\n', +} + +# Default image for OGP (to prevent font errors, see +# https://github.com/canonical/sphinx-docs-starter-pack/pull/54 ) +if not 'ogp_image' in locals(): + ogp_image = 'https://assets.ubuntu.com/v1/253da317-image-document-ubuntudocs.svg' + +############################################################ +### General configuration +############################################################ + +exclude_patterns = [ + '_build', + 'Thumbs.db', + '.DS_Store', + '.sphinx', +] +exclude_patterns.extend(custom_excludes) + +rst_epilog = ''' +.. include:: /reuse/links.txt +''' +if 'custom_rst_epilog' in locals(): + rst_epilog = custom_rst_epilog + +source_suffix = { + '.rst': 'restructuredtext', + '.md': 'markdown', +} + +if not 'conf_py_path' in html_context and 'github_folder' in html_context: + html_context['conf_py_path'] = html_context['github_folder'] + +# For ignoring specific links +linkcheck_anchors_ignore_for_url = [ + r'https://github\.com/.*' +] +linkcheck_anchors_ignore_for_url.extend(custom_linkcheck_anchors_ignore_for_url) + +# Tags cannot be added directly in custom_conf.py, so add them here +for tag in custom_tags: + tags.add(tag) + +# html_context['get_contribs'] is a function and cannot be +# cached (see https://github.com/sphinx-doc/sphinx/issues/12300) +suppress_warnings = ["config.cache"] + +############################################################ +### Styling +############################################################ + +# Find the current builder +builder = 'dirhtml' +if '-b' in sys.argv: + builder = sys.argv[sys.argv.index('-b')+1] + +# Setting templates_path for epub makes the build fail +if builder == 'dirhtml' or builder == 'html': + templates_path = ['.sphinx/_templates'] + notfound_template = '404.html' + +# Theme configuration +html_theme = 'furo' +html_last_updated_fmt = '' +html_permalinks_icon = '¶' + +if html_title == '': + html_theme_options = { + 'sidebar_hide_name': True + } + +############################################################ +### Additional files +############################################################ + +html_static_path = ['.sphinx/_static'] + +html_css_files = [ + 'custom.css', + 'header.css', + 'github_issue_links.css', + 'furo_colors.css', + 'footer.css' +] +html_css_files.extend(custom_html_css_files) + +html_js_files = ['header-nav.js', 'footer.js'] +if 'github_issues' in html_context and html_context['github_issues'] and not disable_feedback_button: + html_js_files.append('github_issue_links.js') +html_js_files.extend(custom_html_js_files) + +############################################################# +# Display the contributors + + +############################################################# +# DISABLED AS IT DOESN'T WORK FOR source not in same dir + +#def get_contributors_for_file(github_url, github_folder, github_source, pagename, page_source_suffix, display_contributors_since=None): +# filename = f"{pagename}{page_source_suffix}" +# paths=html_context['github_source'][1:] + filename +# +# try: +# repo = Repo(".") +# except InvalidGitRepositoryError: +# cwd = os.getcwd() +# ghfolder = html_context['github_source'][:-1] +# +# if ghfolder and cwd.endswith(ghfolder): +# repo = Repo(cwd.rpartition(ghfolder)[0]) +# else: +# print("The local Git repository could not be found.") +# return +# +# since = display_contributors_since if display_contributors_since and display_contributors_since.strip() else None +# +# commits = repo.iter_commits(paths=paths, since=since) +# +# contributors_dict = {} +# for commit in commits: +# contributor = commit.author.name +# if contributor not in contributors_dict or commit.committed_date > contributors_dict[contributor]['date']: +# contributors_dict[contributor] = { +# 'date': commit.committed_date, +# 'sha': commit.hexsha +# } +# # The github_page contains the link to the contributor's latest commit. +# contributors_list = [{'name': name, 'github_page': f"{github_url}/commit/{data['sha']}"} for name, data in contributors_dict.items()] +# sorted_contributors_list = sorted(contributors_list, key=lambda x: x['name']) +# return sorted_contributors_list +# +# html_context['get_contribs'] = get_contributors_for_file + +############################################################ +### Myst configuration +############################################################ +if os.path.exists('./reuse/substitutions.yaml'): + with open('./reuse/substitutions.yaml', 'r') as fd: + myst_substitutions = yaml.safe_load(fd.read()) + + +############################################################ +### PDF configuration +############################################################ + +latex_additional_files = [ + "./.sphinx/fonts/Ubuntu-B.ttf", + "./.sphinx/fonts/Ubuntu-R.ttf", + "./.sphinx/fonts/Ubuntu-RI.ttf", + "./.sphinx/fonts/UbuntuMono-R.ttf", + "./.sphinx/fonts/UbuntuMono-RI.ttf", + "./.sphinx/fonts/UbuntuMono-B.ttf", + "./.sphinx/images/Canonical-logo-4x.png", + "./.sphinx/images/front-page-light.pdf", + "./.sphinx/images/normal-page-footer.pdf", +] + +latex_engine = 'xelatex' +latex_show_pagerefs = True +latex_show_urls = 'footnote' + +with open(".sphinx/latex_elements_template.txt", "rt") as file: + latex_config = file.read() + +latex_elements = ast.literal_eval(latex_config.replace("$PROJECT", project)) + +master_doc = 'index' \ No newline at end of file diff --git a/docs/canonicalk8s/conf.py b/docs/canonicalk8s/conf.py index c3b447cb8..c804e78c1 100644 --- a/docs/canonicalk8s/conf.py +++ b/docs/canonicalk8s/conf.py @@ -225,6 +225,7 @@ with open('./reuse/substitutions.yaml', 'r') as fd: myst_substitutions = yaml.safe_load(fd.read()) +suppress_warnings = ["myst.xref_missing", "myst.iref_ambiguous"] ############################################################ ### PDF configuration @@ -249,4 +250,6 @@ with open(".sphinx/latex_elements_template.txt", "rt") as file: latex_config = file.read() -latex_elements = ast.literal_eval(latex_config.replace("$PROJECT", project)) \ No newline at end of file +latex_elements = ast.literal_eval(latex_config.replace("$PROJECT", project)) + +master_doc = 'index' \ No newline at end of file diff --git a/docs/canonicalk8s/custom_conf.py b/docs/canonicalk8s/custom_conf.py index 83795a3ee..87d919a81 100644 --- a/docs/canonicalk8s/custom_conf.py +++ b/docs/canonicalk8s/custom_conf.py @@ -167,6 +167,7 @@ 'canonical.terminal-output', 'notfound.extension', 'sphinxcontrib.cairosvgconverter', + 'sphinxcontrib.kroki', ] # Add custom required Python modules that must be added to the @@ -184,7 +185,8 @@ # Add files or directories that should be excluded from processing. custom_excludes = [ 'doc-cheat-sheet*', - '_parts' + '_parts/*', + 'src/_parts' ] # Add CSS files (located in .sphinx/_static/) @@ -218,6 +220,12 @@ ## Add any configuration that is not covered by the common conf.py file. +# Change the default code highlighting to 'none' + +highlight_language = 'none' + + + # Define a :center: role that can be used to center the content of table cells. rst_prolog = ''' .. role:: center diff --git a/docs/src/index.md b/docs/canonicalk8s/index.md similarity index 67% rename from docs/src/index.md rename to docs/canonicalk8s/index.md index 1635cc3f5..f7f8f5a8e 100644 --- a/docs/src/index.md +++ b/docs/canonicalk8s/index.md @@ -20,11 +20,11 @@ Home :titlesonly: :maxdepth: 6 :caption: Deploy from Snap package -Overview -snap/tutorial/index -snap/howto/index -snap/explanation/index -snap/reference/index +Overview +src/snap/tutorial/index +src/snap/howto/index +src/snap/explanation/index +src/snap/reference/index ``` ```{toctree} @@ -32,11 +32,11 @@ snap/reference/index :caption: Deploy with Juju :titlesonly: :glob: -Overview -charm/tutorial/index -charm/howto/index -charm/explanation/index -charm/reference/index +Overview +src/charm/tutorial/index +src/charm/howto/index +src/charm/explanation/index +src/charm/reference/index ``` ```{toctree} @@ -44,11 +44,11 @@ charm/reference/index :caption: Deploy with Cluster API (WIP) :titlesonly: :glob: -Overview -capi/tutorial/index -capi/howto/index -capi/explanation/index -capi/reference/index +Overview +src/capi/tutorial/index +src/capi/howto/index +src/capi/explanation/index +src/capi/reference/index ``` --- @@ -56,16 +56,16 @@ capi/reference/index ````{grid} 1 1 2 2 ```{grid-item-card} -:link: snap/ -### [Install K8s from a snap ›](snap/index) +:link: src/snap/ +### [Install K8s from a snap ›](src/snap/index) ^^^ Our tutorials, How To guides and other pages will explain how to install, configure and use the {{product}} 'k8s' snap. ``` ```{grid-item-card} -:link: charm/ -### [Deploy K8s using Juju ›](charm/index) +:link: src/charm/ +### [Deploy K8s using Juju ›](src/charm/index) ^^^ Our tutorials, How To guides and other pages will explain how to install, configure and use the {{product}} 'k8s' charm. @@ -73,8 +73,8 @@ Our tutorials, How To guides and other pages will explain how to install, ```{grid-item-card} -:link: capi/ -### [Deploy K8s using Cluster API ›](capi/index) +:link: src/capi/ +### [Deploy K8s using Cluster API ›](src/capi/index) ^^^ Our tutorials, guides and explanation pages will explain how to install, configure and use {{product}} through CAPI. @@ -101,8 +101,8 @@ and constructive feedback. [Code of Conduct]: https://ubuntu.com/community/ethos/code-of-conduct -[community]: snap/reference/community -[contribute]: snap/howto/contribute -[roadmap]: snap/reference/roadmap -[overview page]: snap/explanation/about -[architecture documentation]: snap/reference/architecture +[community]: src/snap/reference/community +[contribute]: src/snap/howto/contribute +[roadmap]: src/snap/reference/roadmap +[overview page]: src/snap/explanation/about +[architecture documentation]: src/snap/reference/architecture diff --git a/docs/src/capi/explanation/security.md b/docs/src/capi/explanation/security.md index 6c1048a19..002e071d1 100644 --- a/docs/src/capi/explanation/security.md +++ b/docs/src/capi/explanation/security.md @@ -1,2 +1,2 @@ -```{include} /snap/explanation/security.md +```{include} ../../snap/explanation/security.md ``` diff --git a/docs/src/capi/index.md b/docs/src/capi/index.md index df4102a01..fa1369fdb 100644 --- a/docs/src/capi/index.md +++ b/docs/src/capi/index.md @@ -55,10 +55,10 @@ and constructive feedback. [Code of Conduct]: https://ubuntu.com/community/ethos/code-of-conduct -[community]: /charm/reference/community -[contribute]: /snap/howto/contribute -[roadmap]: /snap/reference/roadmap -[overview page]: /charm/explanation/about -[arch]: /charm/reference/architecture +[community]: ../charm/reference/community +[contribute]: ../snap/howto/contribute +[roadmap]: ../snap/reference/roadmap +[overview page]: ../charm/explanation/about +[arch]: ../charm/reference/architecture [Juju]: https://juju.is -[k8s snap package]: /snap/index \ No newline at end of file +[k8s snap package]: ../snap/index \ No newline at end of file diff --git a/docs/src/capi/reference/configs.md b/docs/src/capi/reference/configs.md index 7297d4f24..a304f68c1 100644 --- a/docs/src/capi/reference/configs.md +++ b/docs/src/capi/reference/configs.md @@ -218,7 +218,7 @@ spec: ``` -[Install custom {{product}} on machines]: /capi/howto/custom-ck8s.md +[Install custom {{product}} on machines]: ../howto/custom-ck8s.md [etcd best practices]: https://etcd.io/docs/v3.5/faq/#why-an-odd-number-of-cluster-members diff --git a/docs/src/charm/explanation/index.md b/docs/src/charm/explanation/index.md index 58409c598..e73fa9827 100644 --- a/docs/src/charm/explanation/index.md +++ b/docs/src/charm/explanation/index.md @@ -39,4 +39,4 @@ details or information such as the command reference or release notes. [Tutorials section]: ../tutorial/index [How-to guides]: ../howto/index [Reference section]: ../reference/index -[explanation topic]: /snap/explanation/index.md +[explanation topic]: ../explanation/index.md diff --git a/docs/src/charm/explanation/security.md b/docs/src/charm/explanation/security.md index 6c1048a19..002e071d1 100644 --- a/docs/src/charm/explanation/security.md +++ b/docs/src/charm/explanation/security.md @@ -1,2 +1,2 @@ -```{include} /snap/explanation/security.md +```{include} ../../snap/explanation/security.md ``` diff --git a/docs/src/charm/reference/architecture.md b/docs/src/charm/reference/architecture.md index 28a51c753..2e2696ba5 100644 --- a/docs/src/charm/reference/architecture.md +++ b/docs/src/charm/reference/architecture.md @@ -1,5 +1,5 @@ # K8s charm architecture -```{include} /snap/reference/architecture.md +```{include} ../../snap/reference/architecture.md :start-after: '## Canonical K8s charms' ``` diff --git a/docs/src/charm/reference/proxy.md b/docs/src/charm/reference/proxy.md index e4dfd0e16..1ebabb32b 100644 --- a/docs/src/charm/reference/proxy.md +++ b/docs/src/charm/reference/proxy.md @@ -1,2 +1,2 @@ -```{include} /snap/reference/proxy.md +```{include} ../../snap/reference/proxy.md ``` \ No newline at end of file diff --git a/docs/src/snap/explanation/index.md b/docs/src/snap/explanation/index.md index 2f8380ea1..194f7aff7 100644 --- a/docs/src/snap/explanation/index.md +++ b/docs/src/snap/explanation/index.md @@ -17,7 +17,7 @@ channels clustering ingress epa -/snap/explanation/security +security ``` --- diff --git a/docs/src/snap/explanation/security.md b/docs/src/snap/explanation/security.md index 53f5ea727..c0a7b1dcc 100644 --- a/docs/src/snap/explanation/security.md +++ b/docs/src/snap/explanation/security.md @@ -62,4 +62,4 @@ check the [roadmap][] for current areas of work. [Kubernetes Security documentation]: https://kubernetes.io/docs/concepts/security/overview/ [snap documentation]: https://snapcraft.io/docs/security-sandboxing [rocks-security]: https://canonical-rockcraft.readthedocs-hosted.com/en/latest/explanation/rockcraft/ -[roadmap]: /snap/reference/roadmap +[roadmap]: ../reference/roadmap diff --git a/docs/src/snap/howto/networking/index.md b/docs/src/snap/howto/networking/index.md index 64f64ce49..4973f6f82 100644 --- a/docs/src/snap/howto/networking/index.md +++ b/docs/src/snap/howto/networking/index.md @@ -11,10 +11,10 @@ how to configure and use key capabilities of {{product}}. ```{toctree} :titlesonly: -/snap/howto/networking/default-dns.md -/snap/howto/networking/default-network.md -/snap/howto/networking/default-ingress.md -/snap/howto/networking/default-loadbalancer.md -/snap/howto/networking/dualstack.md -/snap/howto/networking/ipv6.md +default-dns.md +default-network.md +default-ingress.md +default-loadbalancer.md +dualstack.md +ipv6.md ``` diff --git a/docs/src/snap/reference/community.md b/docs/src/snap/reference/community.md index 080b89348..182ee8688 100644 --- a/docs/src/snap/reference/community.md +++ b/docs/src/snap/reference/community.md @@ -68,6 +68,6 @@ the guidelines for participation. [matrix]: https://matrix.to/#/#k8s:ubuntu.com [Discourse]: https://discourse.ubuntu.com/c/kubernetes/180 [bugs]: https://github.com/canonical/k8s-snap/issues -[Contributing guide]: /snap/howto/contribute -[Developer guide]: /snap/howto/contribute +[Contributing guide]: ../howto/contribute +[Developer guide]: ../howto/contribute [support]: https://ubuntu.com/support diff --git a/docs/src/snap/reference/proxy.md b/docs/src/snap/reference/proxy.md index 1fa29f765..cc8d17465 100644 --- a/docs/src/snap/reference/proxy.md +++ b/docs/src/snap/reference/proxy.md @@ -37,5 +37,5 @@ how to set these. -[How to guide for configuring proxies for the k8s snap]: /snap/howto/proxy -[How to guide for configuring proxies for k8s charms]: /charm/howto/proxy +[How to guide for configuring proxies for the k8s snap]: ../howto/proxy +[How to guide for configuring proxies for k8s charms]: ../../charm/howto/proxy diff --git a/docs/src/snap/reference/releases.md b/docs/src/snap/reference/releases.md index 319f16737..2e73630c9 100644 --- a/docs/src/snap/reference/releases.md +++ b/docs/src/snap/reference/releases.md @@ -32,8 +32,8 @@ Follow along with the [tutorial] to get started! -[tutorial]: /snap/tutorial/getting-started -[nodes]: /snap/tutorial/add-remove-nodes +[tutorial]: ../tutorial/getting-started +[nodes]: ../tutorial/add-remove-nodes [COS Lite]: https://charmhub.io/cos-lite -[networking]: /snap/howto/networking/index -[observability documentation]: /charm/howto/cos-lite \ No newline at end of file +[networking]: ../howto/networking/index +[observability documentation]: ../../charm/howto/cos-lite \ No newline at end of file