From 09a5f8ea43a7e6630f81bf02bff86687bda065ef Mon Sep 17 00:00:00 2001 From: sidecus <4399408+sidecus@users.noreply.github.com> Date: Thu, 25 Jul 2024 18:10:31 +0800 Subject: [PATCH 1/2] use entrypoint script to set environment variables --- src/magicmirror/devcontainer-feature.json | 9 +++++---- src/magicmirror/install.sh | 9 +++++++-- test/magicmirror/hf.sh | 4 ++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/magicmirror/devcontainer-feature.json b/src/magicmirror/devcontainer-feature.json index 00652c6..ac40fc9 100644 --- a/src/magicmirror/devcontainer-feature.json +++ b/src/magicmirror/devcontainer-feature.json @@ -3,6 +3,10 @@ "id": "magicmirror", "version": "1.0.3", "description": "Automatic mirror setup for package managers like apt, pypi, apk etc.", + "entrypoint": "/usr/local/bin/magicmirror.sh", + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ], "options": { "pypi_mirror": { "type": "string", @@ -36,8 +40,5 @@ "default": "", "description": "Huggingface mirror" } - }, - "installsAfter": [ - "ghcr.io/devcontainers/features/common-utils" - ] + } } diff --git a/src/magicmirror/install.sh b/src/magicmirror/install.sh index 16a745b..dbcb6ea 100644 --- a/src/magicmirror/install.sh +++ b/src/magicmirror/install.sh @@ -47,6 +47,13 @@ if [ "${OS}" = '"Alpine Linux"' ] && [ -n "${APK_MIRROR}" ]; then sed -i "s/dl-cdn.alpinelinux.org/${APK_MIRROR}/g" /etc/apk/repositories fi +# add entrypoint script +cat > /usr/local/bin/magicmirror.sh << EOF +#!/bin/sh +set -a; . /etc/environment; set +a; +EOF +chmod +x /usr/local/bin/magicmirror.sh + # Set Huggingface mirror if it's provided HUGGINGFACE_MIRROR=${HUGGINGFACE_MIRROR:-""} echo "HUGGINGFACE_MIRROR: $HUGGINGFACE_MIRROR" @@ -54,6 +61,4 @@ if [ -n "${HUGGINGFACE_MIRROR}" ]; then echo "Enabling Huggingface mirror: ${HUGGINGFACE_MIRROR}" touch /etc/environment && cp /etc/environment /etc/environment.mm.bak echo "HF_ENDPOINT=${HUGGINGFACE_MIRROR}" >> /etc/environment - # export the new env - set -a; . /etc/environment; set +a; fi diff --git a/test/magicmirror/hf.sh b/test/magicmirror/hf.sh index d007abe..756e472 100644 --- a/test/magicmirror/hf.sh +++ b/test/magicmirror/hf.sh @@ -12,8 +12,8 @@ source dev-container-features-test-lib # The 'check' command comes from the dev-container-features-test-lib. # TODO[sidecus]: Workaround for the test case since /env/environment is not loaded in test case scenarios # Should consider using containerEnv if this is solved: https://github.com/devcontainers/spec/issues/164 -# check "test HF mirror" bash -c "test \"${HF_ENDPOINT}\" = \"https://dummy-hf-mirror.com/"" -check "test HF mirror" bash -c "cat /etc/environment | grep 'https://dummy-hf-mirror.com/'" +check "test HF mirror" bash -c "test \"${HF_ENDPOINT}\" = \"https://dummy-hf-mirror.com/"" +# check "test HF mirror" bash -c "cat /etc/environment | grep 'https://dummy-hf-mirror.com/'" # Report results # If any of the checks above exited with a non-zero exit code, the test will fail. From 520326babb8fb114b8280773e61b8edc9e097c67 Mon Sep 17 00:00:00 2001 From: sidecus <4399408+sidecus@users.noreply.github.com> Date: Thu, 25 Jul 2024 14:26:43 +0000 Subject: [PATCH 2/2] use entrypoint script --- src/magicmirror/install.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/magicmirror/install.sh b/src/magicmirror/install.sh index dbcb6ea..dd5f3b0 100644 --- a/src/magicmirror/install.sh +++ b/src/magicmirror/install.sh @@ -50,7 +50,7 @@ fi # add entrypoint script cat > /usr/local/bin/magicmirror.sh << EOF #!/bin/sh -set -a; . /etc/environment; set +a; +echo "running magicmirror entrypoint" EOF chmod +x /usr/local/bin/magicmirror.sh @@ -59,6 +59,6 @@ HUGGINGFACE_MIRROR=${HUGGINGFACE_MIRROR:-""} echo "HUGGINGFACE_MIRROR: $HUGGINGFACE_MIRROR" if [ -n "${HUGGINGFACE_MIRROR}" ]; then echo "Enabling Huggingface mirror: ${HUGGINGFACE_MIRROR}" - touch /etc/environment && cp /etc/environment /etc/environment.mm.bak - echo "HF_ENDPOINT=${HUGGINGFACE_MIRROR}" >> /etc/environment + echo "Injecting HF_ENDPOINT value setting into magicmirror.sh" + echo "export HF_ENDPOINT=${HUGGINGFACE_MIRROR};echo \${HF_ENDPOINT}" >> /usr/local/bin/magicmirror.sh fi