Skip to content

Commit 8579541

Browse files
committed
docker: optimize Dockerfile by consolidating installation steps and improving cache usage
1 parent 461c475 commit 8579541

File tree

1 file changed

+17
-25
lines changed

1 file changed

+17
-25
lines changed

Dockerfile

Lines changed: 17 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -20,31 +20,21 @@ ENV AUTORUN_ENABLED="true" \
2020
# Switch to root so we can do root things
2121
USER root
2222

23-
# Install jq for parsing GitHub API responses and iperf for network testing
24-
RUN apk add --no-cache jq iperf3
25-
26-
# Install LibreSpeed CLI
27-
RUN curl -o \
28-
/tmp/librespeed-cli.tgz -L \
29-
"https://github.com/librespeed/speedtest-cli/releases/download/v${LIBRESPEED_CLI_VERSION}/librespeed-cli_${LIBRESPEED_CLI_VERSION}_linux_amd64.tar.gz" && \
30-
tar xzf \
31-
/tmp/librespeed-cli.tgz -C \
32-
/usr/bin \
33-
&& rm /tmp/librespeed-cli.tgz
34-
35-
36-
# Install Speedtest CLI
37-
RUN curl -o \
38-
/tmp/speedtest-cli.tgz -L \
39-
"https://install.speedtest.net/app/cli/ookla-speedtest-${OOKLA_CLI_VERSION}-linux-x86_64.tgz" && \
40-
tar xzf \
41-
/tmp/speedtest-cli.tgz -C \
42-
/usr/bin \
43-
&& rm /tmp/speedtest-cli.tgz
23+
# Install system dependencies and clean up in the same layer
24+
RUN apk add --no-cache jq iperf3 \
25+
&& rm -rf /var/cache/apk/*
26+
27+
# Install CLI tools in a single layer
28+
RUN curl -o /tmp/librespeed-cli.tgz -L \
29+
"https://github.com/librespeed/speedtest-cli/releases/download/v${LIBRESPEED_CLI_VERSION}/librespeed-cli_${LIBRESPEED_CLI_VERSION}_linux_amd64.tar.gz" \
30+
&& curl -o /tmp/speedtest-cli.tgz -L \
31+
"https://install.speedtest.net/app/cli/ookla-speedtest-${OOKLA_CLI_VERSION}-linux-x86_64.tgz" \
32+
&& tar xzf /tmp/librespeed-cli.tgz -C /usr/bin \
33+
&& tar xzf /tmp/speedtest-cli.tgz -C /usr/bin \
34+
&& rm /tmp/librespeed-cli.tgz /tmp/speedtest-cli.tgz
4435

4536
# Install the intl extension with root permissions
4637
RUN install-php-extensions intl \
47-
&& rm -rf /var/cache/apk/* \
4838
&& rm -rf /tmp/*
4939

5040
# Drop back to our unprivileged user
@@ -70,18 +60,20 @@ RUN set -e; \
7060
&& rm ${RELEASE_TAG}.tar.gz; \
7161
fi
7262

73-
RUN composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
63+
RUN --mount=type=cache,target=/tmp/cache \
64+
COMPOSER_CACHE_DIR=/tmp/cache composer install --no-interaction --prefer-dist --optimize-autoloader --no-dev
7465

7566
#############################
7667
# Node go brrr
7768
#############################
78-
FROM node:24 AS assets
69+
FROM node:24-alpine AS assets
7970

8071
WORKDIR /app
8172

8273
COPY --from=base /var/www/html /app
8374

84-
RUN npm ci && npm run build
75+
RUN --mount=type=cache,target=/root/.npm \
76+
npm ci && npm run build
8577

8678
#############################
8779
# Production image

0 commit comments

Comments
 (0)