This commit is contained in:
2025-05-16 22:11:10 +03:00
commit 02991449f1
7 changed files with 157 additions and 0 deletions

37
Dockerfile Normal file
View File

@@ -0,0 +1,37 @@
FROM ubuntu:24.04 AS ubuntu
# setting non-interactive mode for apt
ENV DEBIAN_FRONTEND=noninteractive
# update system and install the required stuff
RUN apt-get update && apt-get upgrade -y
RUN apt-get install -y --no-install-recommends \
gosu
# install packages appearing in packages.list
# clean up chache and remove package lists
COPY ./packages.list /tmp
RUN xargs apt-get install -y --no-install-recommends </tmp/packages.list && \
apt-get clean && \
rm /tmp/packages.list
# install what can not be installed with
# package manager
COPY ./build_time_scripts.sh /tmp
COPY ./custom /tmp/custom
RUN /tmp/build_time_scripts.sh /tmp/custom && \
rm -rf /tmp/build_time_scripts.sh /tmp/custom
# set working dir inside the container
WORKDIR /home/ubuntu
# password to log in as ubuntu user
ENV SECRET="ubuntu"
# copy enrypoint script
COPY ./entrypoint.sh /usr/bin/entrypoint-docker.sh
ENTRYPOINT ["/bin/sh", "/usr/bin/entrypoint-docker.sh"]
CMD ["/usr/bin/bash"]

13
Makefile Normal file
View File

@@ -0,0 +1,13 @@
#image basename
BASENAME=devenv
# TODO use git tag
IMAGE_NAME=$(BASENAME):latest
build:
$(info BUILDING IMAGE NAME: $(IMAGE_NAME))
docker build \
-t $(IMAGE_NAME) \
-f Dockerfile .
docker image ls $(IMAGE_NAME)

58
README.md Normal file
View File

@@ -0,0 +1,58 @@
# devenv
**devenv** is a tool to quickly build a Docker image based on Ubuntu 22.04 with
easily customisable set of packages. The image is built with an entrypoint script
which lets you set up an unprivileged user in container OS.
The whole story is intended for developers needing to experiment with different
versions of build tools etc.
## Customise
1. Customize packages that you want to install into the
container OS. Just edit the **packages.list** putting
one package name per line.
2. Add shell scripts or binaries to **./custom** directory. These
will run at build time as **root** and the produced result will be
baked into the image.
3. **(optional)** edit Makefile, Dockerfile, entrypoint.sh accoriding
to your requirements.
## Build the image
This builds Docker image with Ubuntu 22.04 as base
installing the tools you chose above. Note that build
executes all scripts in **./scripts** directory if any are present.
```bash
make build
```
## Entrypoint
Entrypoint script creates an unprivileged user in container system.
Username, gid and uig can be altered when launching the container by passing environment
variables to docker run.
If no environment variables were passed to docker run, the unprivileged user will
default to **developer:developer** with uig/gid **1001:1001**.
By default the unprivileged user created by entrpoint script has passwordless sudo.
If this is not the desired behaviour - consider editing **entrypoint.sh** before
building the image.
## Create launch script
This will create a bash script that runs the Docker container from the image
built above with your current username, uid and gid. Since username, uid and
gid are the same as in your host system you can safely mount anything from
your host system into container without creating mess in host OS.
By default the launch script mounts your home directory into the unprivileged
user's home in the container. Edit the produced script as approprite if this
is not the desired behaviour.
```bash
make script
```
## Create and install launch script
This will create the launch script (see above) and place it into you
**$HOME/.local/bin** creating the directory is if does not exist.
```bash
make install
```

13
build_time_scripts.sh Executable file
View File

@@ -0,0 +1,13 @@
# exit on errors
set -e
# now let's fire up all the scripts from the
# directory which we received as a second argument
if [ "$(ls $1)" ]; then
for script in $1/*
do
echo "executing $script"
$script
done
else
echo "custom scripts directory is empty"
fi

10
custom/010_vanilla_go.sh Executable file
View File

@@ -0,0 +1,10 @@
# install vanilla Go 1.24.3
set -e
echo "fetching go compiler"
curl --location https://go.dev/dl/go1.24.3.linux-amd64.tar.gz -o /tmp/go.tar.gz
echo "unpacking go compiler..."
tar -xzf /tmp/go.tar.gz -C /usr/local
echo "removing archive"
rm /tmp/go.tar.gz
ln -s /usr/local/go/bin/* /usr/bin
echo "Go 1.24.3 installed into /usr/local"

12
entrypoint.sh Normal file
View File

@@ -0,0 +1,12 @@
set -e
# set password
echo "ubuntu:${SECRET}" | chpasswd
mkdir /run/sshd
/sbin/sshd -o "PasswordAuthentication=yes"
# add ubuntu to groups
usermod -aG sudo ubuntu
exec gosu ubuntu:ubuntu $@

14
packages.list Normal file
View File

@@ -0,0 +1,14 @@
sudo
openssh-server
openssh-client
curl
wget
ca-certificates
tzdata
git
make
build-essential
tree
htop
iproute2
openssh-client