central-arch-doc/Makefile
Elyan f7a245706b
Some checks failed
Central(Architecture) Docs Build / Build Documentation (push) Failing after 7s
Different volume handling while running in CI
2024-10-13 18:36:56 +02:00

74 lines
2.1 KiB
Makefile

# vim: noexpandtab:tabstop=4:shiftwidth=4
# Taken and adapted from https://github.com/riscv/riscv-isa-manual/blob/main/Makefile
# Adapted to run in Gitea Actions: https://gitea.com/gitea/act_runner/issues/189#issuecomment-812870
DOCS := central-execution-engine-spec
DOCKER_IMG_BASE := git.elyanpoujol.fr/elyan
DOCKER_IMG := $(DOCKER_IMG_BASE)/docker-asciidoctor-wavedrom:latest
ENV := LANG=C.utf8
OPTIONS := -D build \
--trace \
--failure-level=ERROR
REQUIRES := --require=asciidoctor-diagram
DOCKER_IS_ROOTLESS = \
$(shell ! ps ux | grep -v grep | grep dockerd-rootless >/dev/null ; echo $$?)
VOLUME_LOCAL := -v $(PWD):$(PWD)
VOLUME_CI := --volumes-from=$(JOB_CONTAINER_NAME)
ifeq "$(CI)" "true"
VOLUME := VOLUME_CI
$(info Running in a CI environment)
else ifneq "$(DOCKER_IS_ROOTLESS)" "1"
# Rooted Docker requires this flag so that the files it creates are
# owned by the current user instead of root. Rootless docker does not
# require it, and Podman doesn't either since it is always rootless.
DOCKER_USER_ARG := --user $(shell id -u)
SUDO_PREFIX := sudo
VOLUME := $(VOLUME_LOCAL)
$(info Running locally)
else
VOLUME := $(VOLUME_LOCAL)
$(info Running locally in rootless mode)
endif
SRC_DIR := src
BUILD_DIR := build
DOCKER_DIR := docker
ALL_SRC := $(shell find $(SRC_DIR) -type f -name '*.adoc' -print)
DOCS_PDF := $(addprefix $(BUILD_DIR)/, $(addsuffix .pdf, $(DOCS)))
.PHONY: all build build-in-docker image clean
all: build
build:
$(SUDO_PREFIX) docker run --rm $(VOLUME) $(DOCKER_USER_ARG) $(DOCKER_IMG) /bin/sh -c "cd $(PWD) && make build-in-docker"
build-in-docker: $(DOCS_PDF)
$(BUILD_DIR)/%.pdf: $(SRC_DIR)/%.adoc $(ALL_SRC)
@echo "Building documentation in docker container..."
rm -rf $@.workdir
mkdir -p $@.workdir
cp -r src $@.workdir
$(ENV) cd $@.workdir && asciidoctor-pdf $(OPTIONS) $(REQUIRES) $<
mv $@.workdir/$@ $@
rm -rf $@.workdir
@echo "Build completed."
image:
$(SUDO_PREFIX) docker build -t $(DOCKER_IMG) $(DOCKER_DIR)
clean:
@echo "Cleaning up generated files..."
rm -rf $(BUILD_DIR)
@echo "Cleanup completed."