lib/generators/templates/Dockerfile.erb in dockerfile-rails-0.4.1 vs lib/generators/templates/Dockerfile.erb in dockerfile-rails-0.4.2

- old
+ new

@@ -19,52 +19,40 @@ # Set production environment ENV RAILS_ENV="production" \ BUNDLE_PATH="vendor/bundle" \ BUNDLE_WITHOUT="<%= options.ci? ? 'test' : 'development:test' %>" +# Update gems and preinstall the desired version of bundler ARG BUNDLER_VERSION=<%= Bundler::VERSION %> RUN gem update --system --no-document && \ gem install -N bundler -v ${BUNDLER_VERSION} +<% if using_execjs? -%> +# Install packages needed to install nodejs +<%= render partial: 'apt_install', locals: {packages: %w(curl unzip), clean: true} %> +<%= render partial: 'install_node', locals: {yarn_version: nil} %> + +<% end -%> + # Throw-away build stage<%= parallel? ? 's' : '' %> to reduce size of final image FROM base as <%= parallel? ? 'pre' : '' %>build -# Install packages need to build gems<%= using_node? ? " and node modules" : "" %> -<% if options.cache? %> -RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \ - --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \ - apt-get update -qq && \ -<% else -%> -RUN apt-get update -qq && \ -<% end -%> - apt-get install -y <%= build_packages.join(" ") %> +# Install packages needed to build gems<%= using_node? ? " and node modules" : "" %> +<%= render partial: 'apt_install', locals: {packages: build_packages, clean: false} %> <% if parallel? -%> FROM prebuild as node <% end -%> <% if using_node? -%> -# Install JavaScript dependencies -ARG NODE_VERSION=<%= node_version %> -ARG YARN_VERSION=<%= yarn_version %> -RUN curl -fsSL https://fnm.vercel.app/install | bash && \ - /root/.local/share/fnm/fnm install $NODE_VERSION -ENV PATH=/root/.local/share/fnm/aliases/default/bin/:$PATH -RUN npm install -g yarn@$YARN_VERSION +<%= render partial: 'install_node', locals: {node_version: using_execjs? ? nil : node_version} %> <% end -%> <% if parallel? -%> -# Install node modules -COPY package.json yarn.lock ./ -<% if options.cache? -%> -RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \ - YARN_CACHE_FOLDER=/root/.yarn yarn install -<% else -%> -RUN yarn install -<% end -%> +<%= render partial: 'npm_install', locals: {sources: %w(package.json yarn.lock)} %> FROM prebuild as build <% end -%> @@ -89,18 +77,11 @@ <% end -%> <% if parallel? -%> asdf <% elsif using_node? -%> -# Install node modules -COPY package.json yarn.lock ./ -<% if options.cache? -%> -RUN --mount=type=cache,id=bld-yarn-cache,target=/root/.yarn \ - YARN_CACHE_FOLDER=/root/.yarn yarn install -<% else -%> -RUN yarn install -<% end -%> +<%= render partial: 'npm_install', locals: {sources: %w(package.json yarn.lock)} %> <% end -%> # Copy application code COPY . . @@ -122,20 +103,11 @@ # Final stage for app image FROM base <% unless deploy_packages.empty? -%> -# Install packages need for deployment -<% if options.cache? -%> -RUN --mount=type=cache,id=dev-apt-cache,sharing=locked,target=/var/cache/apt \ - --mount=type=cache,id=dev-apt-lib,sharing=locked,target=/var/lib/apt \ - apt-get update -qq && \ - apt-get install --no-install-recommends -y <%= deploy_packages.join(" ") %> -<% else -%> -RUN apt-get update -qq && \ - apt-get install --no-install-recommends -y <%= deploy_packages.join(" ") %> && \ - rm -rf /var/lib/apt/lists /var/cache/apt/archives -<% end -%> +# Install packages needed for deployment +<%= render partial: 'apt_install', locals: {packages: deploy_packages, clean: true} %> <% end -%> # Copy built application from previous stage <% if options.ci? -%> COPY --from=build /usr/local/bundle /usr/local/bundle