Skip to content

Commit dbb7a4a

Browse files
authored
Merge pull request #135 from collectiveidea/alpine-no-cache
Use apk add --no-cache to consolidate install on alpine
2 parents ca1e730 + 4eea3a8 commit dbb7a4a

File tree

2 files changed

+5
-9
lines changed

2 files changed

+5
-9
lines changed

lib/generators/templates/_apt_install.erb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
RUN <%= pkg_cache.map {|name, path| "--mount=type=cache,id=#{name},sharing=locked,target=#{path} \\"}.join("\n ") %>
33
<%= repos %><%= pkg_update %> && \
44
<%= pkg_install %> <%= packages.join(" ") %>
5+
<% elsif options.alpine? && clean -%>
6+
RUN apk add --no-cache <%= packages.join(" ") %>
57
<% else -%>
68
RUN <%= repos %><%= pkg_update %> && \
79
<%= pkg_install %> <%= packages.join(" ") %><% if clean %> && \

test/results/alpine/Dockerfile

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ RUN gem update --system --no-document && \
1919
gem install -N bundler
2020

2121
# Install base packages
22-
RUN apk update && \
23-
apk add curl jemalloc postgresql-client tzdata && \
24-
rm -rf /var/cache/apk/*
22+
RUN apk add --no-cache curl jemalloc postgresql-client tzdata
2523

2624
# Set production environment
2725
ENV BUNDLE_DEPLOYMENT="1" \
@@ -34,9 +32,7 @@ ENV BUNDLE_DEPLOYMENT="1" \
3432
FROM base AS build
3533

3634
# Install packages needed to build gems and node modules
37-
RUN apk update && \
38-
apk add build-base gyp libpq-dev pkgconfig python3 yaml-dev && \
39-
rm -rf /var/cache/apk/*
35+
RUN apk add --no-cache build-base gyp libpq-dev pkgconfig python3 yaml-dev
4036

4137
# Install JavaScript dependencies
4238
ARG NODE_VERSION=xxx
@@ -72,9 +68,7 @@ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
7268
FROM base
7369

7470
# Install packages needed for deployment
75-
RUN apk update && \
76-
apk add libpq && \
77-
rm -rf /var/cache/apk/*
71+
RUN apk add --no-cache libpq
7872

7973
# Copy built artifacts: gems, application
8074
COPY --from=build "${BUNDLE_PATH}" "${BUNDLE_PATH}"

0 commit comments

Comments
 (0)