Skip to content
This repository has been archived by the owner on Feb 1, 2019. It is now read-only.

Commit

Permalink
Merge 909eb3b into c6bbd82
Browse files Browse the repository at this point in the history
  • Loading branch information
wpears committed Oct 6, 2015
2 parents c6bbd82 + 909eb3b commit 6dea735
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 66 deletions.
4 changes: 1 addition & 3 deletions .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ node_modules

docs

# ingore mongo-docker
mongo-docker

build-docker-containers.sh
run-docker-containers.sh
run-docker-containers.sh
16 changes: 8 additions & 8 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
FROM alpine:3.2
FROM mhart/alpine-node:0.10

# Add source and make sure we're working in that dir
ADD . /usr/local/node/hmda-edit-check-api
WORKDIR /usr/local/node/hmda-edit-check-api

# Set the environment
ENV NODE_VERSION=v0.12.5 NODE_ENV=production PORT=8000 NODE_TLS_REJECT_UNAUTHORIZED=0
ENV NODE_ENV=production PORT=8000 NODE_TLS_REJECT_UNAUTHORIZED=0

# Use a custom build script instead of messy chained together RUN
# or multiple RUN statements that add bloat to the image
# Install deps and app files
RUN ./docker-scripts/run.sh

# Tests. Yes, Virginia, you can test Docker builds
# Ensure proper build
RUN ./docker-scripts/tests.sh

EXPOSE ${PORT}
COPY ./docker-scripts/entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
CMD ["node", "server.js"]

USER notroot

CMD ["node", "server.js"]
45 changes: 9 additions & 36 deletions docker-scripts/run.sh
Original file line number Diff line number Diff line change
@@ -1,48 +1,21 @@
#!/bin/sh

##### add dependencies
apk --update add bash git curl make gcc g++ python linux-headers paxctl libgcc libstdc++
# We need shadow to create user/group for node, requires testing repo at this time
apk add shadow --update-cache --repository http://dl-3.alpinelinux.org/alpine/edge/testing/


##### add our nodejs user and group first to make sure their IDs get assigned consistently
groupadd -r nodejs -g 1000
useradd -u 1000 -r -g 1000 -d /usr/local/node nodejs
chown -R nodejs:nodejs /usr/local/node

##### install gosu for easy step-down from root
echo -n "--- installing gosu... "
curl -o /usr/local/bin/gosu -sSL https://github.com/tianon/gosu/releases/download/1.4/gosu-amd64
chmod +x /usr/local/bin/gosu
echo "done"

##### Compile and install nodejs
CONFIG_FLAGS="--prefix=/usr"
CMD=node
DOMAIN=nodejs.org

cd /tmp
curl -sSL https://${DOMAIN}/dist/${NODE_VERSION}/${CMD}-${NODE_VERSION}.tar.gz | tar -xz && \
cd /tmp/${CMD}-${NODE_VERSION} && \
./configure ${CONFIG_FLAGS} && \
make -j$(grep -c ^processor /proc/cpuinfo 2>/dev/null || 1) && \
make install && \
paxctl -cm /usr/bin/${CMD} && \
cd / && \
if [ -x /usr/bin/npm ]; then \
npm install -g npm && \
find /usr/lib/node_modules/npm -name test -o -name .bin -type d | xargs rm -rf; \
fi && \
apk --update add git make g++ python

##### do npm install on the app so it has all the proper modules
cd /usr/local/node/hmda-edit-check-api
gosu nodejs npm cache clean && npm install
npm cache clean && npm install

##### add a non-root user
adduser -S notroot
chown -R notroot .


##### clean up
apk del git curl make gcc g++ python linux-headers paxctl
apk del git make gcc g++ python
rm -rf /etc/ssl /usr/include /usr/share/man /tmp/* \
/usr/include /root/.npm /root/.node-gyp \
/usr/local/node/.npm /usr/local/node/.node-gyp \
/usr/lib/node_modules/npm/man /usr/lib/node_modules/npm/doc \
/usr/lib/node_modules/npm/html /var/cache/apk/*
/usr/lib/node_modules/npm/html /var/cache/apk/*
9 changes: 2 additions & 7 deletions docker-scripts/tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,7 @@

echo --- TESTS ---

echo -n "it should install gosu 1.4... "
gosu 2>&1 | grep "version: 1.4" > /dev/null
echo -n "it should install nodejs 0.10.x"
node --version 2>&1 | grep "0.10" > /dev/null
[ "$?" -ne 0 ] && echo fail && exit 1
echo pass

echo -n "it should install nodejs 0.12.5... "
node --version 2>&1 | grep "0.12.5" > /dev/null
[ "$?" -ne 0 ] && echo fail && exit 1
echo pass
24 changes: 12 additions & 12 deletions mongo-docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# Based roughly around official MongoDB docker image
# https://github.com/docker-library/mongo/blob/master/2.6/Dockerfile
FROM alpine:3.2
FROM mhart/alpine-node:0.10

# Use a custom build script instead of messy chained together RUN
# or multiple RUN statements that add bloat to the image
ADD run.sh /tmp/run.sh
ENV NODE_ENV=production

COPY mongo-docker /tmp

# Build
RUN /tmp/run.sh && rm /tmp/run.sh

# Tests. Yes, Virginia, you can test Docker builds
ADD tests.sh /tmp/tests.sh
# Tests
RUN /tmp/tests.sh && rm /tmp/tests.sh

VOLUME /data/db
COPY entrypoint.sh /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
# Install app
COPY . /usr/local/app
RUN /tmp/install-app.sh && rm /tmp/install-app.sh

EXPOSE 27017
CMD ["mongod"]
CMD ["/tmp/start.sh"]
11 changes: 11 additions & 0 deletions mongo-docker/install-app.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/sh

apk --update add make g++ python git

# Install app deps
cd /usr/local/app
npm install

# Clean
apk del make g++ git python
rm -rf /var/cache/apk/*
3 changes: 3 additions & 0 deletions mongo-docker/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ chown -R root:root /tmp/mongodb-linux-x86_64-$MONGO_VERSION
mv /tmp/mongodb-linux-x86_64-$MONGO_VERSION/bin/* /usr/local/bin
echo "done"

##### create app area for data loading
mkdir -p /usr/local/app

##### Clean up after ourselves
# We don't need wget any longer
apk del wget
Expand Down
9 changes: 9 additions & 0 deletions mongo-docker/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/bin/bash

# Start mongo
/tmp/entrypoint.sh mongod&

sleep 5

# Load data
node /usr/local/app/data/reload_mongo.js

0 comments on commit 6dea735

Please sign in to comment.