mirror of
https://github.com/openstf/stf
synced 2025-10-06 12:00:08 +02:00
Reduce image size to ~580MB by making sure we get absolutely nothing but production dependencies, and clear all caches.
This commit is contained in:
parent
eeaa07c3a8
commit
243be57e10
2 changed files with 30 additions and 9 deletions
|
@ -2,6 +2,7 @@
|
||||||
.DS_Store
|
.DS_Store
|
||||||
/*.tgz
|
/*.tgz
|
||||||
/.bowerrc
|
/.bowerrc
|
||||||
|
/.dockerignore
|
||||||
/.editorconfig
|
/.editorconfig
|
||||||
/.env
|
/.env
|
||||||
/.gitignore
|
/.gitignore
|
||||||
|
@ -9,6 +10,8 @@
|
||||||
/.jscsrc
|
/.jscsrc
|
||||||
/.npmignore
|
/.npmignore
|
||||||
/.npmrc
|
/.npmrc
|
||||||
|
/.travis.yml
|
||||||
|
/docker
|
||||||
/Dockerfile
|
/Dockerfile
|
||||||
/bower.json
|
/bower.json
|
||||||
/component.json
|
/component.json
|
||||||
|
|
36
Dockerfile
36
Dockerfile
|
@ -1,10 +1,13 @@
|
||||||
FROM openstf/base:v1.0.1
|
FROM openstf/base:v1.0.1
|
||||||
|
|
||||||
# Add a user for the app.
|
# Add a user for building and running the app.
|
||||||
RUN useradd --system \
|
RUN useradd --system \
|
||||||
|
--create-home \
|
||||||
|
--shell /usr/sbin/nologin \
|
||||||
|
stf-build && \
|
||||||
|
useradd --system \
|
||||||
--no-create-home \
|
--no-create-home \
|
||||||
--shell /usr/sbin/nologin \
|
--shell /usr/sbin/nologin \
|
||||||
--home-dir /app \
|
|
||||||
stf
|
stf
|
||||||
|
|
||||||
# Sneak the stf executable into $PATH.
|
# Sneak the stf executable into $PATH.
|
||||||
|
@ -18,14 +21,29 @@ WORKDIR /app
|
||||||
EXPOSE 3000
|
EXPOSE 3000
|
||||||
|
|
||||||
# Copy app source.
|
# Copy app source.
|
||||||
COPY . /app/
|
COPY . /tmp/build/
|
||||||
|
|
||||||
# Get the rest of the dependencies and build.
|
# Give permissions to our build user.
|
||||||
RUN export PATH=/app/node_modules/.bin:$PATH && \
|
RUN mkdir -p /app && \
|
||||||
npm install && \
|
chown -R stf-build:stf-build /tmp/build /app
|
||||||
bower install --allow-root && \
|
|
||||||
gulp build && \
|
# Switch over to the build user.
|
||||||
npm prune --production
|
USER stf-build
|
||||||
|
|
||||||
|
# Run the build.
|
||||||
|
RUN set -x && \
|
||||||
|
cd /tmp/build && \
|
||||||
|
export PATH=$PWD/node_modules/.bin:$PATH && \
|
||||||
|
npm install --loglevel http && \
|
||||||
|
npm pack && \
|
||||||
|
tar xzf stf-*.tgz --strip-components 1 -C /app && \
|
||||||
|
bower cache clean && \
|
||||||
|
npm prune --production && \
|
||||||
|
mv node_modules /app && \
|
||||||
|
npm cache clean && \
|
||||||
|
rm -rf ~/.node-gyp && \
|
||||||
|
cd /app && \
|
||||||
|
rm -rf /tmp/*
|
||||||
|
|
||||||
# Switch to weak user.
|
# Switch to weak user.
|
||||||
USER stf
|
USER stf
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue