-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDockerfile
More file actions
229 lines (185 loc) · 7.31 KB
/
Dockerfile
File metadata and controls
229 lines (185 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
# =============================================================================
# Multi-stage Dockerfile for dotfiles container
#
# Targets:
# debian - Prebaked Debian image (default, recommended)
# debian-bootstrap - Debian image that runs bootstrap on first start
# arch - Prebaked Arch Linux image
# arch-bootstrap - Arch Linux image that runs bootstrap on first start
#
# Usage:
# docker build --target debian -t myimage .
# docker build --target arch-bootstrap -t myimage .
# =============================================================================
# =============================================================================
# DEBIAN BASE STAGE
# =============================================================================
FROM docker.io/library/debian:bookworm-slim AS debian-base
# Install base dependencies required for bootstrap
RUN apt-get update && apt-get install -y --no-install-recommends \
bash \
curl \
wget \
git \
build-essential \
sudo \
ca-certificates \
python3 \
python3-pip \
python3-venv \
openssh-server \
openssh-client \
unzip \
gnupg \
pkg-config \
libgtk-3-dev \
libglib2.0-dev \
libwebkit2gtk-4.1-dev \
libayatana-appindicator3-dev \
librsvg2-dev \
&& rm -rf /var/lib/apt/lists/*
# Create sshd run directory (required for Debian)
RUN mkdir -p /run/sshd
# =============================================================================
# ARCH BASE STAGE
# =============================================================================
FROM docker.io/library/archlinux:latest AS arch-base
# Install base dependencies
RUN pacman -Syu --noconfirm \
base-devel \
git \
curl \
wget \
sudo \
ca-certificates \
python \
python-pip \
openssh \
unzip \
gnupg \
pkgconf \
gtk3 \
glib2 \
webkit2gtk-4.1 \
libayatana-appindicator \
librsvg \
fish \
&& pacman -Scc --noconfirm
# Create sshd run directory
RUN mkdir -p /run/sshd
# =============================================================================
# USER SETUP (shared pattern)
# =============================================================================
FROM debian-base AS debian-user
ARG USERNAME=rfhold
ARG USER_UID=1000
ARG USER_GID=1000
RUN groupadd -g $USER_GID $USERNAME \
&& useradd -m -u $USER_UID -g $USERNAME -s /bin/bash $USERNAME \
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& passwd -d $USERNAME
COPY etc/sshd_config /etc/ssh/sshd_config
FROM arch-base AS arch-user
ARG USERNAME=rfhold
ARG USER_UID=1000
ARG USER_GID=1000
RUN groupadd -g $USER_GID $USERNAME \
&& useradd -m -u $USER_UID -g $USERNAME -s /bin/bash $USERNAME \
&& echo "$USERNAME ALL=(ALL) NOPASSWD:ALL" >> /etc/sudoers \
&& passwd -d $USERNAME
# Use Arch-specific sshd_config (different sftp path, no PrintLastLog)
COPY etc/sshd_config.arch /etc/ssh/sshd_config
# =============================================================================
# DEBIAN COMMON - Copy dotfiles and configure environment
# =============================================================================
FROM debian-user AS debian-common
ARG USERNAME=rfhold
USER $USERNAME
WORKDIR /home/$USERNAME
# Copy bootstrap script first for better layer caching
COPY --chown=$USERNAME:$USERNAME bin/bootstrap.sh /home/$USERNAME/dot/bin/bootstrap.sh
# Copy the rest of dotfiles (changes more frequently)
COPY --chown=$USERNAME:$USERNAME . /home/$USERNAME/dot
# Environment setup
ENV PATH="/home/rfhold/dot/bin/container:/home/rfhold/.local/bin:/usr/local/go/bin:/home/rfhold/.bun/bin:/home/rfhold/.cargo/bin:/home/rfhold/go/bin:${PATH}"
ENV SHELL=/usr/bin/fish
EXPOSE 22
# =============================================================================
# ARCH COMMON - Copy dotfiles and configure environment
# =============================================================================
FROM arch-user AS arch-common
ARG USERNAME=rfhold
USER $USERNAME
WORKDIR /home/$USERNAME
# Copy bootstrap script first for better layer caching
COPY --chown=$USERNAME:$USERNAME bin/bootstrap.sh /home/$USERNAME/dot/bin/bootstrap.sh
# Copy the rest of dotfiles (changes more frequently)
COPY --chown=$USERNAME:$USERNAME . /home/$USERNAME/dot
# Environment setup
ENV PATH="/home/rfhold/dot/bin/container:/home/rfhold/.local/bin:/usr/local/go/bin:/home/rfhold/.bun/bin:/home/rfhold/.cargo/bin:/home/rfhold/go/bin:${PATH}"
ENV SHELL=/usr/bin/fish
EXPOSE 22
# =============================================================================
# DEBIAN PREBAKED - Bootstrap at build time (recommended)
# =============================================================================
FROM debian-common AS debian
ARG USERNAME=rfhold
# Run bootstrap (installs rustup, uv, go, bun and runs pyinfra)
RUN /home/$USERNAME/dot/bin/bootstrap.sh
# Mark bootstrap complete so entrypoint skips it
RUN touch /home/$USERNAME/.bootstrap-complete
# Set fish as the user's login shell
RUN sudo chsh -s /usr/bin/fish $USERNAME
# Aggressive cleanup of build caches to reduce image size
RUN rm -rf ~/.cargo/registry ~/.cargo/git \
&& rm -rf ~/.cache/uv \
&& rm -rf ~/.cache/go-build \
&& rm -rf ~/.bun/install/cache \
&& sudo apt-get clean \
&& sudo rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
ENTRYPOINT ["/home/rfhold/dot/bin/entrypoint.sh"]
CMD []
# =============================================================================
# ARCH PREBAKED - Bootstrap at build time
# =============================================================================
FROM arch-common AS arch
ARG USERNAME=rfhold
# Run bootstrap (installs rustup, uv, go, bun and runs pyinfra)
RUN /home/$USERNAME/dot/bin/bootstrap.sh
# Mark bootstrap complete so entrypoint skips it
RUN touch /home/$USERNAME/.bootstrap-complete
# Set fish as the user's login shell
RUN sudo chsh -s /usr/bin/fish $USERNAME
# Aggressive cleanup of build caches to reduce image size
RUN rm -rf ~/.cargo/registry ~/.cargo/git \
&& rm -rf ~/.cache/uv \
&& rm -rf ~/.cache/go-build \
&& rm -rf ~/.bun/install/cache \
&& sudo pacman -Scc --noconfirm \
&& sudo rm -rf /tmp/* /var/tmp/*
ENTRYPOINT ["/home/rfhold/dot/bin/entrypoint.sh"]
CMD []
# =============================================================================
# DEBIAN BOOTSTRAP - Bootstrap at runtime (smaller image, slower first start)
# =============================================================================
FROM debian-common AS debian-bootstrap
ARG USERNAME=rfhold
# Set fish as the user's login shell (fish installed via apt in base)
RUN sudo chsh -s /usr/bin/fish $USERNAME
# Clean apt cache
RUN sudo apt-get clean && sudo rm -rf /var/lib/apt/lists/*
# Bootstrap will run on first container start via entrypoint
ENTRYPOINT ["/home/rfhold/dot/bin/entrypoint.sh"]
CMD []
# =============================================================================
# ARCH BOOTSTRAP - Bootstrap at runtime (smaller image, slower first start)
# =============================================================================
FROM arch-common AS arch-bootstrap
ARG USERNAME=rfhold
# Set fish as the user's login shell (fish installed via pacman in base)
RUN sudo chsh -s /usr/bin/fish $USERNAME
# Clean pacman cache
RUN sudo pacman -Scc --noconfirm
# Bootstrap will run on first container start via entrypoint
ENTRYPOINT ["/home/rfhold/dot/bin/entrypoint.sh"]
CMD []