Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use entrypoint script to set environment variables #9

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/magicmirror/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -36,8 +40,5 @@
"default": "",
"description": "Huggingface mirror"
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
}
13 changes: 9 additions & 4 deletions src/magicmirror/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,18 @@ 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
echo "running magicmirror entrypoint"
EOF
chmod +x /usr/local/bin/magicmirror.sh

# Set Huggingface mirror if it's provided
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
# export the new env
set -a; . /etc/environment; set +a;
echo "Injecting HF_ENDPOINT value setting into magicmirror.sh"
echo "export HF_ENDPOINT=${HUGGINGFACE_MIRROR};echo \${HF_ENDPOINT}" >> /usr/local/bin/magicmirror.sh
fi
4 changes: 2 additions & 2 deletions test/magicmirror/hf.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading