allow override for toolchain docker volume and workdir for niche environments

This commit is contained in:
Lance Vick 2023-05-02 14:55:45 -07:00
parent 70c9e403ac
commit a4086420ca
Signed by: lrvick
GPG Key ID: 8E47A1EC35A1551D
2 changed files with 34 additions and 27 deletions

View File

@ -13,7 +13,7 @@ IMAGE := local/$(NAME)
UID := $(shell id -u) UID := $(shell id -u)
GID := $(shell id -g) GID := $(shell id -g)
USER := $(UID):$(GID) USER := $(UID):$(GID)
CPUS := $(shell docker run -it debian nproc) CPUS := $(shell docker run debian nproc)
PRESERVE_CACHE := "false" PRESERVE_CACHE := "false"
GIT_REF := $(shell git log -1 --format=%H) GIT_REF := $(shell git log -1 --format=%H)
GIT_AUTHOR := $(shell git log -1 --format=%an) GIT_AUTHOR := $(shell git log -1 --format=%an)
@ -214,20 +214,23 @@ define fetch_pgp_key
') ')
endef endef
TOOLCHAIN_VOLUME := $(PWD):/home/build
TOOLCHAIN_WORKDIR := /home/build
define toolchain define toolchain
docker run \ docker run \
--rm \ --rm \
--tty \ --tty \
$(2) \ $(2) \
--env UID=$(UID) \ --env UID=$(UID) \
--env GID=$(GID) \ --env GID=$(GID) \
--platform=linux/$(ARCH) \ --platform=linux/$(ARCH) \
--privileged \ --privileged \
--cpus $(CPUS) \ --cpus $(CPUS) \
--volume $(PWD):/home/build \ --volume $(TOOLCHAIN_VOLUME) \
--workdir /home/build \ --workdir $(TOOLCHAIN_WORKDIR) \
--env-file=$(CONFIG_DIR)/global.env \ --env-file=$(CONFIG_DIR)/global.env \
--env-file=$(CACHE_DIR_ROOT)/toolchain.env \ --env-file=$(CACHE_DIR_ROOT)/toolchain.env \
$(shell cat cache/toolchain.state 2> /dev/null) \ $(shell cat cache/toolchain.state 2> /dev/null) \
$(SRC_DIR)/toolchain/scripts/host-env bash -c $(1) $(SRC_DIR)/toolchain/scripts/host-env bash -c $(1)
endef endef

View File

@ -6,15 +6,19 @@ gid=${GID?}
user=${USER:-"build"} user=${USER:-"build"}
export HOME="/home/${user}" export HOME="/home/${user}"
groupdel dialout # If running user is not root, pivot to custom user/group
groupadd -g "$gid" "${user}" [ "$uid" != "0" ] && {
useradd \ getent group "$gid" && groupdel "$gid"
-g "$gid" \ getent passwd "$uid" && userdel "$uid"
-G sudo \ groupadd -g "$gid" "${user}"
-u "$uid" \ useradd \
-d "/home/${user}" \ -g "$gid" \
-s /bin/bash \ -G sudo \
"${user}" -u "$uid" \
-d "/home/${user}" \
-s /bin/bash \
"${user}"
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"
}
cd "$HOME" exec "$@"
setpriv --reuid="$uid" --regid="$gid" --init-groups "$@"