Compare commits

..

3 Commits

Author SHA1 Message Date
a67ea6c795
feat: disable autocomplete with the enter key
Some checks failed
Container build / container-build (push) Has been cancelled
2024-09-29 16:49:15 +02:00
63ac1aae83
feat: handle automatically updates with enter.sh 2024-09-29 16:48:50 +02:00
df8b7b5bfe
feat: add bash_profile for creating copilot directory 2024-09-29 16:48:19 +02:00
5 changed files with 113 additions and 19 deletions

View File

@ -10,6 +10,7 @@ RUN useradd -ms /bin/bash user && usermod -aG wheel user && sed -i '/NOPASSWD/s/
USER user USER user
WORKDIR /home/user WORKDIR /home/user
COPY config/user/bashrc /home/user/.bashrc COPY config/user/bashrc /home/user/.bashrc
COPY config/user/profile /home/user/.bash_profile
# === setup neovim === # === setup neovim ===
RUN git clone --depth 1 https://github.com/LazyVim/starter ~/.config/nvim RUN git clone --depth 1 https://github.com/LazyVim/starter ~/.config/nvim
@ -19,5 +20,5 @@ COPY config/nvim/lazyvim.json /home/user/.config/nvim/lazyvim.json
# === setup container === # === setup container ===
ENV TZ="Europe/Amsterdam" ENV TZ="Europe/Amsterdam"
VOLUME /home/user/.local /home/user/.cache /home/user/.config/github-copilot VOLUME /home/user/.local /home/user/.cache
CMD ["bash"] CMD ["bash", "-l"]

View File

@ -1,2 +1,2 @@
#!/bin/sh #!/bin/sh
podman build . -t dev podman build . $@ -t git.plabble.org/job79/dev

View File

@ -0,0 +1,9 @@
return {
"hrsh7th/nvim-cmp",
opts = function(_, opts)
local cmp = require("cmp")
opts.mapping = vim.tbl_deep_extend("force", opts.mapping, {
["<CR>"] = cmp.config.disable,
})
end,
}

7
config/user/profile Normal file
View File

@ -0,0 +1,7 @@
. ~/.bashrc
# === persist copilot auth files inside .local volume ===
if [ ! -d ~/.config/github-copilot ]; then
mkdir -p ~/.local/share/github-copilot
ln -s ~/.local/share/github-copilot ~/.config
fi

109
enter.sh
View File

@ -1,17 +1,94 @@
#!/bin/sh #!/bin/sh
name="${1:-dev}" # =============================================== #
podman container rm -f -t 1 "$name" # enter.sh v1.0; job79 #
podman pull git.plabble.org/job79/dev:latest # Enter into an existing or new dev container and #
podman run -it \ # automatically handle dev container updates. #
--name "$name" \ # =============================================== #
-v /run/user/1000/wayland-0:/run/user/1000/wayland-0 \ set -e
-v "$SSH_AUTH_SOCK":/run/user/1000/ssh-auth-sock \
-v ~/Documents:/home/user/Documents \ # podman_run opens a shell into a newly created dev container.
-v ~/.ssh:/home/user/.ssh \ podman_run() {
-v ~/.config/git:/home/user/.config/git \ args="--name $name"
-v "$name"-copilot:/home/user/.config/github-copilot \ arg() { args="$args $@"; }
-v "$name"-local:/home/user/.local \
-v "$name"-cache:/home/user/.cache \ # Automatically update the container when a newer
--security-opt label=disable \ # image is available.
--userns=keep-id \ [ "$no_pull" = 1 ] || arg "--pull newer"
git.plabble.org/job79/dev:latest
# Disable some security settings to make it possible to mount
# host directories without problems.
arg "--security-opt label=disable" # disable labeling so mounts don't need to be labbeled.
arg "--userns=keep-id" # required for ~/.ssh which is usually 700.
# Mount the wayland socket. Required to get the system
# clipbard (wl-copy) working.
arg "-v /run/user/$UID/wayland-0:/run/user/1000/wayland-0"
# Mount the ssh socket, directory and git directory. This
# gets the host ssh and git configuration working inside
# the container.
arg "-v $SSH_AUTH_SOCK:/run/user/1000/ssh-auth-sock"
[ -d ~/.ssh ] && arg "-v $HOME/.ssh:/home/user/.ssh"
[ -d ~/.config/git ] && arg "-v $HOME/.config/git:/home/user/.config/git"
# Mount host directories with programming projects.
[ -d ~/Documents ] && arg "-v $HOME/Documents:/home/user/Documents"
[ -d ~/.dev ] && arg "-v $HOME/.dev:/home/user/.dev"
# Add volumes for .local and .cache so these survive
# container restarts.
arg "-v $name-local:/home/user/.local"
arg "-v $name-cache:/home/user/.cache"
podman run -it $args "$image"
}
# podman_exec opens a shell into an existing dev container.
podman_exec() { podman exec -it "$name" bash -l; }
# podman_start starts a stopped existing dev container.
podman_start() { podman start "$name" 1>/dev/null; }
# podman_delete deletes a dev container.
podman_delete() { podman container rm -f -t 1 "$name" 1>/dev/null; }
### MAIN ###
name="dev"
image="git.plabble.org/job79/dev:latest"
while test $# -gt 0; do
case "$1" in
--recreate | -r) podman_delete ;;
--no-pull | -np) no_pull=1 ;;
-*) echo "unknown option '$1'" ;;
*) name="$1" ;;
esac
shift
done
if ! podman container exists "$name"; then
podman_run
exit
fi
if [ "$(podman container inspect "$name" -f {{.State.Running}} 2>&1)" = 'true' ]; then
podman_exec
exit
fi
if [ "$no_pull" = 1 ]; then
podman_start
podman_exec
exit
fi
iid="$(podman image inspect "$image" -f {{.Id}})"
podman pull -q "$image" 1>/dev/null
if [ "$(podman image inspect "$image" -f {{.Id}})" != "$iid" ]; then
# When container is stopped and a newer image is available,
# recreate the container instead of starting the existing one.
podman_delete
podman_run
else
podman_start
podman_exec
fi