From c6497419058e914ed3082b812fa201f4f157684d Mon Sep 17 00:00:00 2001 From: Stefan Tatschner Date: Tue, 29 Oct 2024 13:23:31 +0100 Subject: [PATCH] Add code --- arch/Containerfile | 28 ++++++++ arch/justfile | 2 + debian/Containerfile | 75 ++++++++++++++++++++ debian/debian-de.sources | 12 ++++ debian/justfile | 2 + devpod | 144 +++++++++++++++++++++++++++++++++++++++ justfile | 5 ++ 7 files changed, 268 insertions(+) create mode 100644 arch/Containerfile create mode 100644 arch/justfile create mode 100644 debian/Containerfile create mode 100644 debian/debian-de.sources create mode 100644 debian/justfile create mode 100755 devpod create mode 100644 justfile diff --git a/arch/Containerfile b/arch/Containerfile new file mode 100644 index 0000000..27209bb --- /dev/null +++ b/arch/Containerfile @@ -0,0 +1,28 @@ +FROM docker.io/archlinux + +RUN pacman -Syu --noconfirm +RUN pacman -S --noconfirm \ + git \ + neovim \ + htop \ + fish \ + tmux \ + sudo \ + base-devel \ + cargo \ + ripgrep \ + devtools \ + fd \ + bat \ + go \ + clang \ + aurpublish \ + git-delta + +ENV TERM=xterm-256color +RUN useradd -m -G wheel dev +RUN echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +USER dev +RUN cd /tmp && git clone https://aur.archlinux.org/paru.git && cd paru && makepkg -si --noconfirm + diff --git a/arch/justfile b/arch/justfile new file mode 100644 index 0000000..18a7c9c --- /dev/null +++ b/arch/justfile @@ -0,0 +1,2 @@ +build: + podman build . -t devpod-arch diff --git a/debian/Containerfile b/debian/Containerfile new file mode 100644 index 0000000..85f1db9 --- /dev/null +++ b/debian/Containerfile @@ -0,0 +1,75 @@ +FROM docker.io/debian:trixie + +COPY debian-de.sources /etc/apt/sources.list.de/ + +RUN apt-get update + +# Installing latex takes so long, cache it. +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y texlive-full latexmk xindy +RUN DEBIAN_FRONTEND=noninteractive apt-get install -y \ + atuin \ + apt-utils \ + bat \ + build-essential \ + clang \ + cmake \ + curl \ + desktop-file-utils \ + dialog \ + evince \ + fd-find \ + fish \ + gh \ + git \ + git-delta \ + golang-go \ + htop \ + just \ + kitty \ + locales \ + locales-all \ + meson \ + neovim \ + netcat-openbsd \ + npm \ + pipx \ + python3-poetry \ + ripgrep \ + rustup \ + shellcheck \ + shfmt \ + socat \ + strace \ + sudo \ + tmux \ + valgrind \ + gettext \ + wireshark + +ENV LC_ALL en_US.UTF-8 +ENV LANG en_US.UTF-8 +ENV LANGUAGE en_US.UTF-8 + +RUN ln -s -f /usr/share/zoneinfo/Europe/Berlin /etc/localtime + +RUN groupadd wheel +RUN useradd -m -G wheel dev +RUN echo '%wheel ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers +RUN DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y + +RUN git clone https://github.com/neovim/neovim +RUN git -C neovim checkout stable +RUN cd neovim && make CMAKE_BUILD_TYPE=RelWithDebInfo +RUN cd neovim && sudo make install +RUN rm -rf neovim + +USER dev + +ENV TERM=xterm-256color +ENV PATH=/home/dev/.local/bin:/home/dev/.local/npm-packages/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin + +RUN pipx install ruff uv +RUN npm install --prefix /home/dev/.local/npm-packages -g bash-language-server +RUN rustup toolchain install stable + +WORKDIR $HOME diff --git a/debian/debian-de.sources b/debian/debian-de.sources new file mode 100644 index 0000000..427f706 --- /dev/null +++ b/debian/debian-de.sources @@ -0,0 +1,12 @@ +Types: deb +URIs: http://ftp.de.debian.org/debian +Suites: trixie trixie-updates +Components: main +Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg + +Types: deb +URIs: http://ftp.de.debian.org/debian-security +Suites: trixie-security +Components: main +Signed-By: /usr/share/keyrings/debian-archive-keyring.gpg + diff --git a/debian/justfile b/debian/justfile new file mode 100644 index 0000000..41bdc74 --- /dev/null +++ b/debian/justfile @@ -0,0 +1,2 @@ +build: + podman build . -t devpod-debian diff --git a/devpod b/devpod new file mode 100755 index 0000000..a227369 --- /dev/null +++ b/devpod @@ -0,0 +1,144 @@ +#!/usr/bin/env bash + +set -eu + +search_configs() { + local global_conf="/etc/devpod/config.sh" + if [[ -f "$global_conf" ]]; then + export DEVPOD_GLOBAL_CONF="$global_conf" + fi + + local user_conf="$HOME/.config/devpod/config.sh" + if [[ -f "$user_conf" ]]; then + export DEVPOD_USER_CONF="$user_conf" + fi + + local git_root + if git_root="$(git rev-parse --show-toplevel 2>/dev/null)"; then + local git_root_conf="$git_root/.devpod.sh" + if [[ -f "$git_root_conf" ]]; then + export DEVPOD_GIT_ROOT_CONF="$git_root_conf" + fi + fi + + local pwd_conf="$PWD/.devpod.sh" + if [[ -f "$pwd_conf" ]]; then + export DEVPOD_PWD_CONF="$pwd_conf" + fi +} + +search_and_source_config() { + search_configs + + if [[ -n "${DEVPOD_PWD_CONF-}" ]]; then + # shellcheck source=/dev/null + source "$DEVPOD_PWD_CONF" + return 0 + fi + if [[ -n "${DEVPOD_GIT_ROOT_CONF-}" ]]; then + # shellcheck source=/dev/null + source "$DEVPOD_GIT_ROOT_CONF" + return 0 + fi + if [[ -n "${DEVPOD_USER_CONF-}" ]]; then + # shellcheck source=/dev/null + source "$DEVPOD_USER_CONF" + return 0 + fi + if [[ -n "${DEVPOD_GLOBAL_CONF-}" ]]; then + # shellcheck source=/dev/null + source "$DEVPOD_GLOBAL_CONF" + return 0 + fi +} + +show_help() { + echo "usage: $(basename "$BASH_ARGV0") [-c CONTAINER] CMD" + echo "" + echo " -g mount stuff to allow wayland GUI applications" + echo " -s mount stuff to allow ssh config and agent from host" + echo " -c CONTAINER container to use, default is debian" +} + +main() { + configured_args=() + CONTAINER_HOME="/home/dev" + + search_and_source_config + + local container="devpod-debian" + local allow_gui="0" + local allow_ssh="0" + + while getopts "h?gsc:" opt; do + case "$opt" in + c) + container="devpod-$1" + ;; + g) + allow_gui="1" + ;; + s) + allow_ssh="1" + ;; + h | \?) + show_help + exit 0 + ;; + *) + show_help + exit 1 + ;; + esac + done + + shift $((OPTIND - 1)) + + if [[ "$#" == 0 ]]; then + show_help + exit 1 + else + local cmd + cmd=("/bin/sh" "-c" "$*") + fi + + local args + args=( + --rm + -it + --workdir "$CONTAINER_HOME/PWD/$(basename "$PWD")" + --volume "$PWD:$CONTAINER_HOME/PWD/$(basename "$PWD")" + --volume "$XDG_RUNTIME_DIR:$XDG_RUNTIME_DIR" + --log-driver none + --hostname "$container" + --group-add keep-groups + --userns keep-id + ) + + if ((allow_ssh)); then + args+=( + --env "SSH_AUTH_SOCK=$SSH_AUTH_SOCK" + --volume "$SSH_AUTH_SOCK:$SSH_AUTH_SOCK" + --volume "$HOME/.ssh:$CONTAINER_HOME/.ssh:O" + ) + fi + + if ((allow_gui)); then + args+=( + # --env "XDG_DATA_DIRS=$XDG_DATA_DIRS" # TODO: not mounted + --env "XDG_SESSION_CLASS=$XDG_SESSION_CLASS" + --env "XDG_RUNTIME_DIR=$XDG_RUNTIME_DIR" + --env "XDG_SESSION_DESKTOP=$XDG_SESSION_DESKTOP" + --env "XDG_CURRENT_DESKTOP=$XDG_CURRENT_DESKTOP" + --env "XDG_MENU_PREFIX=$XDG_MENU_PREFIX" + --env "XDG_SESSION_TYPE=$XDG_SESSION_TYPE" + --env "WAYLAND_DISPLAY=$WAYLAND_DISPLAY" + --env "DBUS_SESSION_BUS_ADDRESS=$DBUS_SESSION_BUS_ADDRESS" + --device "/dev/dri" + ) + fi + + podman run "${args[@]}" "${configured_args[@]}" "$container" "${cmd[@]}" +} + +main "$@" diff --git a/justfile b/justfile new file mode 100644 index 0000000..0c9d3ed --- /dev/null +++ b/justfile @@ -0,0 +1,5 @@ +build-arch: + cd arch && just build + +build-debian: + cd debian && just build