From 44bcd3952bc0993b53bb1bb93d530c1a69a0b1fe Mon Sep 17 00:00:00 2001 From: Shen Yang Date: Thu, 12 Feb 2026 10:39:46 -0600 Subject: [PATCH 1/3] DRY project root --- Dockerfile | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/Dockerfile b/Dockerfile index c95a446518..061d849df7 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,10 @@ +ARG ROOT=/usr/src/app/ + FROM ruby:3.3.8-alpine AS builder +ARG ROOT +WORKDIR $ROOT + RUN apk update && apk upgrade && apk add --update --no-cache \ build-base \ curl-dev \ @@ -9,17 +14,14 @@ RUN apk update && apk upgrade && apk add --update --no-cache \ postgresql-dev \ tzdata -ARG RAILS_ROOT=/usr/src/app/ -WORKDIR $RAILS_ROOT -COPY Gemfile* $RAILS_ROOT +COPY Gemfile* $ROOT RUN bundle install -### BUILD STEP DONE ### - FROM ruby:3.3.8-alpine -ARG RAILS_ROOT=/usr/src/app/ +ARG ROOT +WORKDIR $ROOT RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main/ nodejs=24.13.0-r2 npm @@ -34,8 +36,6 @@ RUN apk update && apk upgrade && apk add --update --no-cache \ vim \ && rm -rf /var/cache/apk/* -WORKDIR $RAILS_ROOT - COPY . . RUN npm install --global npm@latest RUN npm install From 0bffe8be3fae48f96cc20e305fc212d101ab772a Mon Sep 17 00:00:00 2001 From: Shen Yang Date: Thu, 12 Feb 2026 16:14:51 -0600 Subject: [PATCH 2/3] format build stages for easier reading --- Dockerfile | 68 ++++++++++++++++++++++++++---------------------------- 1 file changed, 33 insertions(+), 35 deletions(-) diff --git a/Dockerfile b/Dockerfile index 061d849df7..2162c65a7f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,49 +1,47 @@ ARG ROOT=/usr/src/app/ FROM ruby:3.3.8-alpine AS builder + ARG ROOT + WORKDIR $ROOT -ARG ROOT -WORKDIR $ROOT + RUN apk update && apk upgrade && apk add --update --no-cache \ + build-base \ + curl-dev \ + libffi-dev \ + yaml-dev \ + linux-headers \ + postgresql-dev \ + tzdata -RUN apk update && apk upgrade && apk add --update --no-cache \ - build-base \ - curl-dev \ - libffi-dev \ - yaml-dev \ - linux-headers \ - postgresql-dev \ - tzdata - -COPY Gemfile* $ROOT -RUN bundle install + COPY Gemfile* $ROOT + RUN bundle install FROM ruby:3.3.8-alpine + ARG ROOT + WORKDIR $ROOT -ARG ROOT -WORKDIR $ROOT - -RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main/ nodejs=24.13.0-r2 npm + RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main/ nodejs=24.13.0-r2 npm -# available: https://pkgs.alpinelinux.org/packages -RUN apk update && apk upgrade && apk add --update --no-cache \ - bash \ - build-base \ - curl \ - imagemagick \ - postgresql-client \ - tzdata \ - vim \ - && rm -rf /var/cache/apk/* + # available: https://pkgs.alpinelinux.org/packages + RUN apk update && apk upgrade && apk add --update --no-cache \ + bash \ + build-base \ + curl \ + imagemagick \ + postgresql-client \ + tzdata \ + vim \ + && rm -rf /var/cache/apk/* -COPY . . -RUN npm install --global npm@latest -RUN npm install -RUN npm run build && npm run build:css + COPY . . + RUN npm install --global npm@latest + RUN npm install + RUN npm run build && npm run build:css -COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ + COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ -EXPOSE 3000 + EXPOSE 3000 -ENTRYPOINT ["./docker-entrypoint.sh"] -CMD ["bin/rails", "s", "-b", "0.0.0.0"] + ENTRYPOINT ["./docker-entrypoint.sh"] + CMD ["bin/rails", "s", "-b", "0.0.0.0"] From 7e3c0190db1de4d20ccb9101caa0272a24bb9142 Mon Sep 17 00:00:00 2001 From: Shen Yang Date: Thu, 12 Feb 2026 23:17:54 -0600 Subject: [PATCH 3/3] source node binaries from pinned alpine image --- Dockerfile | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Dockerfile b/Dockerfile index 2162c65a7f..5f7413b150 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,6 +1,10 @@ ARG ROOT=/usr/src/app/ -FROM ruby:3.3.8-alpine AS builder +# available alpine packages: https://pkgs.alpinelinux.org/packages + +FROM node:24-alpine AS node-source + +FROM ruby:3.3.8-alpine AS build ARG ROOT WORKDIR $ROOT @@ -13,7 +17,6 @@ FROM ruby:3.3.8-alpine AS builder postgresql-dev \ tzdata - COPY Gemfile* $ROOT RUN bundle install @@ -21,9 +24,6 @@ FROM ruby:3.3.8-alpine ARG ROOT WORKDIR $ROOT - RUN apk add --no-cache --repository http://dl-cdn.alpinelinux.org/alpine/edge/main/ nodejs=24.13.0-r2 npm - - # available: https://pkgs.alpinelinux.org/packages RUN apk update && apk upgrade && apk add --update --no-cache \ bash \ build-base \ @@ -35,11 +35,12 @@ FROM ruby:3.3.8-alpine && rm -rf /var/cache/apk/* COPY . . - RUN npm install --global npm@latest - RUN npm install - RUN npm run build && npm run build:css + COPY --from=node-source /usr/local/bin/node /usr/local/bin/node + COPY --from=node-source /usr/local/lib/node_modules /usr/local/lib/node_modules + RUN ln -s /usr/local/lib/node_modules/npm/bin/npm-cli.js /usr/local/bin/npm + RUN npm ci - COPY --from=builder /usr/local/bundle/ /usr/local/bundle/ + COPY --from=build /usr/local/bundle/ /usr/local/bundle/ EXPOSE 3000