Skip to content

Commit a7d36b5

Browse files
committed
Copy bun's executable from official image instead of installing
1 parent 591c56e commit a7d36b5

File tree

3 files changed

+17
-11
lines changed

3 files changed

+17
-11
lines changed

lib/generators/templates/Dockerfile.erb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,15 @@ FROM prebuild AS <% if using_bun? %>bun<% else %>node<% end %>
7171

7272
<% end -%>
7373
<% if using_bun? and (!using_execjs? || File.exist?('bun.lockb') || File.exist?('bun.lock')) -%>
74+
<% if bun_version -%>
75+
ARG BUN_VERSION=<%= bun_version %>
76+
<% end -%>
77+
<% if options.alpine? -%>
78+
FROM oven/bun:<%= bun_version ? '${BUN_VERSION}' : '1' %>-alpine AS bun
79+
<% else -%>
80+
FROM oven/bun:<%= bun_version ? '${BUN_VERSION}' : '1' %>-debian AS bun
81+
<% end -%>
82+
7483
<%= render partial: 'install_node', locals: {bun_version: using_execjs? ? nil : bun_version} %>
7584

7685
<% elsif using_node? and (!using_execjs? || File.exist?('yarn.lock')) -%>

lib/generators/templates/_install_node.erb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<% if using_bun? -%>
2-
# Install Bun
3-
<% if bun_version -%>
4-
ARG BUN_VERSION=<%= bun_version %>
5-
<% end -%>
6-
ENV BUN_INSTALL=/usr/local/bun
7-
ENV PATH=/usr/local/bun/bin:$PATH
8-
RUN curl -fsSL https://bun.sh/install | bash<% if bun_version %> -s -- "bun-v${BUN_VERSION}"<% end %>
2+
# Copy Bun from official image
3+
COPY --from=bun /usr/local/bin/bun /usr/local/bin/bun
4+
ENV PATH=/usr/local/bin:$PATH
95
<% else -%>
106
<% if node_version and yarn_version -%>
117
# Install JavaScript dependencies

test/results/bun/Dockerfile

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,11 +38,12 @@ RUN apt-get update -qq && \
3838
apt-get install --no-install-recommends -y build-essential libyaml-dev pkg-config unzip && \
3939
rm -rf /var/lib/apt/lists /var/cache/apt/archives
4040

41-
# Install Bun
4241
ARG BUN_VERSION=xxx
43-
ENV BUN_INSTALL=/usr/local/bun
44-
ENV PATH=/usr/local/bun/bin:$PATH
45-
RUN curl -fsSL https://bun.sh/install | bash -s -- "bun-v${BUN_VERSION}"
42+
FROM oven/bun:${BUN_VERSION}-debian AS bun
43+
44+
# Copy Bun from official image
45+
COPY --from=bun /usr/local/bin/bun /usr/local/bin/bun
46+
ENV PATH=/usr/local/bin:$PATH
4647

4748
# Install application gems
4849
COPY Gemfile Gemfile.lock ./

0 commit comments

Comments
 (0)