开发容器配置-初版
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
{
|
||||
"id": "patch-python",
|
||||
"name": "Patch Python Packages",
|
||||
"installsAfter": ["ghcr.io/devcontainers/features/python"]
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env bash
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
# Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
# Licensed under the MIT License. See https://go.microsoft.com/fwlink/?linkid=2090316 for license information.
|
||||
#-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
USERNAME=${USERNAME:-"codespace"}
|
||||
|
||||
set -eux
|
||||
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Ensure that login shells get the correct path if the user updated the PATH using ENV.
|
||||
rm -f /etc/profile.d/00-restore-env.sh
|
||||
echo "export PATH=${PATH//$(sh -lc 'echo $PATH')/\$PATH}" > /etc/profile.d/00-restore-env.sh
|
||||
chmod +x /etc/profile.d/00-restore-env.sh
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
sudo_if() {
|
||||
COMMAND="$*"
|
||||
if [ "$(id -u)" -eq 0 ] && [ "$USERNAME" != "root" ]; then
|
||||
su - "$USERNAME" -c "$COMMAND"
|
||||
else
|
||||
"$COMMAND"
|
||||
fi
|
||||
}
|
||||
|
||||
update_package() {
|
||||
PYTHON_PATH=$1
|
||||
PACKAGE=$2
|
||||
VERSION=$3
|
||||
|
||||
sudo_if "$PYTHON_PATH -m pip uninstall --yes $PACKAGE"
|
||||
sudo_if "$PYTHON_PATH -m pip install --upgrade --no-cache-dir $PACKAGE==$VERSION"
|
||||
sudo_if "$PYTHON_PATH -m pip show --no-python-version-warning $PACKAGE"
|
||||
}
|
||||
# Updating pip version for python 3.11. Must be removed when pinned version 3.11 is updated to a different python version.
|
||||
sudo_if /usr/local/python/3.11.*/bin/python -m pip install --upgrade pip
|
||||
|
||||
# https://github.com/advisories/GHSA-5rjg-fvgr-3xxf
|
||||
# Updating setuptools version for python 3.11. Must be removed when pinned version 3.11 is updated to a different python version.
|
||||
update_package /usr/local/python/3.11.*/bin/python setuptools "78.1.1"
|
||||
Reference in New Issue
Block a user