From 2e42fbb6c8aa515a5399de7d2149c88544ec3827 Mon Sep 17 00:00:00 2001 From: Ron Williams Date: Tue, 15 Nov 2022 12:35:44 -0800 Subject: [PATCH] move Rust install to a persistent container dir --- mk/podman.mk | 18 ++++++++++++++---- podman/redox-base-containerfile | 12 ++++-------- podman/rustinstall.sh | 7 +++++++ 3 files changed, 25 insertions(+), 12 deletions(-) create mode 100755 podman/rustinstall.sh diff --git a/mk/podman.mk b/mk/podman.mk index a36e8c0..bba5543 100644 --- a/mk/podman.mk +++ b/mk/podman.mk @@ -8,8 +8,10 @@ IMAGE_TAG?=redox-base ## Working Directory in Podman CONTAINER_WORKDIR?=/mnt/redox +## Podman Home Directory +PODMAN_HOME?=$(HOME)/.local/share/containers/storage/podman_home ## Podman command with its many arguments -PODMAN_VOLUMES?=--volume "`pwd`":$(CONTAINER_WORKDIR):Z +PODMAN_VOLUMES?=--volume "`pwd`":$(CONTAINER_WORKDIR):Z --volume $(PODMAN_HOME):/home:Z PODMAN_ENV?=--env PATH=/home/poduser/.cargo/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin --env PODMAN_BUILD=0 PODMAN_CONFIG?=--env ARCH=$(ARCH) --env CONFIG_NAME=$(CONFIG_NAME) --env FILESYSTEM_CONFIG=$(FILESYSTEM_CONFIG) PODMAN_OPTIONS?=--rm --workdir $(CONTAINER_WORKDIR) --userns keep-id --user `id -u` --interactive --tty --env TERM=$(TERM) @@ -24,13 +26,16 @@ endif container_clean: FORCE rm -f build/container.tag + @echo "If podman_home dir cannot be removed, " + @echo "remove with either \"sudo rm\" or \"podman system reset\"." + -rm -rf $(PODMAN_HOME) || true @echo "For complete clean of images and containers, use \"podman system reset\"" -podman image rm --force $(IMAGE_TAG) || true container_touch: FORCE ifeq ($(PODMAN_BUILD),1) - @echo If you get an error, the image does not exist. Just do a normal make. - podman image exists $(IMAGE_TAG) + rm -f build/container.tag + podman image exists $(IMAGE_TAG) || (echo "Image does not exist, it will be rebuilt during normal make."; exit 1) touch build/container.tag else @echo PODMAN_BUILD=$(PODMAN_BUILD), container not required. @@ -40,13 +45,18 @@ endif build/container.tag: $(CONTAINERFILE) ifeq ($(PODMAN_BUILD),1) rm -f build/container.tag + @echo "If podman_home dir cannot be removed, " + @echo "remove with either \"sudo rm\" or \"podman system reset\"." + -rm -rf $(PODMAN_HOME) || true -podman image rm --force $(IMAGE_TAG) || true + mkdir -p $(PODMAN_HOME) @echo "Building Podman image. This may take some time." sed s/_UID_/`id -u`/ $(CONTAINERFILE) | podman build --file - $(PODMAN_VOLUMES) --tag $(IMAGE_TAG) @echo "Mapping Podman user space. Please wait." - $(PODMAN_RUN) echo "Podman ready!" + $(PODMAN_RUN) bash -e podman/rustinstall.sh mkdir -p build touch $@ + @echo "Podman ready!" else @echo PODMAN_BUILD=$(PODMAN_BUILD), container not required. endif diff --git a/podman/redox-base-containerfile b/podman/redox-base-containerfile index 7698dc1..d9eb7dc 100644 --- a/podman/redox-base-containerfile +++ b/podman/redox-base-containerfile @@ -38,12 +38,8 @@ RUN apt-get update \ wget # _UID_ must be replaced with the user's uid on host -RUN useradd --create-home --no-log-init --uid _UID_ poduser +# podman root is mapped to your user id on host during build, +# poduser is mapped to your user id during podman run +RUN useradd --create-home --no-log-init --uid _UID_ poduser && \ + chown -R root:root /home -USER poduser - -RUN curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly && \ - /home/poduser/.cargo/bin/cargo install --force --version 0.1.1 cargo-config && \ - /home/poduser/.cargo/bin/cargo install --force --version 0.3.20 xargo - -CMD [ "bash", "-c"] \ No newline at end of file diff --git a/podman/rustinstall.sh b/podman/rustinstall.sh new file mode 100755 index 0000000..9955bee --- /dev/null +++ b/podman/rustinstall.sh @@ -0,0 +1,7 @@ +#/usr/bin/env bash + +# Install Rust in Podman, after the image has been built + +curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly +cargo install --force --version 0.1.1 cargo-config +cargo install --force --version 0.3.20 xargo