diff --git a/.npmignore b/.npmignore index 4c8400c9..4b1edeec 100644 --- a/.npmignore +++ b/.npmignore @@ -2,6 +2,7 @@ .DS_Store /*.tgz /.bowerrc +/.dockerignore /.editorconfig /.env /.gitignore @@ -9,11 +10,12 @@ /.jscsrc /.npmignore /.npmrc +/.travis.yml +/docker /Dockerfile /bower.json /component.json /gulpfile.js -/node_modules/ /npm-debug.log /res/bower_components/ /res/test/ diff --git a/Dockerfile b/Dockerfile index 224bf9a8..a698121b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,4 @@ -FROM openstf/base:v1.0.1 - -# Add a user for the app. -RUN useradd --system \ - --no-create-home \ - --shell /usr/sbin/nologin \ - --home-dir /app \ - stf +FROM openstf/base:v1.0.2 # Sneak the stf executable into $PATH. ENV PATH /app/bin:$PATH @@ -18,16 +11,31 @@ WORKDIR /app EXPOSE 3000 # Copy app source. -COPY . /app/ +COPY . /tmp/build/ -# Get the rest of the dependencies and build. -RUN export PATH=/app/node_modules/.bin:$PATH && \ - npm install && \ - bower install --allow-root && \ - gulp build && \ - npm prune --production +# Give permissions to our build user. +RUN mkdir -p /app && \ + chown -R stf-build:stf-build /tmp/build /app -# Switch to weak user. +# Switch over to the build user. +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 the app user. USER stf # Show help by default.