Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updating gulp, webpack, and Dockerfile #118

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .bowerrc
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
{
"registry": "https://registry.bower.io",
"directory": "res/bower_components"
"registry": "http://registry.bower.io",
"directory": "/tmp/build/bower_modules",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if there is an explanation in the commit message, I'd rather not keep it that way.

"allow_root": true,
"off_proxy": "http://127.0.0.1:8080",
"off_https-proxy": "http://127.0.0.1:8080",
"strict-ssl": false
}
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ rethinkdb_data/
temp/
tmp/
.eslintcache
Dockerfile
169 changes: 106 additions & 63 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,74 +1,117 @@
FROM ubuntu:16.04
FROM ubuntu:18.04 AS nodebase

# Sneak the stf executable into $PATH.
ENV PATH /app/bin:$PATH
# Install base packages
RUN export DEBIAN_FRONTEND=noninteractive && \
apt-get update && \
apt-get -y --no-install-recommends install curl wget libxml-bare-perl libzmq3-dev libprotobuf-dev graphicsmagick ca-certificates openjdk-8-jdk

# Work in app dir by default.
WORKDIR /app
# Install node
RUN export DEBIAN_FRONTEND=noninteractive && \
curl -sL -o /tmp/install_node.sh https://deb.nodesource.com/setup_8.x && \
/bin/bash /tmp/install_node.sh && \
apt install --no-install-recommends -y nodejs

# Export default app port, not enough for all processes but it should do
# for now.
EXPOSE 3000
RUN useradd --system --create-home --shell /usr/sbin/nologin stf

FROM nodebase as with_packages

