Skip to content

Commit

Permalink
Add code
Browse files Browse the repository at this point in the history
  • Loading branch information
rumpelsepp committed Oct 29, 2024
1 parent baa8c90 commit c649741
Show file tree
Hide file tree
Showing 7 changed files with 268 additions and 0 deletions.
28 changes: 28 additions & 0 deletions arch/Containerfile
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions arch/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
podman build . -t devpod-arch
75 changes: 75 additions & 0 deletions debian/Containerfile
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions debian/debian-de.sources
Original file line number Diff line number Diff line change
@@ -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

2 changes: 2 additions & 0 deletions debian/justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
podman build . -t devpod-debian
144 changes: 144 additions & 0 deletions devpod
Original file line number Diff line number Diff line change
@@ -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 "$@"
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
build-arch:
cd arch && just build

build-debian:
cd debian && just build

0 comments on commit c649741

Please sign in to comment.