Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions doc_builder/build_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,7 @@
import pathlib
from doc_builder import sys_utils

# The Docker image used to build documentation via Docker
DOCKER_IMAGE = "escomp/base"
default_docker_image = "ghcr.io/escomp/ctsm/ctsm-docs:v1.0.0"

# The path in Docker's filesystem where the user's home directory is mounted
_DOCKER_HOME = "/home/user/mounted_home"
Expand Down Expand Up @@ -65,7 +64,7 @@ def get_build_dir(build_dir=None, repo_root=None, version=None):
return build_dir

def get_build_command(build_dir, run_from_dir, build_target, num_make_jobs, docker_name=None,
warnings_as_warnings=False,
warnings_as_warnings=False, docker_image=default_docker_image,
):
"""Return a string giving the build command.

Expand Down Expand Up @@ -109,6 +108,10 @@ def get_build_command(build_dir, run_from_dir, build_target, num_make_jobs, dock
errmsg_if_not_under_mountpoint=
"build directory must reside under your home directory")

# Get current user's UID and GID
uid = os.getuid()
gid = os.getgid()

make_command = _get_make_command(build_dir=docker_build_dir,
build_target=build_target,
num_make_jobs=num_make_jobs,
Expand All @@ -117,12 +120,13 @@ def get_build_command(build_dir, run_from_dir, build_target, num_make_jobs, dock

docker_command = ["docker", "run",
"--name", docker_name,
"--user", f"{uid}:{gid}",
"--mount", "type=bind,source={},target={}".format(
docker_mountpoint, _DOCKER_HOME),
"--workdir", docker_workdir,
"-t", # "-t" is needed for colorful output
"--rm",
DOCKER_IMAGE] + make_command
docker_image] + make_command
return docker_command

def _get_make_command(build_dir, build_target, num_make_jobs, warnings_as_warnings):
Expand Down
27 changes: 22 additions & 5 deletions doc_builder/build_docs.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import string
import sys
import signal
from doc_builder.build_commands import get_build_dir, get_build_command, DOCKER_IMAGE
from doc_builder.build_commands import get_build_dir, get_build_command, default_docker_image

def commandline_options(cmdline_args=None):
"""Process the command-line arguments.
Expand Down Expand Up @@ -80,15 +80,23 @@ def commandline_options(cmdline_args=None):
help="Before building, run 'make clean'.")

parser.add_argument("-d", "--build-with-docker", action="store_true",
help="Use the {docker_image} Docker container to build the documentation,\n"
help="Use a Docker container to build the documentation,\n"
"rather than relying on locally-installed versions of Sphinx, etc.\n"
"This assumes that Docker is installed and running on your system.\n"
"\n"
"NOTE: This mounts your home directory in the Docker image.\n"
"Therefore, both the current directory (containing the Makefile for\n"
"building the documentation) and the documentation build directory\n"
"must reside somewhere within your home directory.".format(
docker_image=DOCKER_IMAGE))
"must reside somewhere within your home directory."
"\n"
f"Default image: {default_docker_image}\n"
"This can be changed with -i/--docker-image.")

parser.add_argument(
"-i", "--docker-image", "--docker-container",
default=None,
help="Docker container to use. Implies -d."
)

parser.add_argument("-t", "--build-target", default="html",
help="Target for the make command.\n"
Expand All @@ -102,6 +110,13 @@ def commandline_options(cmdline_args=None):
help="Treat sphinx warnings as warnings, not errors.")

options = parser.parse_args(cmdline_args)

if options.docker_image:
options.docker_image = options.docker_image.lower()
options.build_with_docker = True
elif options.build_with_docker:
options.docker_image = default_docker_image

return options

def run_build_command(build_command):
Expand Down Expand Up @@ -168,14 +183,16 @@ def main(cmdline_args=None):
run_from_dir=os.getcwd(),
build_target="clean",
num_make_jobs=opts.num_make_jobs,
docker_name=docker_name)
docker_name=docker_name,
docker_image=opts.docker_image)
run_build_command(build_command=clean_command)

build_command = get_build_command(build_dir=build_dir,
run_from_dir=os.getcwd(),
build_target=opts.build_target,
num_make_jobs=opts.num_make_jobs,
docker_name=docker_name,
docker_image=opts.docker_image,
warnings_as_warnings=opts.warnings_as_warnings,
)
run_build_command(build_command=build_command)