开发容器配置-初版
This commit is contained in:
1
universal-base/.devcontainer/Dockerfile
Normal file
1
universal-base/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1 @@
|
||||
FROM registry.yqxpro.com/devcontainers/develop-base
|
||||
66
universal-base/.devcontainer/devcontainer.json
Normal file
66
universal-base/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,66 @@
|
||||
{
|
||||
"build": {
|
||||
"dockerfile": "./Dockerfile",
|
||||
"context": ".",
|
||||
},
|
||||
"features": {
|
||||
"ghcr.io/devcontainers/features/node:1": {
|
||||
"version": "22",
|
||||
"additionalVersions": "18,22,24",
|
||||
},
|
||||
"./local-features/nvs": "latest",
|
||||
"ghcr.io/devcontainers/features/python:1": {
|
||||
"version": "3.12.1",
|
||||
"installJupyterlab": "true",
|
||||
"configureJupyterlabAllowOrigin": "*",
|
||||
},
|
||||
"ghcr.io/devcontainers/features/anaconda:1": {},
|
||||
"ghcr.io/devcontainers/features/java:1": {
|
||||
"jdkDistro": "tem",
|
||||
"version": "21",
|
||||
"additionalVersions": "8,21,25",
|
||||
"installGradle": "true",
|
||||
"installMaven": "true",
|
||||
},
|
||||
"ghcr.io/devcontainers/features/go:1": {},
|
||||
"ghcr.io/devcontainers/features/rust:1": {
|
||||
"profile": "complete",
|
||||
},
|
||||
"./local-features/setup-user": "latest",
|
||||
},
|
||||
// Configure tool-specific properties.
|
||||
"customizations": {
|
||||
// Configure properties specific to VS Code.
|
||||
"vscode": {
|
||||
// Set *default* container specific settings.json values on container create.
|
||||
"settings": {
|
||||
"go.toolsManagement.checkForUpdates": "local",
|
||||
"go.useLanguageServer": true,
|
||||
"go.gopath": "/go",
|
||||
"python.defaultInterpreterPath": "/home/codespace/.python/current/bin/python3",
|
||||
"jupyter.kernels.filter": [
|
||||
{
|
||||
"path": "/opt/conda/bin/python",
|
||||
"type": "pythonEnvironment",
|
||||
},
|
||||
{
|
||||
"path": "/usr/local/python/current/bin/python3",
|
||||
"type": "pythonEnvironment",
|
||||
},
|
||||
{
|
||||
"path": "/usr/local/python/current/bin/python",
|
||||
"type": "pythonEnvironment",
|
||||
},
|
||||
{
|
||||
"path": "/usr/bin/python3",
|
||||
"type": "pythonEnvironment",
|
||||
},
|
||||
{
|
||||
"path": "/bin/python3",
|
||||
"type": "pythonEnvironment",
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
{
|
||||
"id": "nvs",
|
||||
"name": "Node Version Switcher",
|
||||
"containerEnv": {
|
||||
"NVS_DIR": "/usr/local/nvs",
|
||||
"PATH": "${NVS_DIR}:${PATH}"
|
||||
},
|
||||
"install": {
|
||||
"app": "",
|
||||
"file": "install.sh"
|
||||
}
|
||||
}
|
||||
79
universal-base/.devcontainer/local-features/nvs/install.sh
Normal file
79
universal-base/.devcontainer/local-features/nvs/install.sh
Normal file
@@ -0,0 +1,79 @@
|
||||
#!/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"}
|
||||
NVS_HOME=${NVS_HOME:-"/usr/local/nvs"}
|
||||
|
||||
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
|
||||
|
||||
# Function to run apt-get if needed
|
||||
apt_get_update_if_needed()
|
||||
{
|
||||
if [ ! -d "/var/lib/apt/lists" ] || [ "$(ls /var/lib/apt/lists/ | wc -l)" = "0" ]; then
|
||||
echo "Running apt-get update..."
|
||||
apt-get update
|
||||
else
|
||||
echo "Skipping apt-get update."
|
||||
fi
|
||||
}
|
||||
|
||||
# Checks if packages are installed and installs them if not
|
||||
check_packages() {
|
||||
if ! dpkg -s "$@" > /dev/null 2>&1; then
|
||||
apt_get_update_if_needed
|
||||
apt-get -y install --no-install-recommends "$@"
|
||||
fi
|
||||
}
|
||||
|
||||
updaterc() {
|
||||
echo "Updating /etc/bash.bashrc and /etc/zsh/zshrc..."
|
||||
if [[ "$(cat /etc/bash.bashrc)" != *"$1"* ]]; then
|
||||
echo -e "$1" >> /etc/bash.bashrc
|
||||
fi
|
||||
if [ -f "/etc/zsh/zshrc" ] && [[ "$(cat /etc/zsh/zshrc)" != *"$1"* ]]; then
|
||||
echo -e "$1" >> /etc/zsh/zshrc
|
||||
fi
|
||||
}
|
||||
|
||||
export DEBIAN_FRONTEND=noninteractive
|
||||
|
||||
if ! cat /etc/group | grep -e "^nvs:" > /dev/null 2>&1; then
|
||||
groupadd -r nvs
|
||||
fi
|
||||
usermod -a -G nvs "${USERNAME}"
|
||||
|
||||
git config --global --add safe.directory ${NVS_HOME}
|
||||
mkdir -p ${NVS_HOME}
|
||||
|
||||
git clone -c advice.detachedHead=false --depth 1 https://github.com/jasongin/nvs ${NVS_HOME} 2>&1
|
||||
(cd ${NVS_HOME} && git remote get-url origin && echo $(git log -n 1 --pretty=format:%H -- .)) > ${NVS_HOME}/.git-remote-and-commit
|
||||
bash ${NVS_HOME}/nvs.sh install
|
||||
rm ${NVS_HOME}/cache/*
|
||||
|
||||
# Clean up
|
||||
rm -rf ${NVS_HOME}/.git
|
||||
|
||||
updaterc "if [[ \"\${PATH}\" != *\"${NVS_HOME}\"* ]]; then export PATH=${NVS_HOME}:\${PATH}; fi"
|
||||
|
||||
chown -R "${USERNAME}:nvs" "${NVS_HOME}"
|
||||
chmod -R g+r+w "${NVS_HOME}"
|
||||
find "${NVS_HOME}" -type d | xargs -n 1 chmod g+s
|
||||
|
||||
NVS="/home/codespace/.nvs"
|
||||
mkdir -p ${NVS}
|
||||
ln -snf ${NVS_HOME}/* $NVS
|
||||
|
||||
echo "Done!"
|
||||
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"id": "setup-user",
|
||||
"name": "Setup user configs",
|
||||
"containerEnv": {
|
||||
"JAVA_ROOT": "/home/codespace/java",
|
||||
"NODE_ROOT": "/home/codespace/nvm",
|
||||
"PYTHON_ROOT": "/home/codespace/.python",
|
||||
"MAVEN_ROOT": "/home/codespace/.maven",
|
||||
"PYTHONIOENCODING": "UTF-8",
|
||||
"NPM_GLOBAL": "/home/codespace/.npm-global",
|
||||
"NVS_HOME": "/home/codespace/.nvs",
|
||||
"GOROOT": "/usr/local/go",
|
||||
"JUPYTERLAB_PATH": "/home/codespace/.local/bin",
|
||||
"PATH": "/home/codespace/nvm/current/bin:/home/codespace/.python/current/bin:/home/codespace/java/current/bin:/home/codespace/.local/bin:${PATH}"
|
||||
},
|
||||
"install": {
|
||||
"app": "",
|
||||
"file": "install.sh"
|
||||
},
|
||||
"installsAfter": [
|
||||
"ghcr.io/devcontainers/features/node:1",
|
||||
"./local-features/nvs",
|
||||
"ghcr.io/devcontainers/features/python:1",
|
||||
"ghcr.io/devcontainers/features/anaconda:1",
|
||||
"ghcr.io/devcontainers/features/java:1",
|
||||
"ghcr.io/devcontainers/features/go:1",
|
||||
"ghcr.io/devcontainers/features/rust:1"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
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
|
||||
touch /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
|
||||
}
|
||||
|
||||
NODE_PATH="/home/codespace/nvm/current"
|
||||
ln -snf /usr/local/share/nvm /home/codespace
|
||||
|
||||
PYTHON_PATH="/home/${USERNAME}/.python/current"
|
||||
mkdir -p /home/${USERNAME}/.python
|
||||
ln -snf /usr/local/python/current $PYTHON_PATH
|
||||
ln -snf /usr/local/python /opt/python
|
||||
|
||||
JAVA_PATH="/home/codespace/java/current"
|
||||
ln -snf /usr/local/sdkman/candidates/java /home/codespace
|
||||
|
||||
MAVEN_PATH="/home/${USERNAME}/.maven/current"
|
||||
mkdir -p /home/${USERNAME}/.maven
|
||||
ln -snf /usr/local/sdkman/candidates/maven/current $MAVEN_PATH
|
||||
|
||||
echo "Defaults secure_path=\"${NODE_PATH}/bin:${PYTHON_PATH}/bin:${JAVA_PATH}/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin:/usr/local/share:/home/${USERNAME}/.local/bin:${PATH}\"" >> /etc/sudoers.d/$USERNAME
|
||||
|
||||
echo "Done!"
|
||||
Reference in New Issue
Block a user