# Install app requirements. Trying to optimize push speed for dependant apps
# by reducing layers as much as possible. Note that one of the final steps
# installs development files for node-gyp so that npm install won't have to
# wait for them on the first native module installation.
# Install additional packages for building things
RUN export DEBIAN_FRONTEND=noninteractive && \
useradd --system \
--create-home \
--shell /usr/sbin/nologin \
stf-build && \
useradd --system \
--create-home \
--shell /usr/sbin/nologin \
stf && \
sed -i'' 's@http://archive.ubuntu.com/ubuntu/@mirror://mirrors.ubuntu.com/mirrors.txt@' /etc/apt/sources.list && \
apt-get update && \
apt-get -y install wget python build-essential && \
cd /tmp && \
wget --progress=dot:mega \
https://nodejs.org/dist/v8.9.3/node-v8.9.3-linux-x64.tar.xz && \
tar -xJf node-v*.tar.xz --strip-components 1 -C /usr/local && \
rm node-v*.tar.xz && \
su stf-build -s /bin/bash -c '/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js install' && \
apt-get -y install libzmq3-dev libprotobuf-dev git graphicsmagick openjdk-8-jdk yasm && \
apt-get clean && \
rm -rf /var/cache/apt/* /var/lib/apt/lists/* && \
mkdir /tmp/bundletool && \
cd /tmp/bundletool && \
wget --progress=dot:mega \
https://github.com/google/bundletool/releases/download/1.2.0/bundletool-all-1.2.0.jar && \
mv bundletool-all-1.2.0.jar bundletool.jar

# Copy app source.
COPY . /tmp/build/

# Give permissions to our build user.
RUN mkdir -p /app && \
chown -R stf-build:stf-build /tmp/build /tmp/bundletool /app

# Switch over to the build user.
USER stf-build

# Run the build.
apt-get -y --no-install-recommends install build-essential git yasm jq python vim

# Install node-gyp ahead of time to avoid installation on native module install
# RUN /bin/bash -c '/usr/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js install'

# Install just the package dependencies before copying in the full source
RUN mkdir -p /tmp/build/res/build
COPY ./package*.json /tmp/build/
WORKDIR /tmp/build
RUN set -x && \
cd /tmp/build && \
export PATH=$PWD/node_modules/.bin:$PATH && \
npm install --loglevel http && \
npm pack && \
tar xzf devicefarmer-stf-*.tgz --strip-components 1 -C /app && \
bower cache clean && \
npm prune --production && \
mv node_modules /app && \
rm -rf ~/.node-gyp && \
mkdir /app/bundletool && \
mv /tmp/bundletool/* /app/bundletool && \
cd /app && \
find /tmp -mindepth 1 ! -regex '^/tmp/hsperfdata_root\(/.*\)?' -delete

# Switch to the app user.
USER stf
curl -sf https://gobinaries.com/tj/node-prune | sh

wget --progress=dot:mega \

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The wget command has to be prefixed by the RUN command, otherwise the build is failing at the beginning

https://github.com/google/bundletool/releases/download/1.2.0/bundletool-all-1.2.0.jar \
-O /tmp/bundletool.jar

# ********* FRONTEND **********

FROM with_packages as frontend

# Install bower dependencies
WORKDIR /tmp/build
COPY ./bower.json /tmp/build/
COPY ./.bowerrc /tmp/build/
RUN mkdir bower_modules && \
./node_modules/.bin/bower install

# Copy the app ( res ) in
COPY ./bower.json /tmp/build/
COPY ./gulpfile.js /tmp/build/
COPY ./webpack.config.js /tmp/build/
COPY ./res /tmp/build/res
COPY ./lib/util /tmp/build/lib/util

RUN ./node_modules/.bin/gulp build

# ********* BACKEND **********

FROM with_packages as backend

COPY ./lib /tmp/build/lib

# Package and cleanup
WORKDIR /tmp/build
RUN npm pack 2>&1 | grep -v "npm notice [1-9]" && \
mv devicefarmer-stf-$(jq .version package.json -j).tgz stf.tgz

#npm prune --production && \
# node-prune && \

FROM alpine as app

RUN mkdir -p /app
COPY --from=backend /tmp/build/stf.tgz /tmp/stf.tgz
RUN tar xf /tmp/stf.tgz --strip-components 1 -C /app

# ********* RUNTIME **********

FROM nodebase as runtime

EXPOSE 3000

# Setup user
RUN mkdir -p /app/res && mkdir -p /app/bundletool && chown stf:stf /app && chown stf:stf /app/*

WORKDIR /app

# Copy in node_modules and prune them
COPY --from=with_packages --chown=stf:stf /tmp/build/node_modules /app/node_modules
COPY --from=with_packages --chown=stf:stf /tmp/build/package.json /app/package.json
RUN npm prune --production

# Copy in resources needed by backend
COPY --chown=stf:stf ./res/common /app/res/common
COPY --chown=stf:stf ./res/app/views /app/res/app/views
COPY --chown=stf:stf ./res/auth/mock/views /app/res/auth/mock/views

# Copy in the backend
COPY --from=app --chown=stf:stf /app /app

# Copy in the frontend
COPY --from=frontend --chown=stf:stf /tmp/build/res/build /app/res/build

# Copy in bundletool
COPY --from=with_packages --chown=stf:stf /tmp/bundletool.jar /app/bundletool/bundletool.jar

COPY ./webpackserver.config.js /app/

#USER root
#RUN apt-get -y --no-install-recommends install ncdu

# Add stf executable dir into $PATH
ENV PATH /app/bin:$PATH

# Show help by default.
CMD stf --help
55 changes: 28 additions & 27 deletions bower.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,48 +2,49 @@
"name": "stf",
"version": "0.1.0",
"dependencies": {
"angular": "~1.5.0-rc.2",
"angular-cookies": "~1.5.0-rc.2",
"angular-route": "~1.5.0-rc.2",
"angular-sanitize": "~1.5.0-rc.2",
"angular-animate": "~1.5.0-rc.2",
"angular-touch": "~1.5.0-rc.2",
"lodash": "~3.10.1",
"oboe": "~2.1.2",
"ng-table": "~1.0.0-beta.9",
"angular-gettext": "~2.2.0",
"angular-ui-ace": "~0.2.3",
"angular-dialog-service": "~5.2.11",
"oboe": "2.1.2",
"ng-table": "~1.0.0",
"ng-file-upload": "~2.0.5",
"angular-growl-v2": "JanStevens/angular-growl-2#~0.7.9",
"underscore.string": "~3.2.3",
"bootstrap": "~3.3.6",
"font-lato-2-subset": "~0.4.0",
"packery": "~1.4.3",
"draggabilly": "~1.2.4",
"angular-elastic": "~2.5.1",
"angular-hotkeys": "chieffancypants/angular-hotkeys#~1.6.0",
"angular-borderlayout": "git://github.com/filearts/angular-borderlayout.git#7c9716aebd9260763f798561ca49d6fbfd4a5c67",
"angular-ui-bootstrap": "~1.1.1",
"ng-context-menu": "AdiDahan/ng-context-menu#~1.0.5",
"components-font-awesome": "~4.5.0",
"epoch": "~0.8.4",
"ng-epoch": "~1.0.7",
"eventEmitter": "~4.3.0",
"angular-ladda": "~0.3.1",
"d3": "~3.5.14",
"spin.js": "~2.3.2",
"angular-xeditable": "~0.1.9"

"angular": "~1.8.0",
"angular-cookies": "~1.8.0",
"angular-route": "~1.8.0",
"angular-sanitize": "~1.8.0",
"angular-animate": "~1.8.0",
"angular-touch": "~1.8.0",
"angular-ladda": "~0.4.3",
"spin.js": "~4.1.0",
"angular-xeditable": "~0.1.9",
"angular-elastic": "~2.5.1",
"angular-ui-bootstrap": "~1.1.1",
"angular-gettext": "~2.4.1",
"angular-ui-ace": "~0.2.3",
"angular-dialog-service": "~5.2.11",
"angular-growl-v2": "JanStevens/angular-growl-2#~0.7.9",
"angular-borderlayout": "https://github.com/nanoscopic/angular-borderlayout.git#0.9.2",
"angular-hotkeys": "https://github.com/nanoscopic/angular-hotkeys.git#2.0.29",
"mousetrap": "https://github.com/nanoscopic/mousetrap.git#1.7.19",

"epoch": "~0.8.4",
"ng-epoch": "~2.0.1"
},
"private": true,
"devDependencies": {
"angular-mocks": "~1.5.0-rc.2"
},
"resolutions": {
"angular": "~1.5.0-rc.2",
"d3": "~3.5.5",
"spin.js": "~2.3.2",
"eventEmitter": "~4.3.0",
"epoch": "~0.8.4"
"epoch": "~0.8.4",
"get-size": "~2.0.3",
"angular": "~1.8.0",
"oboe": "2.1.2"
}
}
Loading