Different volume handling while running in CI
Some checks failed
Central(Architecture) Docs Build / Build Documentation (push) Failing after 7s

This commit is contained in:
Elyan 2024-10-13 18:36:56 +02:00
parent 7cbf03d54f
commit f7a245706b
2 changed files with 32 additions and 27 deletions

View File

@ -39,7 +39,7 @@ jobs:
- name: Build Files - name: Build Files
id: build_files id: build_files
if: steps.pull_container_image.outcome == 'success' if: steps.pull_container_image.outcome == 'success'
run: make -j$(nproc) run: make
- name: Upload central-execution-engine-spec.pdf - name: Upload central-execution-engine-spec.pdf
if: steps.build_files.outcome == 'success' if: steps.build_files.outcome == 'success'

View File

@ -1,6 +1,8 @@
# Taken and adapted from https://github.com/riscv/riscv-isa-manual/blob/main/Makefile
# vim: noexpandtab:tabstop=4:shiftwidth=4 # 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 DOCS := central-execution-engine-spec
DOCKER_IMG_BASE := git.elyanpoujol.fr/elyan DOCKER_IMG_BASE := git.elyanpoujol.fr/elyan
@ -16,31 +18,26 @@ REQUIRES := --require=asciidoctor-diagram
DOCKER_IS_ROOTLESS = \ DOCKER_IS_ROOTLESS = \
$(shell ! ps ux | grep -v grep | grep dockerd-rootless >/dev/null ; echo $$?) $(shell ! ps ux | grep -v grep | grep dockerd-rootless >/dev/null ; echo $$?)
ifneq "$(DOCKER_IS_ROOTLESS)" "1"
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 # Rooted Docker requires this flag so that the files it creates are
# owned by the current user instead of root. Rootless docker does not # owned by the current user instead of root. Rootless docker does not
# require it, and Podman doesn't either since it is always rootless. # require it, and Podman doesn't either since it is always rootless.
DOCKER_USER_ARG := --user $(shell id -u) DOCKER_USER_ARG := --user $(shell id -u)
SUDO_PREFIX := sudo SUDO_PREFIX := sudo
VOLUME := $(VOLUME_LOCAL)
$(info Running locally)
else
VOLUME := $(VOLUME_LOCAL)
$(info Running locally in rootless mode)
endif endif
DOCKER_CMD = \
$(SUDO_PREFIX) docker run --rm \
-v $(PWD)/$@.workdir:/build \
-w /build \
$(DOCKER_USER_ARG) \
$(DOCKER_IMG) \
/bin/sh -c
WORKDIR_SETUP = \
rm -rf $@.workdir && \
mkdir -p $@.workdir && \
cp -r src $@.workdir
WORKDIR_TEARDOWN = \
mv $@.workdir/$@ $@ && \
rm -rf $@.workdir
SRC_DIR := src SRC_DIR := src
BUILD_DIR := build BUILD_DIR := build
DOCKER_DIR := docker DOCKER_DIR := docker
@ -48,18 +45,26 @@ DOCKER_DIR := docker
ALL_SRC := $(shell find $(SRC_DIR) -type f -name '*.adoc' -print) ALL_SRC := $(shell find $(SRC_DIR) -type f -name '*.adoc' -print)
DOCS_PDF := $(addprefix $(BUILD_DIR)/, $(addsuffix .pdf, $(DOCS))) DOCS_PDF := $(addprefix $(BUILD_DIR)/, $(addsuffix .pdf, $(DOCS)))
.PHONY: all build create-docker-image clean .PHONY: all build build-in-docker image clean
all: build-pdf all: build
build-pdf: $(DOCS_PDF) 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) $(BUILD_DIR)/%.pdf: $(SRC_DIR)/%.adoc $(ALL_SRC)
$(WORKDIR_SETUP) @echo "Building documentation in docker container..."
$(DOCKER_CMD) '$(ENV) asciidoctor-pdf $(OPTIONS) $(REQUIRES) $<' rm -rf $@.workdir
$(WORKDIR_TEARDOWN) mkdir -p $@.workdir
cp -r src $@.workdir
$(ENV) cd $@.workdir && asciidoctor-pdf $(OPTIONS) $(REQUIRES) $<
mv $@.workdir/$@ $@
rm -rf $@.workdir
@echo "Build completed."
create-docker-image: image:
$(SUDO_PREFIX) docker build -t $(DOCKER_IMG) $(DOCKER_DIR) $(SUDO_PREFIX) docker build -t $(DOCKER_IMG) $(DOCKER_DIR)
clean: clean: