Repository navigation
Expand file tree
/
Copy pathDockerfile
More file actions
232 lines (202 loc) · 9.62 KB
/
Copy pathDockerfile
File metadata and controls
232 lines (202 loc) · 9.62 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
230
231
232
FROM codercom/code-server:latest
ARG USER_UID=1000
ARG USER_GID=1000
ARG DOCKER_GID=1001
ARG PHP_VERSION=8.4
ARG PHPUNIT_MAJOR=13
ARG NODE_MAJOR=24
ARG LANDO_VERSION=3.26.9
# --- Root operations: UID/GID adjustment and system packages ---
USER root
# Adjust coder user/group to match host UID/GID
RUN groupmod -g ${USER_GID} coder \
&& usermod -u ${USER_UID} -g ${USER_GID} coder \
&& chown -R ${USER_UID}:${USER_GID} /home/coder
# Create docker group matching host socket GID and add coder to it
RUN groupadd -g ${DOCKER_GID} docker \
&& usermod -aG docker coder
# System prerequisites
RUN apt-get update && apt-get install -y --no-install-recommends \
curl \
dnsmasq \
iproute2 \
git \
gnupg \
gosu \
libatomic1 \
lsb-release \
ca-certificates \
unzip \
wget \
&& rm -rf /var/lib/apt/lists/*
# Add Ondrej Sury PHP repository (Debian variant)
RUN curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /usr/share/keyrings/sury-php.gpg \
&& echo "deb [signed-by=/usr/share/keyrings/sury-php.gpg] https://packages.sury.org/php/ $(lsb_release -sc) main" \
> /etc/apt/sources.list.d/sury-php.list
# Install PHP and extensions
RUN apt-get update && apt-get install -y --no-install-recommends \
php${PHP_VERSION}-cli \
php${PHP_VERSION}-mbstring \
php${PHP_VERSION}-xml \
php${PHP_VERSION}-curl \
php${PHP_VERSION}-zip \
php${PHP_VERSION}-gd \
php${PHP_VERSION}-intl \
php${PHP_VERSION}-mysql \
php${PHP_VERSION}-pgsql \
php${PHP_VERSION}-sqlite3 \
php${PHP_VERSION}-bcmath \
php${PHP_VERSION}-xdebug \
&& rm -rf /var/lib/apt/lists/*
# Install Composer via official installer, verifying the installer's SHA-384
# against the published signature before running it.
RUN EXPECTED_SIG="$(curl -fsSL https://composer.github.io/installer.sig)" \
&& curl -fsSL https://getcomposer.org/installer -o /tmp/composer-setup.php \
&& ACTUAL_SIG="$(php -r "echo hash_file('sha384', '/tmp/composer-setup.php');")" \
&& if [ "$EXPECTED_SIG" != "$ACTUAL_SIG" ]; then \
echo "ERROR: Invalid Composer installer checksum" >&2; rm -f /tmp/composer-setup.php; exit 1; \
fi \
&& php /tmp/composer-setup.php --quiet --install-dir=/usr/local/bin --filename=composer \
&& rm -f /tmp/composer-setup.php
# Install PHPUnit (global phar) as a fallback test runner.
# Projects should still prefer their own vendor/bin/phpunit (Drupal pins its own
# PHPUnit version via composer); this global binary covers ad-hoc scripts and
# projects without a composer-managed PHPUnit. PHPUnit 13 requires PHP >= 8.4 —
# lower PHPUNIT_MAJOR if you build with an older PHP_VERSION (12 needs >= 8.3).
RUN curl -fsSL https://phar.phpunit.de/phpunit-${PHPUNIT_MAJOR}.phar -o /usr/local/bin/phpunit \
&& chmod +x /usr/local/bin/phpunit \
&& phpunit --version
# Add NodeSource repository
RUN curl -fsSL https://deb.nodesource.com/setup_${NODE_MAJOR}.x | bash -
# Install Node.js and yarn
RUN apt-get update && apt-get install -y --no-install-recommends \
nodejs \
&& npm install -g yarn \
&& rm -rf /var/lib/apt/lists/*
# Install Python 3 and pip
RUN apt-get update && apt-get install -y --no-install-recommends \
python3 \
python3-pip \
python3-venv \
&& rm -rf /var/lib/apt/lists/*
# Install uv (Python package manager)
RUN curl -LsSf https://astral.sh/uv/install.sh | sh \
&& mv /root/.local/bin/uv /usr/local/bin/ \
&& mv /root/.local/bin/uvx /usr/local/bin/
# Install bun (JavaScript runtime, bundler & package manager).
# The installer drops bun into /root/.bun/bin; move it onto the system PATH so
# it's available to the coder user without per-user profile changes (matches uv).
RUN curl -fsSL https://bun.sh/install | bash \
&& mv /root/.bun/bin/bun /usr/local/bin/bun \
&& ln -sf bun /usr/local/bin/bunx \
&& rm -rf /root/.bun
# Install Playwright with the Chromium browser for agent-driven browsing.
# Browsers live in a system-wide path (PLAYWRIGHT_BROWSERS_PATH) so they're
# shared by the coder user and any project-local Playwright installs instead of
# being re-downloaded per project. `--with-deps` also installs the OS libraries
# Chromium needs via apt, which requires root (still in effect at this stage).
# The browser dir is handed to coder so additional/updated browsers can be
# installed later without sudo.
ENV PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers
RUN npm install -g playwright \
&& mkdir -p /opt/pw-browsers \
&& playwright install --with-deps chromium \
&& chown -R coder:coder /opt/pw-browsers \
&& rm -rf /var/lib/apt/lists/*
# Install GitHub CLI
RUN curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg \
| gpg --dearmor -o /usr/share/keyrings/githubcli-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" \
> /etc/apt/sources.list.d/github-cli.list \
&& apt-get update && apt-get install -y --no-install-recommends gh \
&& rm -rf /var/lib/apt/lists/*
# Install Docker CLI (connects to host Docker via mounted socket)
RUN curl -fsSL https://download.docker.com/linux/debian/gpg \
| gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg \
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -sc) stable" \
> /etc/apt/sources.list.d/docker.list \
&& apt-get update && apt-get install -y --no-install-recommends docker-ce-cli docker-compose-plugin \
&& rm -rf /var/lib/apt/lists/*
# Install Drush Launcher
RUN curl -fsSL https://github.com/drush-ops/drush-launcher/releases/latest/download/drush.phar \
-o /usr/local/bin/drush \
&& chmod +x /usr/local/bin/drush
# Install nvm (Node Version Manager) for switching Node versions per project
# PROFILE=/dev/null prevents nvm from modifying root's shell profiles during install;
# we add the source lines to coder's .bashrc manually below.
ARG NVM_VERSION=0.41.0
RUN mkdir -p /home/coder/.nvm \
&& curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v${NVM_VERSION}/install.sh \
| NVM_DIR=/home/coder/.nvm PROFILE=/dev/null bash \
&& chown -R coder:coder /home/coder/.nvm
# Install Lando CLI (npm package; rename real binary so wrapper can replace it)
# Lando's plugin discovery looks in <core>/node_modules/@lando/, NOT in sibling global
# packages — so all recipe/service plugins must be installed as local deps inside core.
# Install a comprehensive set covering common Drupal 10 project stacks.
RUN npm install -g @lando/core@${LANDO_VERSION} \
&& cd $(npm root -g)/@lando/core && npm install \
@lando/drupal \
@lando/php \
@lando/mysql \
@lando/mariadb \
@lando/postgres \
@lando/nginx \
@lando/apache \
@lando/compose \
@lando/redis \
@lando/memcached \
@lando/solr \
@lando/elasticsearch \
@lando/varnish \
@lando/mailhog \
@lando/phpmyadmin \
@lando/node \
&& ln -sf $(npm root -g)/@lando/core/bin/lando /usr/local/bin/lando.real
# Install Claude Code globally as root so coder user doesn't need a global npm prefix.
# Installing it here keeps coder's .npmrc clean, avoiding nvm/prefix conflicts.
RUN npm install -g @anthropic-ai/claude-code
# Install path-translation wrapper as the 'lando' command
COPY lando-wrapper.sh /usr/local/bin/lando
RUN chmod +x /usr/local/bin/lando
# --- Switch to coder user for extensions and config ---
USER coder
# Set up PATH additions and nvm sourcing for interactive shells.
# No npm prefix is set — nvm manages per-version global installs;
# system-level tools (claude, lando, etc.) are installed as root above.
# $HOME is expanded at shell start-up (single quotes), so it follows the
# HOST_HOME_DIR remap done by entrypoint.sh instead of hard-coding a username.
# /home/coder/src is this repo's src/ directory, bind-mounted by docker-compose.yml.
RUN echo 'export PATH="$HOME/.lando/bin:$PATH"' >> /home/coder/.bashrc \
&& echo 'export PATH="/home/coder/src:$PATH"' >> /home/coder/.bashrc \
&& echo 'export PLAYWRIGHT_BROWSERS_PATH=/opt/pw-browsers' >> /home/coder/.bashrc \
&& echo 'export NVM_DIR="/home/coder/.nvm"' >> /home/coder/.bashrc \
&& echo '[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"' >> /home/coder/.bashrc \
&& echo '[ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"' >> /home/coder/.bashrc
ENV PATH="/home/coder/src:${PATH}"
# Pre-create directories to prevent bind-mounts from creating them as directories
RUN mkdir -p /home/coder/.local/share/code-server/User \
&& mkdir -p /home/coder/.claude \
&& mkdir -p /home/coder/src
# Install VS Code extensions from extensions.txt
COPY extensions.txt /home/coder/extensions.txt
RUN failed_exts=""; \
while IFS= read -r ext || [ -n "$ext" ]; do \
ext=$(echo "$ext" | sed 's/#.*//;s/^[[:space:]]*//;s/[[:space:]]*$//'); \
[ -z "$ext" ] && continue; \
if ! code-server --install-extension "$ext"; then \
echo "Failed to install VS Code extension: $ext" >&2; \
failed_exts="${failed_exts} $ext"; \
fi; \
done < /home/coder/extensions.txt; \
if [ -n "$failed_exts" ]; then \
echo "One or more VS Code extensions failed to install:${failed_exts}" >&2; \
exit 1; \
fi
# Switch back to root for entrypoint (drops to coder via gosu at runtime)
USER root
# Copy entrypoint script
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh
WORKDIR /home/coder/code
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
CMD ["code-server", "--bind-addr", "0.0.0.0:8080", "."]