Skip to content

Commit e592dc1

Browse files
authored
Merge pull request rails#53174 from BarnabeD/fix-yarn-dockerfile
[Dockerfile] Fix yarn installation method for yarn > 1.x.x
2 parents 1719d25 + 6f689e7 commit e592dc1

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

railties/lib/rails/generators/app_base.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,11 @@ def dockerfile_yarn_version
540540
"latest"
541541
end
542542

543+
def yarn_through_corepack?
544+
true if dockerfile_yarn_version == "latest"
545+
dockerfile_yarn_version >= "2"
546+
end
547+
543548
def dockerfile_bun_version
544549
using_bun? and `bun --version`[/\d+\.\d+\.\d+/]
545550
rescue

railties/lib/rails/generators/rails/app/templates/Dockerfile.tt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,17 @@ RUN apt-get update -qq && \
3838
ARG NODE_VERSION=<%= node_version %>
3939
ARG YARN_VERSION=<%= dockerfile_yarn_version %>
4040
ENV PATH=/usr/local/node/bin:$PATH
41+
<% if yarn_through_corepack? -%>
42+
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
43+
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
44+
rm -rf /tmp/node-build-master
45+
RUN corepack enable && yarn set version $YARN_VERSION
46+
<% else -%>
4147
RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
4248
/tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
4349
npm install -g yarn@$YARN_VERSION && \
4450
rm -rf /tmp/node-build-master
51+
<% end -%>
4552

4653
<% end -%>
4754
<% if using_bun? -%>
@@ -61,7 +68,7 @@ RUN bundle install && \
6168
<% if using_node? -%>
6269
# Install node modules
6370
COPY package.json yarn.lock ./
64-
RUN yarn install --frozen-lockfile
71+
RUN yarn install --immutable
6572

6673
<% end -%>
6774
<% if using_bun? -%>

0 commit comments

Comments
 (0)