diff --git a/.env b/.env new file mode 100644 index 0000000..aa847e0 --- /dev/null +++ b/.env @@ -0,0 +1 @@ +COMPOSE_PROJECT_NAME=devcontainers diff --git a/authorized_keys b/authorized_keys new file mode 100644 index 0000000..abda02d --- /dev/null +++ b/authorized_keys @@ -0,0 +1 @@ +ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEXPddCUCbsAShg6+21q/MIvFM27xlqVr+Yg3MoHqUZp diff --git a/combined-init.sh b/combined-init.sh new file mode 100644 index 0000000..1716374 --- /dev/null +++ b/combined-init.sh @@ -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 "$@" diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..ccdff39 --- /dev/null +++ b/docker-compose.yml @@ -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: diff --git a/once-init.sh b/once-init.sh new file mode 100644 index 0000000..74e4859 --- /dev/null +++ b/once-init.sh @@ -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