FROM mhart/alpine-node:4.3.2

MAINTAINER Cristobal Gomez <me@cristobal.io>

RUN apk add --no-cache make bash git python alpine-sdk g++

RUN mkdir -p /app
WORKDIR /app

ENV HOME /app
ENV APP_HOST 0.0.0.0

ENV PG_USER aviator
ENV PG_DATABASE aviation
ENV PG_PASSWORD ""
ENV PG_HOST db
ENV AVIATION_CORS_ORIGIN=http://localhost:8081
ENV AVIATION_GEO_IP_SERVICE=http://geoip:8080/json/

COPY . /app

# Runs the tests, cleans up, removes npm devDependencies and test
# folder
RUN npm install --production && \
  rm -rf /app/test && \
  npm prune --production && \
  npm cache clean && \
  rm -rf /app/spikes

RUN apk del abuild acct alpine-sdk attr bash binutils binutils-libs \
build-base bzip2 ca-certificates cdrkit cryptsetup-libs curl \
device-mapper expat fakeroot file fortify-headers g++ gcc gdbm git \
gmp isl kmod lddtree libatomic libattr libblkid libbz2 libc-dev libcap \
libffi libgomp libssh2 libuuid lzo make mkinitfs mpc1 mpfr3 mtools \
musl-dev ncurses-libs ncurses-terminfo ncurses-terminfo-base openssl \
patch pax-utils pcre pkgconf pkgconfig python readline sqlite-libs \
squashfs-tools sudo tar xz-libs

RUN chown -R nobody:nobody /app/ && \
  chmod 766 -R /app/

USER nobody

EXPOSE 8081

ENTRYPOINT ["npm"]

CMD ["start"]
