diff options
Diffstat (limited to 'docker/debian-dev')
29 files changed, 384 insertions, 0 deletions
diff --git a/docker/debian-dev/Dockerfile b/docker/debian-dev/Dockerfile new file mode 100644 index 0000000..95f0602 --- /dev/null +++ b/docker/debian-dev/Dockerfile @@ -0,0 +1,21 @@ +FROM debian:latest + +ARG USER=crupest +ARG IN_CHINA= +ARG CODE_SERVER=true + +ENV CRUPEST_DEBIAN_DEV_USER=${USER} +ENV CRUPEST_DEBIAN_DEV_IN_CHINA=${IN_CHINA} +ENV CRUPEST_DEBIAN_DEV_SETUP_CODE_SERVER=${CODE_SERVER} + +ADD bootstrap /bootstrap + +RUN /bootstrap/setup.bash +ENV LANG=en_US.utf8 + +USER ${USER} +WORKDIR /home/${USER} + +EXPOSE 8080 +VOLUME [ "/data", "/home/${USER}" ] +CMD [ "bash", "-l" ] diff --git a/docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash b/docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash new file mode 100644 index 0000000..e134a00 --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/11/add-deb-src.bash @@ -0,0 +1,14 @@ +#! /usr/bin/env bash + +set -e + +dir=$(dirname "$0") +domain=$("$dir/get-domain.bash") + +cat <<EOF >> /etc/apt/sources.list + +deb-src https://$domain/debian/ bullseye main +deb-src https://$domain/debian-security/ bullseye-security main +deb-src https://$domain/debian-updates/ bullseye-updates main + +EOF diff --git a/docker/debian-dev/bootstrap/apt-source/11/get-domain.bash b/docker/debian-dev/bootstrap/apt-source/11/get-domain.bash new file mode 100644 index 0000000..d44ea65 --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/11/get-domain.bash @@ -0,0 +1,5 @@ +#! /usr/bin/env bash + +set -e + +sed "s|.*https\?://\([-_.a-zA-Z0-9]\+\)/.*|\\1|;q" /etc/apt/sources.list diff --git a/docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash b/docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash new file mode 100644 index 0000000..86e88dc --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/11/replace-domain.bash @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -e + +echo "Backup /etc/apt/sources.list to /etc/apt/sources.list.bak." +echo "Replace source domain in /etc/apt/sources.list to $1." +sed -i.bak "s|\(https\?://\)[-_.a-zA-Z0-9]\+/|\\1$1/|" /etc/apt/sources.list diff --git a/docker/debian-dev/bootstrap/apt-source/11/replace-http.bash b/docker/debian-dev/bootstrap/apt-source/11/replace-http.bash new file mode 100644 index 0000000..fae082a --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/11/replace-http.bash @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -e + +echo "Backup /etc/apt/sources.list to /etc/apt/sources.list.bak." +echo "Replace http to https in /etc/apt/sources.list." +sed -i.bak 's/https\?/https/' /etc/apt/sources.list diff --git a/docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash b/docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash new file mode 100644 index 0000000..cf741d6 --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/12/add-deb-src.bash @@ -0,0 +1,22 @@ +#! /usr/bin/env bash + +set -e + +dir=$(dirname "$0") +domain=$("$dir/get-domain.bash") + +cat <<EOF >> /etc/apt/sources.list.d/debian.sources + +Types: deb-src +URIs: https://$domain/debian +Suites: bookworm bookworm-updates +Components: main +Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg + +Types: deb-src +URIs: https://$domain/debian-security +Suites: bookworm-security +Components: main +Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg + +EOF
\ No newline at end of file diff --git a/docker/debian-dev/bootstrap/apt-source/12/get-domain.bash b/docker/debian-dev/bootstrap/apt-source/12/get-domain.bash new file mode 100644 index 0000000..a24538c --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/12/get-domain.bash @@ -0,0 +1,6 @@ +#! /usr/bin/env bash + +set -e + +grep -e 'URIs:' /etc/apt/sources.list.d/debian.sources | \ + sed -E 's|URIs:\s*https?://([-_.a-zA-Z0-9]+)/.*|\1|;q' diff --git a/docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash b/docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash new file mode 100644 index 0000000..d55307c --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/12/replace-domain.bash @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -e + +echo "Backup /etc/apt/sources.list.d/debian.sources to /etc/apt/sources.list.d/debian.sources.bak." +echo "Replace source domain in /etc/apt/sources.list.d/debian.sources to $1." +sed -i.bak -E "s|(URIs:\\s*https?://)[-_.a-zA-Z0-9]+(/.*)|\\1$1\\2|" /etc/apt/sources.list.d/debian.sources diff --git a/docker/debian-dev/bootstrap/apt-source/12/replace-http.bash b/docker/debian-dev/bootstrap/apt-source/12/replace-http.bash new file mode 100644 index 0000000..ed4391d --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/12/replace-http.bash @@ -0,0 +1,7 @@ +#! /usr/bin/env bash + +set -e + +echo "Backup /etc/apt/sources.list to /etc/apt/sources.list.d/debian.sources.bak." +echo "Replace http to https in /etc/apt/sources.list.d/debian.sources." +sed -i.bak -E "s|(URIs:\\s*)https?(://[-_.a-zA-Z0-9]+/.*)|\\1https\\2|" /etc/apt/sources.list.d/debian.sources diff --git a/docker/debian-dev/bootstrap/apt-source/china-source.txt b/docker/debian-dev/bootstrap/apt-source/china-source.txt new file mode 100644 index 0000000..4312686 --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/china-source.txt @@ -0,0 +1 @@ +mirrors.tuna.tsinghua.edu.cn
\ No newline at end of file diff --git a/docker/debian-dev/bootstrap/apt-source/install-apt-https.bash b/docker/debian-dev/bootstrap/apt-source/install-apt-https.bash new file mode 100644 index 0000000..70fb371 --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/install-apt-https.bash @@ -0,0 +1,8 @@ +#! /usr/bin/env bash + +set -e + +echo "Install apt https transport." +apt-get update +apt-get install -y apt-utils +apt-get install -y apt-transport-https ca-certificates diff --git a/docker/debian-dev/bootstrap/apt-source/setup.bash b/docker/debian-dev/bootstrap/apt-source/setup.bash new file mode 100644 index 0000000..cdf68af --- /dev/null +++ b/docker/debian-dev/bootstrap/apt-source/setup.bash @@ -0,0 +1,34 @@ +#! /usr/bin/env bash + +set -e + +dir=/bootstrap/apt-source + +echo "Getting debian version..." +debian_version=$("$dir/../get-debian-version.bash") + +if [[ -z $debian_version ]]; then + echo "Debian version not found." + exit 1 +else + echo "Debian version: $debian_version" +fi + +if [[ $debian_version -ge 12 ]]; then + setup_dir=$dir/12 +else + setup_dir=$dir/11 +fi + +echo "Setting up apt source..." + +if [[ -n $CRUPEST_DEBIAN_DEV_IN_CHINA ]]; then + echo "In China, using China source..." + "$setup_dir/replace-domain.bash" "$(cat "$dir/china-source.txt")" +fi + +"$dir/install-apt-https.bash" +"$setup_dir/replace-http.bash" +"$setup_dir/add-deb-src.bash" + +echo "Setting up apt source done." diff --git a/docker/debian-dev/bootstrap/bash/bash-completion.bash b/docker/debian-dev/bootstrap/bash/bash-completion.bash new file mode 100644 index 0000000..75f8333 --- /dev/null +++ b/docker/debian-dev/bootstrap/bash/bash-completion.bash @@ -0,0 +1,4 @@ +if [ -f /etc/bash_completion ]; then + . /etc/bash_completion +fi + diff --git a/docker/debian-dev/bootstrap/bash/code-server.bash b/docker/debian-dev/bootstrap/bash/code-server.bash new file mode 100644 index 0000000..255c280 --- /dev/null +++ b/docker/debian-dev/bootstrap/bash/code-server.bash @@ -0,0 +1,2 @@ +mkdir -p ~/.local/share/code-server +/bootstrap/start/code-server.bash > ~/.local/share/code-server/log 2> ~/.local/share/code-server/error & diff --git a/docker/debian-dev/bootstrap/bash/dquilt.bash b/docker/debian-dev/bootstrap/bash/dquilt.bash new file mode 100644 index 0000000..96a4eb2 --- /dev/null +++ b/docker/debian-dev/bootstrap/bash/dquilt.bash @@ -0,0 +1,4 @@ +alias dquilt="quilt --quiltrc=${HOME}/.quiltrc-dpkg" +. /usr/share/bash-completion/completions/quilt +complete -F _quilt_completion $_quilt_complete_opt dquilt + diff --git a/docker/debian-dev/bootstrap/extra/setup-cmake.bash b/docker/debian-dev/bootstrap/extra/setup-cmake.bash new file mode 100644 index 0000000..76c1ae4 --- /dev/null +++ b/docker/debian-dev/bootstrap/extra/setup-cmake.bash @@ -0,0 +1,9 @@ +#! /usr/bin/env bash + +set -e + +CMAKE_VERSION=$(curl -s https://api.github.com/repos/Kitware/CMake/releases/latest | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') +wget -O cmake-installer.sh https://github.com/Kitware/CMake/releases/download/v"$CMAKE_VERSION"/cmake-"$CMAKE_VERSION"-linux-x86_64.sh +chmod +x cmake-installer.sh +./cmake-installer.sh --skip-license --prefix=/usr +rm cmake-installer.sh diff --git a/docker/debian-dev/bootstrap/extra/setup-dotnet.bash b/docker/debian-dev/bootstrap/extra/setup-dotnet.bash new file mode 100644 index 0000000..0ef7743 --- /dev/null +++ b/docker/debian-dev/bootstrap/extra/setup-dotnet.bash @@ -0,0 +1,10 @@ +#! /usr/bin/env bash + +set -e + +wget https://packages.microsoft.com/config/debian/11/packages-microsoft-prod.deb -O packages-microsoft-prod.deb +dpkg -i packages-microsoft-prod.deb +rm packages-microsoft-prod.deb + +apt-get update +apt-get install -y dotnet-sdk-7.0 diff --git a/docker/debian-dev/bootstrap/extra/setup-llvm.bash b/docker/debian-dev/bootstrap/extra/setup-llvm.bash new file mode 100644 index 0000000..48dde86 --- /dev/null +++ b/docker/debian-dev/bootstrap/extra/setup-llvm.bash @@ -0,0 +1,26 @@ +#! /usr/bin/env bash + +set -e + +LLVM_VERSION=18 + +. /bootstrap/func.bash + +if is_true "$CRUPEST_DEBIAN_DEV_IN_CHINA"; then + base_url=https://mirrors.tuna.tsinghua.edu.cn/llvm-apt +else + base_url=https://apt.llvm.org +fi + +wget "$base_url/llvm.sh" +chmod +x llvm.sh +./llvm.sh $LLVM_VERSION all -m "$base_url" +rm llvm.sh + +update-alternatives --install /usr/bin/clang clang /usr/bin/clang-$LLVM_VERSION 100 \ + --slave /usr/bin/clang++ clang++ /usr/bin/clang++-$LLVM_VERSION \ + --slave /usr/bin/clangd clangd /usr/bin/clangd-$LLVM_VERSION \ + --slave /usr/bin/clang-format clang-format /usr/bin/clang-format-$LLVM_VERSION \ + --slave /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-$LLVM_VERSION \ + --slave /usr/bin/lldb lldb /usr/bin/lldb-$LLVM_VERSION \ + --slave /usr/bin/lld lld /usr/bin/lld-$LLVM_VERSION diff --git a/docker/debian-dev/bootstrap/func.bash b/docker/debian-dev/bootstrap/func.bash new file mode 100644 index 0000000..7782035 --- /dev/null +++ b/docker/debian-dev/bootstrap/func.bash @@ -0,0 +1,19 @@ +is_true() { + if [[ "$1" =~ 1|on|true ]]; then + return 0 + else + return 1 + fi +} + +append-bash-profile() { + cat "/bootstrap/bash/$1" >> /home/$CRUPEST_DEBIAN_DEV_USER/.bash_profile +} + +append-bashrc() { + cat "/bootstrap/bash/$1" >> /home/$CRUPEST_DEBIAN_DEV_USER/.bashrc +} + +copy-home-dot-file() { + cp "/bootstrap/home-dot/$1" "/home/$CRUPEST_DEBIAN_DEV_USER/.$1" +} diff --git a/docker/debian-dev/bootstrap/get-debian-version.bash b/docker/debian-dev/bootstrap/get-debian-version.bash new file mode 100644 index 0000000..2cc10b9 --- /dev/null +++ b/docker/debian-dev/bootstrap/get-debian-version.bash @@ -0,0 +1,13 @@ +#! /usr/bin/env bash + +set -e + +if [ -f /etc/os-release ]; then + . /etc/os-release + if [ "$ID" = "debian" ]; then + echo "$VERSION_ID" + exit 0 + fi +fi + +exit 1 diff --git a/docker/debian-dev/bootstrap/home-dot/devscripts b/docker/debian-dev/bootstrap/home-dot/devscripts new file mode 100644 index 0000000..a15b041 --- /dev/null +++ b/docker/debian-dev/bootstrap/home-dot/devscripts @@ -0,0 +1 @@ +export DGET_VERIFY=no
\ No newline at end of file diff --git a/docker/debian-dev/bootstrap/home-dot/quiltrc-dpkg b/docker/debian-dev/bootstrap/home-dot/quiltrc-dpkg new file mode 100644 index 0000000..e8fc3c5 --- /dev/null +++ b/docker/debian-dev/bootstrap/home-dot/quiltrc-dpkg @@ -0,0 +1,13 @@ +d=. +while [ ! -d $d/debian -a `readlink -e $d` != / ]; + do d=$d/..; done +if [ -d $d/debian ] && [ -z $QUILT_PATCHES ]; then + # if in Debian packaging tree with unset $QUILT_PATCHES + QUILT_PATCHES="debian/patches" + QUILT_PATCH_OPTS="--reject-format=unified" + QUILT_DIFF_ARGS="-p ab --no-timestamps --no-index --color=auto" + QUILT_REFRESH_ARGS="-p ab --no-timestamps --no-index" + QUILT_COLORS="diff_hdr=1;32:diff_add=1;34:diff_rem=1;31:diff_hunk=1;33:" + QUILT_COLORS="${QUILT_COLORS}diff_ctx=35:diff_cctx=33" + if ! [ -d $d/debian/patches ]; then mkdir $d/debian/patches; fi +fi diff --git a/docker/debian-dev/bootstrap/setup-base.bash b/docker/debian-dev/bootstrap/setup-base.bash new file mode 100644 index 0000000..31ded36 --- /dev/null +++ b/docker/debian-dev/bootstrap/setup-base.bash @@ -0,0 +1,25 @@ +#! /usr/bin/env bash + +set -e + +. /bootstrap/func.bash + +echo "Setting up basic system function..." + +echo "Installing basic packages..." +apt-get install -y apt-utils +apt-get install -y locales procps vim less man bash-completion software-properties-common rsync curl wget +echo "Installing basic packages done." + +echo "Setting up locale..." +localedef -i en_US -c -f UTF-8 -A /usr/share/locale/locale.alias en_US.UTF-8 +echo "Setting up locale done." + +echo "Creating data dir..." +mkdir -p /data +chown $CRUPEST_DEBIAN_DEV_USER:$CRUPEST_DEBIAN_DEV_USER /data +echo "Creating data dir done." + +append-bashrc bash-completion.bash + +echo "Setting up basic system function done." diff --git a/docker/debian-dev/bootstrap/setup-code-server.bash b/docker/debian-dev/bootstrap/setup-code-server.bash new file mode 100644 index 0000000..34c9697 --- /dev/null +++ b/docker/debian-dev/bootstrap/setup-code-server.bash @@ -0,0 +1,28 @@ +#! /usr/bin/env bash + +set -e + +. /bootstrap/func.bash + +echo "Setting up code server..." + +echo "Get latest version of code-server..." +VERSION=$(curl -s https://api.github.com/repos/coder/code-server/releases/latest | grep '"tag_name":' | sed -E 's/.*"v([^"]+)".*/\1/') +echo "Current latest version of code-server is $VERSION" + +echo "Downloading code-server..." +url="https://github.com/coder/code-server/releases/download/v${VERSION}/code-server_${VERSION}_amd64.deb" +curl -sSfOL "$url" +echo "Downloading code-server done." + +echo "Installing code-server..." +apt-get install -y "./code-server_${VERSION}_amd64.deb" +echo "Installing code-server done." + +echo "Cleaning up deb..." +rm "code-server_${VERSION}_amd64.deb" +echo "Cleaning up deb done." + +append-bash-profile code-server.bash + +echo "Setting up code server done." diff --git a/docker/debian-dev/bootstrap/setup-dev.bash b/docker/debian-dev/bootstrap/setup-dev.bash new file mode 100644 index 0000000..92deacb --- /dev/null +++ b/docker/debian-dev/bootstrap/setup-dev.bash @@ -0,0 +1,18 @@ +#! /usr/bin/env bash + +set -e + +. /bootstrap/func.bash + +echo "Setting up dev function..." + +echo "Installing dev packages..." +apt-get install -y build-essential git devscripts debhelper quilt +apt-get build-dep -y linux +echo "Installing dev packages done." + +append-bashrc dquilt.bash +copy-home-dot-file devscripts +copy-home-dot-file quiltrc-dpkg + +echo "Setting up dev function done." diff --git a/docker/debian-dev/bootstrap/setup-user.bash b/docker/debian-dev/bootstrap/setup-user.bash new file mode 100644 index 0000000..f74dcdb --- /dev/null +++ b/docker/debian-dev/bootstrap/setup-user.bash @@ -0,0 +1,20 @@ +#! /usr/bin/env bash + +set -e + +echo "Setting up user..." + +echo "Installing sudo..." +apt-get install -y sudo +echo "Installing sudo done." + +echo "Setting up sudo..." +sed -i.bak 's|%sudo[[:space:]]\+ALL=(ALL:ALL)[[:space:]]\+ALL|%sudo ALL=(ALL:ALL) NOPASSWD: ALL|' /etc/sudoers +echo "Setting up sudo done." + +echo "Adding user $CRUPEST_DEBIAN_DEV_USER ..." +useradd -m -G sudo -s /usr/bin/bash "$CRUPEST_DEBIAN_DEV_USER" +echo "Adding user done." + +echo "Setting up user done." + diff --git a/docker/debian-dev/bootstrap/setup.bash b/docker/debian-dev/bootstrap/setup.bash new file mode 100644 index 0000000..09b8137 --- /dev/null +++ b/docker/debian-dev/bootstrap/setup.bash @@ -0,0 +1,30 @@ +#! /usr/bin/env bash + +set -e + +export DEBIAN_FRONTEND=noninteractive + +echo "Setting up crupest-debian-dev..." + +. /bootstrap/func.bash + +/bootstrap/apt-source/setup.bash + +echo "Updating apt source index..." +apt-get update +echo "Updating apt source index done." + +/bootstrap/setup-user.bash +/bootstrap/setup-base.bash +/bootstrap/setup-dev.bash + +if is_true "$CRUPEST_DEBIAN_DEV_SETUP_CODE_SERVER"; then + echo "CRUPEST_DEBIAN_DEV_SETUP_CODE_SERVER is true, setting up code-server..." + /bootstrap/setup-code-server.bash +fi + +echo "Cleaning up apt source index..." +rm -rf /var/lib/apt/lists/* +echo "Cleaning up apt source index done." + +echo "Setting up crupest-debian-dev done." diff --git a/docker/debian-dev/bootstrap/start/code-server.bash b/docker/debian-dev/bootstrap/start/code-server.bash new file mode 100644 index 0000000..7dfc0e9 --- /dev/null +++ b/docker/debian-dev/bootstrap/start/code-server.bash @@ -0,0 +1,18 @@ +#! /usr/bin/env bash + +export CODE_SERVER_CONFIG="/data/code-server-config.yaml" + +CODE_SERVER_PROGRAM=code-server +CODE_SERVER_PORT=8080 + +if which "$CODE_SERVER_PROGRAM" > /dev/null 2>&1; then + if ! pgrep -x "$CODE_SERVER_PROGRAM" > /dev/null 2>&1; then + echo "code-server is not running, starting..." + "$CODE_SERVER_PROGRAM" "--bind-addr" "0.0.0.0:$CODE_SERVER_PORT" + else + echo "code-server is already running." + fi +else + echo "code-server not found, skipping code-server setup." >&2 + exit 1 +fi diff --git a/docker/debian-dev/bootstrap/wait.bash b/docker/debian-dev/bootstrap/wait.bash new file mode 100644 index 0000000..501c706 --- /dev/null +++ b/docker/debian-dev/bootstrap/wait.bash @@ -0,0 +1,5 @@ +#! /usr/bin/env bash + +set -e + +tail -f /dev/null |