aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--Containerfile68
-rw-r--r--Makefile9
-rw-r--r--custom/README.md11
-rwxr-xr-xdbx-init2
-rw-r--r--ssh/config.in5
6 files changed, 97 insertions, 2 deletions
diff --git a/.gitignore b/.gitignore
index b0bfd82..869cb3b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
+.container
+custom/*
+!custom/README.md
ssh/id_*
+ssh/config
diff --git a/Containerfile b/Containerfile
new file mode 100644
index 0000000..b808aab
--- /dev/null
+++ b/Containerfile
@@ -0,0 +1,68 @@
+FROM docker.io/library/debian:13
+
+ARG USER=dbx
+EXPOSE 22/tcp
+
+# Flag that we are a devbox
+RUN touch /run/.dbxenv
+
+# Remove container-specific APT configurations, and install required packages
+RUN rm /etc/apt/apt.conf.d/docker-* && \
+ apt-get update && \
+ apt-get install -y \
+ bash-completion \
+ bzip2 \
+ curl \
+ git \
+ gnupg \
+ htop \
+ less \
+ man-db \
+ manpages \
+ nano \
+ openssh-client \
+ openssh-server \
+ procps \
+ sudo \
+ tini \
+ tree \
+ vim \
+ wget \
+ zip \
+ && \
+ rm -dr /var/lib/apt/lists/*
+
+# Passwordless sudo
+RUN sed -i -e 's/ ALL$/ NOPASSWD:ALL/' /etc/sudoers
+
+# Configure automatic removal of stale forwarded sockets
+RUN echo "StreamLocalBindUnlink yes" >> /etc/ssh/sshd_config
+
+# Create and configure the devbox user
+RUN useradd \
+ --create-home \
+ --groups sudo \
+ --shell /usr/bin/bash \
+ --uid 1000 \
+ --user-group \
+ ${USER}
+
+# Configure SSH login
+RUN mkdir -m 700 /home/${USER}/.ssh && chown 1000:1000 /home/${USER}/.ssh
+COPY --chmod=600 --chown=1000:1000 ssh/id_ed25519.pub /home/${USER}/.ssh/authorized_keys
+
+# User customizations
+COPY --chown=1000:1000 custom/ /home/${USER}/
+RUN rm /home/${USER}/README.md
+RUN if [ -f /home/${USER}/extra-packages ]; then \
+ apt-get install -y $(cat /home/${USER}/extra-packages | xargs) && \
+ rm -dr /var/lib/apt/lists/* /home/${USER}/extra-packages; \
+ fi
+RUN if [ -x /home/${USER}/post-install ]; then \
+ su - ${USER} /home/${USER}/post-install && \
+ rm /home/${USER}/post-install; \
+ fi
+
+# Set up the entrypoint
+COPY dbx-init /usr/local/bin/dbx-init
+ENTRYPOINT ["dbx-init"]
diff --git a/Makefile b/Makefile
index 86aa085..cacc8f8 100644
--- a/Makefile
+++ b/Makefile
@@ -1,5 +1,5 @@
.PHONY: all
-all: ;
+all: ssh/cofig .container;
@ echo "install with 'make install'"
.PHONY: install
@@ -7,5 +7,12 @@ install: all
mkdir -p $(HOME)/.local/bin
ln -s $(PWD)/dbx $(HOME)/.local/bin/dbx
+ssh/config: ssh/config.in ssh/id_ed25519.pub
+ cat $< \
+ | sed -e 's|$$PWD|$(PWD)|' \
+ > $@
+
+.container: ssh/id_ed25519.pub
+
ssh/id_% ssh/id_%.pub:
ssh-keygen -C "$$(id -un)@$$(hostname)" -f ssh/id_$* -N "" -t $*
diff --git a/custom/README.md b/custom/README.md
new file mode 100644
index 0000000..04d6b03
--- /dev/null
+++ b/custom/README.md
@@ -0,0 +1,11 @@
+# Customizations
+
+This directory includes customizations that are not tracked by Git. All files in this directory will be copied over the devbox user's home directory (overwriting any files that may exist there from `/etc/skel`), allowing for easy customization of the devbox user.
+
+## Extra Packages
+
+A special `extra-packages` file can be added to this directory to include additional packages to install when building the container.
+
+## Post Installation Script
+
+A special `post-install` executable can be added to this directory which will be run as a final step when building the container. This allows you to include a one-time setup with the development container image. The post install script is run as the devbox user (with `sudo` access).
diff --git a/dbx-init b/dbx-init
index f0ac1c1..5f7949d 100755
--- a/dbx-init
+++ b/dbx-init
@@ -7,4 +7,4 @@ if [[ ! -f /run/.dbxenv ]]; then
echo "ERROR: not in a devbox" >&2
fi
-exec tini sshd -- -D -e
+exec tini /usr/sbin/sshd -- -D -e
diff --git a/ssh/config.in b/ssh/config.in
new file mode 100644
index 0000000..daf23b8
--- /dev/null
+++ b/ssh/config.in
@@ -0,0 +1,5 @@
+Host dbx
+ HostName 127.0.0.1
+ Port 4222
+ IdentitiesOnly yes
+ IdentityFile $PWD/ssh/id_ed25519