diff --git a/group_vars/all/07_applications.yml b/group_vars/all/07_applications.yml index 55e79a74..65511d2a 100644 --- a/group_vars/all/07_applications.yml +++ b/group_vars/all/07_applications.yml @@ -549,9 +549,9 @@ defaults_applications: ## Sphinx sphinx: - version: "3.9-slim" # Use latest docker image - volumes: - source_dir: "{ansible_playbook_dir}" # Path from which sphinx reads the documentation + version: "3.9-slim" # Use latest docker image + repository_sphinx_source: "https://github.com/kevinveenbirkenbach/cymais.git" # Repository address to pull the source repository from + sphinx_exec_dir_relative: "sphinx/" # The relative path to the sphinx Makefile folder from the source dir ## Taiga diff --git a/roles/docker-sphinx/tasks/main.yml b/roles/docker-sphinx/tasks/main.yml index d165c547..fd99fd1b 100644 --- a/roles/docker-sphinx/tasks/main.yml +++ b/roles/docker-sphinx/tasks/main.yml @@ -4,12 +4,19 @@ include_role: name: docker-compose -- name: pull cymais repository +- name: "Create {{ host_sphinx_source_dir_absolute }} directory" + file: + path: "{{ host_sphinx_source_dir_absolute }}" + state: directory + mode: '0755' + +- name: pull the source repository to build the Sphinx documentation from {{ applications.sphinx.repository_sphinx_source }} git: - repo: "{{ repository_address_cymais }}" - dest: "{{ host_cymais_volume_dir_absolute }}" + repo: "{{ applications.sphinx.repository_sphinx_source }}" + dest: "{{ host_sphinx_source_dir_absolute }}" update: yes - notify: docker compose project setup + clone: yes + notify: docker compose project build and setup become: true - name: "include role nginx-domain-setup for {{application_id}}" @@ -25,7 +32,7 @@ dest: "{{ sphinx_docker_file }}" mode: '770' force: yes - notify: docker compose project setup + notify: docker compose project build and setup - name: "copy docker-compose.yml and env file" include_tasks: copy-docker-compose-and-env.yml \ No newline at end of file diff --git a/roles/docker-sphinx/templates/Dockerfile.j2 b/roles/docker-sphinx/templates/Dockerfile.j2 index 0967ac1c..cf3a9e55 100644 --- a/roles/docker-sphinx/templates/Dockerfile.j2 +++ b/roles/docker-sphinx/templates/Dockerfile.j2 @@ -1,22 +1,35 @@ FROM python:{{applications[application_id].version}} -# Install required packages including 'make' -RUN apt-get update && apt-get install -y make +ARG SPHINX_SOURCE_DIR +ARG SPHINX_BUILD_DIR +ARG SPHINX_EXEC_DIR +ARG SPHINX_APP_DIR +ARG SPHINX_SOURCE_DIR_RELATIVE + +# Set the environment variables so they are available during build +ENV SPHINX_SOURCE_DIR=${SPHINX_SOURCE_DIR} +ENV SPHINX_SOURCE_DIR_RELATIVE=${SPHINX_SOURCE_DIR_RELATIVE} +ENV SPHINX_BUILD_DIR=${SPHINX_BUILD_DIR} +ENV SPHINX_EXEC_DIR=${SPHINX_EXEC_DIR} +ENV SPHINX_APP_DIR=${SPHINX_APP_DIR} + +# Install required packages +RUN apt-get update && apt-get install -y make curl # Set the working directory -WORKDIR {{docker_app_dir}} +WORKDIR ${SPHINX_APP_DIR} # Copy the project files into the container -COPY {{host_cymais_volume_dir_relative}} {{docker_app_dir}} +COPY ${SPHINX_SOURCE_DIR_RELATIVE} ${SPHINX_APP_DIR} # Install Python packages via requirements.txt -RUN cd {{docker_sphinx_dir}} && pip install --upgrade pip && pip install -r requirements.txt +RUN cd ${SPHINX_EXEC_DIR} && pip install --upgrade pip && pip install -r requirements.txt # Build the HTML documentation using Sphinx with the defined directories -RUN cd {{docker_sphinx_dir}} && make html +RUN cd ${SPHINX_EXEC_DIR} && make html # Expose port 8000 where the HTTP server will run EXPOSE 8000 # Start a simple HTTP server to serve the built documentation -CMD ["python", "-m", "http.server", "8000", "--directory", "${BUILD_DIR}"] +CMD ["python", "-m", "http.server", "8000", "--directory", "${SPHINX_BUILD_DIR}"] diff --git a/roles/docker-sphinx/templates/docker-compose.yml.j2 b/roles/docker-sphinx/templates/docker-compose.yml.j2 index 4675c3e3..c257f557 100644 --- a/roles/docker-sphinx/templates/docker-compose.yml.j2 +++ b/roles/docker-sphinx/templates/docker-compose.yml.j2 @@ -1,6 +1,14 @@ services: application: - build: . + build: + context: . + dockerfile: Dockerfile + args: + SPHINX_SOURCE_DIR: {{docker_source_dir}} + SPHINX_BUILD_DIR: {{docker_output_dir}} + SPHINX_EXEC_DIR: {{docker_exec_dir}} + SPHINX_APP_DIR: {{docker_app_dir}} + SPINX_SOURCE_DIR_RELATIVE: {{host_sphinx_source_dir_relative}} ports: - "127.0.0.1:{{ports.localhost.http[application_id]}}:8000" healthcheck: @@ -8,6 +16,7 @@ services: interval: 1m timeout: 10s retries: 3 +{% include 'roles/docker-compose/templates/services/base.yml.j2' %} {% include 'templates/docker/container/networks.yml.j2' %} {% include 'templates/docker/compose/networks.yml.j2' %} diff --git a/roles/docker-sphinx/templates/env.j2 b/roles/docker-sphinx/templates/env.j2 index e9c56f5c..e69de29b 100644 --- a/roles/docker-sphinx/templates/env.j2 +++ b/roles/docker-sphinx/templates/env.j2 @@ -1,2 +0,0 @@ -SOURCE_DIR={{docker_source_dir}} -BUILD_DIR={{docker_output_dir}} \ No newline at end of file diff --git a/roles/docker-sphinx/vars/main.yml b/roles/docker-sphinx/vars/main.yml index 903c4924..1848eac2 100644 --- a/roles/docker-sphinx/vars/main.yml +++ b/roles/docker-sphinx/vars/main.yml @@ -1,13 +1,12 @@ -application_id: "sphinx" +application_id: "sphinx" -repository_address_cymais: "https://github.com/kevinveenbirkenbach/cymais.git" # Repository address to pull cymais from +host_sphinx_source_dir_relative: "volumes/source/" # Place where the sphinx source repository is stored on the host +host_sphinx_source_dir_absolute: "{{docker_compose.directories.instance}}{{host_sphinx_source_dir_relative}}" # Place where the sphinx source repository is stored on the host -host_cymais_volume_dir_absolute: "{{docker_compose.directories.volumes}}cymais/" # Place where the cymais repository is stored on the host -host_cymais_volume_dir_relative: "volumes/cymais/" # Place where the cymais repository is stored on the host +docker_app_dir: "/app/" # Folder in which the application is running +docker_source_dir: "{{docker_app_dir}}" # Folder which is used to be screened +docker_output_dir: "/docs/" +docker_html_output_dir: "{{docker_output_dir}}html/" # Folder to which the output is fuuuucking putted! +docker_exec_dir: "{{docker_app_dir}}{{applications.sphinx.sphinx_exec_dir_relative}}" # Folder which contains the sphinxs makefile and logic -docker_app_dir: "/app/" # Folder in which the application is running -docker_source_dir: "{{docker_app_dir}}" # Folder which is used to be screened -docker_output_dir: "/docs/" # Folder to which the output is fuuuucking putted! -docker_sphinx_dir: "{{docker_app_dir}}/sphinx/" # Folder which contains the sphinxs makefile and logic - -sphinx_docker_file: "{{ docker_compose.directories.instance }}/Dockerfile" \ No newline at end of file +sphinx_docker_file: "{{ docker_compose.directories.instance }}Dockerfile" # Path to the Dockerfile to build sphinx \ No newline at end of file diff --git a/sphinx/Makefile b/sphinx/Makefile index 437ffd0d..917b3268 100644 --- a/sphinx/Makefile +++ b/sphinx/Makefile @@ -2,19 +2,19 @@ # # You can set these variables from the command line, and also -# from the environment for the first two. -SPHINXOPTS ?= -c . -SPHINXBUILD ?= sphinx-build -SOURCE_DIR = ../ -BUILD_DIR = ../docs +# from the environment +SPHINXOPTS ?= -c . +SPHINXBUILD ?= sphinx-build +SPHINX_SOURCE_DIR ?= ../ +SPHINX_BUILD_DIR ?= ../docs # Put it first so that "make" without argument is like "make help". help: - @$(SPHINXBUILD) -M help "$(SOURCE_DIR)" "$(BUILD_DIR)" $(SPHINXOPTS) $(O) + @$(SPHINXBUILD) -M help "$(SPHINX_SOURCE_DIR)" "$(SPHINX_BUILD_DIR)" $(SPHINXOPTS) $(O) .PHONY: help install Makefile # Catch-all target: route all unknown targets to Sphinx using the new # "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS). %: Makefile - @$(SPHINXBUILD) -M $@ "$(SOURCE_DIR)" "$(BUILD_DIR)" $(SPHINXOPTS) $(O) + @$(SPHINXBUILD) -M $@ "$(SPHINX_SOURCE_DIR)" "$(SPHINX_BUILD_DIR)" $(SPHINXOPTS) $(O) diff --git a/sphinx/conf.py b/sphinx/conf.py index efd1daf7..225565df 100644 --- a/sphinx/conf.py +++ b/sphinx/conf.py @@ -32,7 +32,7 @@ html_sidebars = { '**': [ 'globaltoc.html', 'relations.html', - 'sourcelink.html', + # 'sourcelink.html', 'local_md_files.html', # Include your custom template 'searchbox.html', ]