From f7a245706b1544541df4dd366cbabded76516026 Mon Sep 17 00:00:00 2001 From: Elyan Date: Sun, 13 Oct 2024 18:36:56 +0200 Subject: [PATCH] Different volume handling while running in CI --- .gitea/workflows/build.yaml | 2 +- Makefile | 57 ++++++++++++++++++++----------------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index c41b8f1..ccc01c0 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -39,7 +39,7 @@ jobs: - name: Build Files id: build_files if: steps.pull_container_image.outcome == 'success' - run: make -j$(nproc) + run: make - name: Upload central-execution-engine-spec.pdf if: steps.build_files.outcome == 'success' diff --git a/Makefile b/Makefile index c0e0dbe..48680a8 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ -# Taken and adapted from https://github.com/riscv/riscv-isa-manual/blob/main/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 @@ -16,31 +18,26 @@ REQUIRES := --require=asciidoctor-diagram DOCKER_IS_ROOTLESS = \ $(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 # 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 -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 BUILD_DIR := build DOCKER_DIR := docker @@ -48,18 +45,26 @@ 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 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) - $(WORKDIR_SETUP) - $(DOCKER_CMD) '$(ENV) asciidoctor-pdf $(OPTIONS) $(REQUIRES) $<' - $(WORKDIR_TEARDOWN) + @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." -create-docker-image: +image: $(SUDO_PREFIX) docker build -t $(DOCKER_IMG) $(DOCKER_DIR) clean: