Compare commits
6 Commits
4285293f82
...
f7cb2a948c
| Author | SHA1 | Date | |
|---|---|---|---|
| f7cb2a948c | |||
| e123799495 | |||
| 200a08e816 | |||
| c06c1f3404 | |||
| 3e4c54e29a | |||
| 41ad420c72 |
1
authorized_keys
Normal file
1
authorized_keys
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEXPddCUCbsAShg6+21q/MIvFM27xlqVr+Yg3MoHqUZp
|
||||||
29
build.sh
Normal file
29
build.sh
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export REGISTRY=registry.yqxpro.com
|
||||||
|
|
||||||
|
pushd common-base
|
||||||
|
npx devcontainer build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--image-name ${REGISTRY}/devcontainers/common-base --push \
|
||||||
|
--cache-to type=registry,ref=${REGISTRY}/devcontainers/common-base:buildcache,mode=max \
|
||||||
|
--cache-from type=registry,ref=${REGISTRY}/devcontainers/common-base:buildcache
|
||||||
|
popd
|
||||||
|
|
||||||
|
pushd develop-base
|
||||||
|
npx devcontainer build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--image-name ${REGISTRY}/devcontainers/develop-base --push \
|
||||||
|
--cache-to type=registry,ref=${REGISTRY}/devcontainers/develop-base:buildcache,mode=max \
|
||||||
|
--cache-from type=registry,ref=${REGISTRY}/devcontainers/develop-base:buildcache
|
||||||
|
popd
|
||||||
|
|
||||||
|
pushd universal-base
|
||||||
|
npx devcontainer build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--image-name ${REGISTRY}/devcontainers/universal-base --push \
|
||||||
|
--cache-to type=registry,ref=${REGISTRY}/devcontainers/universal-base:buildcache,mode=max \
|
||||||
|
--cache-from type=registry,ref=${REGISTRY}/devcontainers/universal-base:buildcache
|
||||||
|
popd
|
||||||
37
build/build-image.sh
Normal file
37
build/build-image.sh
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
export BUILDX_BUILDER=hk-builder
|
||||||
|
|
||||||
|
export REGISTRY="registry.yqxpro.com"
|
||||||
|
|
||||||
|
export S3_ENDPOINT_URL=https://oss-cn-hongkong-internal.aliyuncs.com
|
||||||
|
export S3_REGION=cn-hongkong
|
||||||
|
export S3_BUCKET=hk-builder-cache-yqxpro
|
||||||
|
export S3_ACCESSKEY=LTAI5t8AtjWfsqQWYnyBeCjH
|
||||||
|
export S3_SECRETKEY=UPKF20AmcW2zB5BwAMIQeQgZeTkMEs
|
||||||
|
export S3_CONFIG=endpoint_url=${S3_ENDPOINT_URL},region=${S3_REGION},bucket=${S3_BUCKET},access_key_id=${S3_ACCESSKEY},secret_access_key=${S3_SECRETKEY}
|
||||||
|
|
||||||
|
build() {
|
||||||
|
local target="$1"
|
||||||
|
|
||||||
|
echo "Build $target started"
|
||||||
|
|
||||||
|
pushd $target
|
||||||
|
npx devcontainer build \
|
||||||
|
--platform linux/amd64,linux/arm64 \
|
||||||
|
--image-name ${REGISTRY}/devcontainers/$target --push \
|
||||||
|
--cache-to type=s3,${S3_CONFIG},prefix=$target/,mode=max \
|
||||||
|
--cache-from type=s3,${S3_CONFIG},prefix=$target/
|
||||||
|
popd
|
||||||
|
|
||||||
|
echo "Build $target completed"
|
||||||
|
}
|
||||||
|
|
||||||
|
main() {
|
||||||
|
for target in "$@"; do
|
||||||
|
build "$target"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
main "$@"
|
||||||
10
build/builder-setup.sh
Normal file
10
build/builder-setup.sh
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
export TARGET_USER=ecs-user
|
||||||
|
export REGISTRY_IP=172.22.178.82
|
||||||
|
|
||||||
|
curl -fsSL https://raw.githubusercontent.com/docker/docker-install/master/install.sh | sh
|
||||||
|
sudo usermod -aG docker $TARGET_USER
|
||||||
|
|
||||||
|
echo "$REGISTRY_IP registry.yqxpro.com" | sudo tee -a /etc/hosts
|
||||||
19
build/host-setup.sh
Normal file
19
build/host-setup.sh
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
# SSH 配置中先准备好 hk-builder-linux-arm64 和 hk-builder-linux-amd64
|
||||||
|
docker buildx create \
|
||||||
|
--name hk-builder \
|
||||||
|
--driver docker-container \
|
||||||
|
--driver-opt network=host \
|
||||||
|
--platform linux/amd64 \
|
||||||
|
--node hk-builder-linux-amd64 \
|
||||||
|
ssh://hk-builder-linux-amd64
|
||||||
|
docker buildx create \
|
||||||
|
--name hk-builder \
|
||||||
|
--driver docker-container \
|
||||||
|
--driver-opt network=host \
|
||||||
|
--platform linux/arm64 \
|
||||||
|
--append \
|
||||||
|
--node hk-builder-linux-arm64 \
|
||||||
|
ssh://hk-builder-linux-arm64
|
||||||
36
build/publish-image.sh
Normal file
36
build/publish-image.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
export REGISTRY=registry.yqxpro.com
|
||||||
|
export REGISTRY_PUBLISH=crpi-kbfsbvlqwt19zxum-vpc.cn-hongkong.personal.cr.aliyuncs.com/registry-yqxpro
|
||||||
|
export TAG=$(git rev-parse --short HEAD)
|
||||||
|
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y skopeo
|
||||||
|
|
||||||
|
docker login $REGISTRY_PUBLISH
|
||||||
|
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/common-base:latest \
|
||||||
|
docker://${REGISTRY_PUBLISH}/devcontainers-common-base:latest
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/common-base:latest \
|
||||||
|
docker://${REGISTRY_PUBLISH}/devcontainers-common-base:${TAG}
|
||||||
|
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/develop-base:latest \
|
||||||
|
docker://${REGISTRY_PUBLISH}/devcontainers-develop-base:latest
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/develop-base:latest \
|
||||||
|
docker://${REGISTRY_PUBLISH}/devcontainers-develop-base:${TAG}
|
||||||
|
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/universal-base:latest \
|
||||||
|
docker://${REGISTRY_PUBLISH}/devcontainers-universal-base:latest
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/universal-base:latest \
|
||||||
|
docker://${REGISTRY_PUBLISH}/devcontainers-universal-base:${TAG}
|
||||||
|
|
||||||
|
skopeo copy --all \
|
||||||
|
docker://${REGISTRY}/devcontainers/universal-base:latest \
|
||||||
|
oci-archive:devcontainers-universal-base.tar
|
||||||
13
build/registry-setup.sh
Normal file
13
build/registry-setup.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
tar xvzf certs.tgz
|
||||||
|
docker run -d \
|
||||||
|
--restart=always \
|
||||||
|
--name registry \
|
||||||
|
-v "$(pwd)"/certs:/certs \
|
||||||
|
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
|
||||||
|
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.yqxpro.com.crt \
|
||||||
|
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.yqxpro.com.key \
|
||||||
|
-p 443:443 \
|
||||||
|
registry:3
|
||||||
13
combined-init.sh
Normal file
13
combined-init.sh
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
/usr/local/share/desktop-init.sh echo "Desktop initialization complete"
|
||||||
|
/usr/local/share/docker-init.sh echo "Docker initialization complete"
|
||||||
|
/usr/local/share/ssh-init.sh echo "SSH initialization complete"
|
||||||
|
|
||||||
|
# exposed ports
|
||||||
|
# 5901 VNC
|
||||||
|
# 6080 noVNC
|
||||||
|
# 2222 SSH
|
||||||
|
|
||||||
|
exec "$@"
|
||||||
83
common-base/.devcontainer/Dockerfile
Normal file
83
common-base/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,83 @@
|
|||||||
|
FROM ubuntu:noble
|
||||||
|
|
||||||
|
RUN if id "ubuntu" &>/dev/null; then \
|
||||||
|
echo "Deleting user 'ubuntu' for noble" && userdel -f -r ubuntu || echo "Failed to delete ubuntu user for noble"; \
|
||||||
|
else \
|
||||||
|
echo "User 'ubuntu' does not exist for noble"; \
|
||||||
|
fi
|
||||||
|
|
||||||
|
ENV LANG="C.UTF-8"
|
||||||
|
|
||||||
|
#Merging the mutiple layers to reduce the size of the image slightly
|
||||||
|
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
|
||||||
|
# Restore man command
|
||||||
|
&& yes | unminimize 2>&1 \
|
||||||
|
# Install basic build tools
|
||||||
|
&& apt-get upgrade -y \
|
||||||
|
&& DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
|
||||||
|
make \
|
||||||
|
unzip \
|
||||||
|
# The tools in this package are used when installing packages for Python
|
||||||
|
build-essential \
|
||||||
|
swig3.0 \
|
||||||
|
# Required for Microsoft SQL Server
|
||||||
|
unixodbc-dev \
|
||||||
|
# Required for PostgreSQL
|
||||||
|
libpq-dev \
|
||||||
|
# Required for mysqlclient
|
||||||
|
default-libmysqlclient-dev \
|
||||||
|
# Required for ts
|
||||||
|
moreutils \
|
||||||
|
rsync \
|
||||||
|
zip \
|
||||||
|
libgdiplus \
|
||||||
|
jq \
|
||||||
|
# By default pip is not available in the buildpacks image
|
||||||
|
python3-pip \
|
||||||
|
#.NET Core related pre-requisites
|
||||||
|
libc6 \
|
||||||
|
libgcc1 \
|
||||||
|
libgssapi-krb5-2 \
|
||||||
|
libncurses6 \
|
||||||
|
liblttng-ust1 \
|
||||||
|
libssl-dev \
|
||||||
|
libstdc++6 \
|
||||||
|
zlib1g \
|
||||||
|
libuuid1 \
|
||||||
|
libunwind8 \
|
||||||
|
sqlite3 \
|
||||||
|
libsqlite3-dev \
|
||||||
|
software-properties-common \
|
||||||
|
tk-dev \
|
||||||
|
uuid-dev \
|
||||||
|
curl \
|
||||||
|
gettext \
|
||||||
|
inotify-tools \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
# This is the folder containing 'links' to benv and build script generator
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get upgrade -y \
|
||||||
|
&& add-apt-repository universe \
|
||||||
|
&& rm -rf /var/lib/apt/lists/* \
|
||||||
|
# Verify expected build and debug tools are present
|
||||||
|
&& apt-get update \
|
||||||
|
&& apt-get -y install build-essential cmake cppcheck valgrind clang lldb llvm gdb python3-dev \
|
||||||
|
# Install tools and shells not in common script
|
||||||
|
&& apt-get install -yq vim vim-doc xtail software-properties-common libsecret-1-dev \
|
||||||
|
# Clean up
|
||||||
|
&& apt-get autoremove -y && apt-get clean -y \
|
||||||
|
# Move first run notice to right spot
|
||||||
|
&& mkdir -p "/usr/local/etc/vscode-dev-containers/" \
|
||||||
|
# Install and setup fish
|
||||||
|
&& apt-get install -yq fish \
|
||||||
|
&& FISH_PROMPT="function fish_prompt\n set_color green\n echo -n (whoami)\n set_color normal\n echo -n \":\"\n set_color blue\n echo -n (pwd)\n set_color normal\n echo -n \"> \"\nend\n" \
|
||||||
|
&& printf "$FISH_PROMPT" >> /etc/fish/functions/fish_prompt.fish \
|
||||||
|
&& printf "if type code-insiders > /dev/null 2>&1; and not type code > /dev/null 2>&1\n alias code=code-insiders\nend" >> /etc/fish/conf.d/code_alias.fish \
|
||||||
|
# Remove scripts now that we're done with them
|
||||||
|
&& apt-get clean -y && rm -rf /tmp/scripts
|
||||||
|
|
||||||
|
# Default to bash shell (other shells available at /usr/bin/fish and /usr/bin/zsh)
|
||||||
|
ENV SHELL=/bin/bash \
|
||||||
|
DOCKER_BUILDKIT=1
|
||||||
|
|
||||||
|
CMD [ "sleep", "infinity" ]
|
||||||
37
common-base/.devcontainer/devcontainer.json
Normal file
37
common-base/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"dockerfile": "./Dockerfile",
|
||||||
|
"context": ".",
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/common-utils:2": {
|
||||||
|
"username": "codespace",
|
||||||
|
"userUid": "1000",
|
||||||
|
"userGid": "1000",
|
||||||
|
},
|
||||||
|
"ghcr.io/devcontainers/features/sshd:1": {
|
||||||
|
"gatewayPorts": "yes",
|
||||||
|
},
|
||||||
|
"ghcr.io/devcontainers/features/desktop-lite:1": {
|
||||||
|
"password": "noPassword",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"remoteUser": "codespace",
|
||||||
|
"containerUser": "codespace",
|
||||||
|
|
||||||
|
// Use 'forwardPorts' to make a list of ports inside the container available locally.
|
||||||
|
// "forwardPorts": [],
|
||||||
|
|
||||||
|
// Configure tool-specific properties.
|
||||||
|
"customizations": {
|
||||||
|
// Configure properties specific to VS Code.
|
||||||
|
"vscode": {
|
||||||
|
// Set *default* container specific settings.json values on container create.
|
||||||
|
"settings": {
|
||||||
|
"lldb.executable": "/usr/bin/lldb",
|
||||||
|
},
|
||||||
|
// Add the IDs of extensions you want installed when the container is created.
|
||||||
|
"extensions": [],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
4
develop-base/.devcontainer/Dockerfile
Normal file
4
develop-base/.devcontainer/Dockerfile
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
FROM registry.yqxpro.com/devcontainers/common-base
|
||||||
|
|
||||||
|
# Mount for docker-in-docker
|
||||||
|
VOLUME [ "/var/lib/docker" ]
|
||||||
12
develop-base/.devcontainer/devcontainer.json
Normal file
12
develop-base/.devcontainer/devcontainer.json
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"build": {
|
||||||
|
"dockerfile": "./Dockerfile",
|
||||||
|
"context": ".",
|
||||||
|
},
|
||||||
|
"features": {
|
||||||
|
"ghcr.io/devcontainers/features/git:1": {},
|
||||||
|
"ghcr.io/devcontainers/features/git-lfs:1": {},
|
||||||
|
"ghcr.io/devcontainers/features/docker-in-docker:2": {},
|
||||||
|
"ghcr.io/devcontainers/features/kubectl-helm-minikube:1": {},
|
||||||
|
},
|
||||||
|
}
|
||||||
33
docker-compose.yml
Normal file
33
docker-compose.yml
Normal file
@@ -0,0 +1,33 @@
|
|||||||
|
services:
|
||||||
|
dev-server:
|
||||||
|
image: registry.yqxpro.com/devcontainers/universal-base:latest
|
||||||
|
privileged: true
|
||||||
|
restart: always
|
||||||
|
ports:
|
||||||
|
- 2222:2222
|
||||||
|
- 6080:6080
|
||||||
|
volumes:
|
||||||
|
# environment
|
||||||
|
- ${PWD}/authorized_keys:/home/codespace/.ssh/authorized_keys
|
||||||
|
- ${PWD}/combined-init.sh:/usr/local/share/combined-init.sh
|
||||||
|
- ${PWD}/once-init.sh:/usr/local/share/once-init.sh
|
||||||
|
# workspace
|
||||||
|
- workspace:/workspace
|
||||||
|
# cache
|
||||||
|
- maven-cache:/home/codespace/.m2/repository
|
||||||
|
- docker-cache:/var/lib/docker
|
||||||
|
- apt-cache:/var/cache/apt
|
||||||
|
- vscode-cache:/home/codespace/.vscode-server
|
||||||
|
- zed-cache:/home/codespace/.zed_server
|
||||||
|
entrypoint: /usr/local/share/combined-init.sh
|
||||||
|
command: sleep infinity
|
||||||
|
|
||||||
|
volumes:
|
||||||
|
workspace:
|
||||||
|
name: dev-server-workspace
|
||||||
|
external: true
|
||||||
|
maven-cache:
|
||||||
|
docker-cache:
|
||||||
|
apt-cache:
|
||||||
|
vscode-cache:
|
||||||
|
zed-cache:
|
||||||
36
once-init.sh
Normal file
36
once-init.sh
Normal file
@@ -0,0 +1,36 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
set -eux
|
||||||
|
|
||||||
|
# use VNC DISPLAY by default
|
||||||
|
echo "export DISPLAY=:1.0" >> /etc/profile.d/00-restore-env.sh
|
||||||
|
|
||||||
|
mkdir -pv /home/codespace/.cargo
|
||||||
|
cat > /home/codespace/.cargo/config.toml << EOF
|
||||||
|
[source.crates-io]
|
||||||
|
replace-with = 'aliyun'
|
||||||
|
|
||||||
|
[source.mirror]
|
||||||
|
registry = "sparse+https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/"
|
||||||
|
|
||||||
|
[source.aliyun]
|
||||||
|
registry = "sparse+https://mirrors.aliyun.com/crates.io-index/"
|
||||||
|
|
||||||
|
#[registries.mirror]
|
||||||
|
#index = "sparse+https://mirrors.tuna.tsinghua.edu.cn/crates.io-index/"
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# fix permissions
|
||||||
|
chown -R codespace:codespace /workspace
|
||||||
|
chown -R codespace:codespace /home/codespace/
|
||||||
|
chmod 700 /home/codespace/.ssh
|
||||||
|
chmod 600 /home/codespace/.ssh/authorized_keys
|
||||||
|
|
||||||
|
# configuration
|
||||||
|
sudo -u codespace git config --global user.email "me@yqxpro.com"
|
||||||
|
sudo -u codespace git config --global user.name "QXYang686"
|
||||||
|
|
||||||
|
sudo -u codespace npm config set registry https://registry.npmmirror.com
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
sudo -u codespace ln -snf /workspace/dev-server /home/codespace/Projects
|
||||||
23
system-setup.sh
Normal file
23
system-setup.sh
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
sudo apt update
|
||||||
|
sudo apt install -y npm git
|
||||||
|
curl -fsSL https://raw.githubusercontent.com/docker/docker-install/master/install.sh | sh
|
||||||
|
sudo usermod -aG docker $USER
|
||||||
|
docker buildx create --use --bootstrap --name multiarch-builder --driver-opt network=host
|
||||||
|
echo "127.0.0.1 registry.yqxpro.com" | sudo tee -a /etc/hosts
|
||||||
|
|
||||||
|
tar xvzf certs.tgz
|
||||||
|
docker run -d \
|
||||||
|
--restart=always \
|
||||||
|
--name registry \
|
||||||
|
-v "$(pwd)"/certs:/certs \
|
||||||
|
-e REGISTRY_HTTP_ADDR=0.0.0.0:443 \
|
||||||
|
-e REGISTRY_HTTP_TLS_CERTIFICATE=/certs/registry.yqxpro.com.crt \
|
||||||
|
-e REGISTRY_HTTP_TLS_KEY=/certs/registry.yqxpro.com.key \
|
||||||
|
-p 443:443 \
|
||||||
|
registry:3
|
||||||
|
|
||||||
|
git clone https://gitea.yqxpro.com/QXYang686/devcontainers.git
|
||||||
|
cd devcontainers
|
||||||
|
npm install
|
||||||
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