Skip to content

Commit a1c21db

Browse files
committed
Add docker
1 parent e3cbab9 commit a1c21db

4 files changed

Lines changed: 106 additions & 3 deletions

File tree

Dockerfile

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ ARG \
8383
BIND9_VERSION=1:9.20.23-1~deb13u1 \
8484
# renovate: datasource=repology depName=debian_13/bubblewrap
8585
BW_VERSION=0.11.0-2+deb13u1 \
86+
# renovate: datasource=deb depName=docker-ce
87+
DOCKER_CE_VERSION=5:29.5.3-1~debian.13~trixie \
88+
# renovate: datasource=deb depName=containerd.io
89+
CONTAINERD_IO_VERSION=2.2.4-1~debian.13~trixie \
90+
# renovate: datasource=deb depName=docker-buildx-plugin
91+
DOCKER_BUILDX_PLUGIN_VERSION=0.34.1-1~debian.13~trixie \
92+
# renovate: datasource=deb depName=docker-compose-plugin
93+
DOCKER_COMPOSE_PLUGIN_VERSION=5.1.4-1~debian.13~trixie \
8694
# renovate: datasource=repology depName=debian_13/fzf
8795
FZF_VERSION=0.60.3-1+b2 \
8896
# renovate: datasource=repology depName=debian_13/gh
@@ -140,6 +148,17 @@ SHELL ["/bin/bash", "-o", "pipefail", "-ex", "-c"]
140148
RUN --mount=type=cache,id=apt-cache-${TARGETARCH},sharing=locked,target=/var/cache/apt \
141149
BC_VERSION_HACK="${BC_VERSION}$([ "${TARGETARCH}" = "arm64" ] && echo "+b1" || echo "")" && \
142150
rm -f /etc/apt/apt.conf.d/docker-clean && \
151+
install -m 0755 -d /etc/apt/keyrings && \
152+
wget -q -O /etc/apt/keyrings/docker.asc https://download.docker.com/linux/debian/gpg && \
153+
chmod a+r /etc/apt/keyrings/docker.asc && \
154+
printf '%s\n' \
155+
'Types: deb' \
156+
'URIs: https://download.docker.com/linux/debian' \
157+
'Suites: trixie' \
158+
'Components: stable' \
159+
"Architectures: $(dpkg --print-architecture)" \
160+
'Signed-By: /etc/apt/keyrings/docker.asc' \
161+
> /etc/apt/sources.list.d/docker.sources && \
143162
wget -q -O - https://apt.releases.hashicorp.com/gpg | gpg --dearmor -o /usr/share/keyrings/hashicorp-archive-keyring.gpg && \
144163
echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/hashicorp-archive-keyring.gpg] https://apt.releases.hashicorp.com trixie main" | tee /etc/apt/sources.list.d/hashicorp.list && \
145164
apt-get update && \
@@ -149,6 +168,11 @@ RUN --mount=type=cache,id=apt-cache-${TARGETARCH},sharing=locked,target=/var/cac
149168
bind9-dnsutils="${BIND9_VERSION}" \
150169
bubblewrap="${BW_VERSION}" \
151170
composer="${COMPOSER_VERSION}" \
171+
containerd.io="${CONTAINERD_IO_VERSION}" \
172+
docker-buildx-plugin="${DOCKER_BUILDX_PLUGIN_VERSION}" \
173+
docker-ce="${DOCKER_CE_VERSION}" \
174+
docker-ce-cli="${DOCKER_CE_VERSION}" \
175+
docker-compose-plugin="${DOCKER_COMPOSE_PLUGIN_VERSION}" \
152176
fzf="${FZF_VERSION}" \
153177
gh="${GH_VERSION}" \
154178
git="${GIT_VERSION}" \
@@ -180,6 +204,12 @@ RUN --mount=type=cache,id=apt-cache-${TARGETARCH},sharing=locked,target=/var/cac
180204
unzip="${UNZIP_VERSION}" \
181205
vim="${VIM_VERSION}" \
182206
terraform="${TERRAFORM_VERSION}" && \
207+
apt-mark hold \
208+
containerd.io \
209+
docker-buildx-plugin \
210+
docker-ce \
211+
docker-ce-cli \
212+
docker-compose-plugin && \
183213
rm -rf /var/lib/apt/lists/*
184214

185215
COPY download.sh /usr/local/bin
@@ -209,10 +239,19 @@ COPY --from=go-tools-builder /root/go/bin/buf /usr/local/bin/
209239
SHELL ["/bin/bash", "-o", "pipefail", "-c"]
210240

211241
COPY --chown=node init-firewall.sh /usr/local/bin/
212-
RUN chmod +x /usr/local/bin/init-firewall.sh && \
213-
echo "node ALL=(root) NOPASSWD: /usr/local/bin/init-firewall.sh" > /etc/sudoers.d/node-firewall && \
242+
COPY --chown=node fix-docker-socket.sh /usr/local/bin/
243+
RUN chmod +x /usr/local/bin/init-firewall.sh /usr/local/bin/fix-docker-socket.sh && \
244+
printf '%s\n' \
245+
'node ALL=(root) NOPASSWD: /usr/local/bin/init-firewall.sh' \
246+
'node ALL=(root) NOPASSWD: /usr/local/bin/fix-docker-socket.sh' \
247+
> /etc/sudoers.d/node-firewall && \
214248
chmod 0440 /etc/sudoers.d/node-firewall
215249

250+
# Add node to the docker group (the docker-ce postinst created it).
251+
# usermod/gpasswd aren't installed, so edit /etc/group directly:
252+
# add a comma separator only if the member list is non-empty, then append node.
253+
RUN sed -i -E '/^docker:/{ /:$/! s/$/,/; s/$/node/ }' /etc/group
254+
216255
USER node
217256

218257
ENV \

docker-entrypoint.sh

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,32 @@ if [ "${SKIP_EGRESS_FIREWALL:-false}" != "true" ]; then
1111
)
1212
fi
1313

14+
# If a Docker socket is mounted in, make node a member of the group that owns
15+
# it. The socket is read-only so we cannot chmod it; the sudo'd helper only
16+
# edits /etc/group (the one bit that needs root) and prints the group name.
17+
# We must NOT run the workload itself through sudo: env_reset would clobber
18+
# HOME, CODEX_HOME, PATH, etc. and the command would run with root's HOME.
19+
docker_grp=""
20+
if [ -S /var/run/docker.sock ]; then
21+
docker_grp="$(sudo /usr/local/bin/fix-docker-socket.sh || true)"
22+
fi
23+
1424
# sometimes i forget where i started after all the firewall rule stdout
1525
ls -la
1626

1727
if [ -d "$HOME/.local/bin" ]; then
1828
export PATH="$HOME/.local/bin:$PATH"
1929
fi
2030

31+
# Build the command we actually want to run.
2132
if [ "$#" -eq 0 ]; then
22-
exec /bin/bash -l
33+
set -- /bin/bash -l
34+
fi
35+
36+
if [ -n "$docker_grp" ]; then
37+
# Re-exec with the socket's group added. Unlike sudo, sg preserves the
38+
# environment and needs no password now that node is a member of the group.
39+
exec sg "$docker_grp" -c "exec $(printf '%q ' "$@")"
2340
else
2441
exec "$@"
2542
fi

fix-docker-socket.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Ensure the node user is a member of the group that owns the Docker socket,
4+
# and print that group's name on stdout.
5+
#
6+
# Why this shape:
7+
# * The socket is usually bind-mounted read-only, so we CANNOT chgrp/chmod
8+
# it from inside the container.
9+
# * A running process's supplementary groups are fixed at exec time, so the
10+
# caller must re-exec (via sg) to pick up the membership we add here.
11+
#
12+
# This script does the ONLY part that needs root: editing /etc/group. It does
13+
# NOT exec the workload, so we never drag the command through sudo's
14+
# env_reset (which would clobber HOME, CODEX_HOME, PATH, etc.). Keep it side
15+
# effect free on stdout apart from the final group name.
16+
set -euo pipefail
17+
18+
SOCK=/var/run/docker.sock
19+
20+
[ -S "$SOCK" ] || exit 0
21+
22+
gid="$(stat -c %g "$SOCK")"
23+
24+
# Find the group name for that GID, creating one if the GID is unknown.
25+
grp="$(getent group "$gid" | cut -d: -f1 || true)"
26+
if [ -z "$grp" ]; then
27+
grp=hostdocker
28+
echo "${grp}:x:${gid}:" >> /etc/group
29+
fi
30+
31+
# Add node to that group if it isn't already a member.
32+
if ! id -nG node | tr ' ' '\n' | grep -qx "$grp"; then
33+
sed -i -E "/^${grp}:/ { /:\$/! s/\$/,/; s/\$/node/ }" /etc/group
34+
fi
35+
36+
printf '%s\n' "$grp"

renovate.json5

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
extends: [
44
'github>libops/renovate-config:default.json5',
55
],
6+
customManagers: [
7+
{
8+
customType: 'regex',
9+
managerFilePatterns: ['/^Dockerfile$/'],
10+
matchStrings: [
11+
'#\\s*renovate:\\s*datasource=deb\\s+depName=(?<depName>[^\\s]+)[^\\n]*\\n\\s+[A-Z0-9_]+_VERSION=(?<currentValue>[^\\s\\\\]+)',
12+
],
13+
datasourceTemplate: 'deb',
14+
registryUrlTemplate: 'https://download.docker.com/linux/debian?suite=trixie&components=stable&binaryArch=amd64',
15+
},
16+
],
617
packageRules: [
718
{
819
matchDatasources: ['golang-version'],

0 commit comments

Comments
 (0)