content: FROM debian:stable
  MAINTAINER Jeremy Shimko <jeremy.shimko@gmail.com>
  ARG DEBIAN_FRONTEND=noninteractive
  
  RUN groupadd -r node && useradd -m -g node node
  
  ENV DEV_BUILD true
  
  # Gosu
  ENV GOSU_VERSION 1.10
  
  # MongoDB
  ENV MONGO_VERSION 3.4.10
  ENV MONGO_MAJOR 3.4
  ENV MONGO_PACKAGE mongodb-org
  
  # PhantomJS
  ENV PHANTOM_VERSION 2.1.1
  
  # build directories
  ENV APP_SOURCE_DIR /opt/meteor/src
  ENV APP_BUNDLE_DIR /opt/meteor/dist
  ENV BUILD_SCRIPTS_DIR /opt/build_scripts
  
  # Add entrypoint and build scripts
  COPY scripts $BUILD_SCRIPTS_DIR
  RUN chmod -R 750 $BUILD_SCRIPTS_DIR
  
  # install base dependencies, build app, cleanup
  RUN bash $BUILD_SCRIPTS_DIR/install-deps.sh && \
  		bash $BUILD_SCRIPTS_DIR/post-install-cleanup.sh
  
  # define all --build-arg options
  ONBUILD ARG APT_GET_INSTALL
  ONBUILD ENV APT_GET_INSTALL $APT_GET_INSTALL
  
  ONBUILD ARG NODE_VERSION
  ONBUILD ENV NODE_VERSION ${NODE_VERSION:-14.17.4}
  
  ONBUILD ARG INSTALL_MONGO
  ONBUILD ENV INSTALL_MONGO ${INSTALL_MONGO:-true}
  
  ONBUILD ARG INSTALL_PHANTOMJS
  ONBUILD ENV INSTALL_PHANTOMJS ${INSTALL_PHANTOMJS:-true}
  
  ONBUILD ARG INSTALL_GRAPHICSMAGICK
  ONBUILD ENV INSTALL_GRAPHICSMAGICK ${INSTALL_GRAPHICSMAGICK:-true}
  
  # optionally custom apt dependencies at app build time
  ONBUILD RUN if [ "$APT_GET_INSTALL" ]; then apt-get update && apt-get install -y $APT_GET_INSTALL; fi
  
  # optionally install Mongo or Phantom at app build time
  ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-phantom.sh
  ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-mongo.sh
  ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-graphicsmagick.sh
  
  # Node flags for the Meteor build tool
  ONBUILD ARG TOOL_NODE_FLAGS
  ONBUILD ENV TOOL_NODE_FLAGS $TOOL_NODE_FLAGS
  
  ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-node.sh
  ONBUILD RUN bash $BUILD_SCRIPTS_DIR/install-meteor.sh
  ONBUILD COPY . $APP_SOURCE_DIR
  ONBUILD RUN bash $BUILD_SCRIPTS_DIR/build-meteor.sh
  
  # Default values for Meteor environment variables
  ENV ROOT_URL http://localhost
  ENV MONGO_URL mongodb://127.0.0.1:27017/meteor
  ENV PORT 3000
  
  EXPOSE 3000
  
  WORKDIR $APP_BUNDLE_DIR/bundle
  
  # start the app
  ENTRYPOINT ["./entrypoint.sh"]
  CMD ["node", "main.js"]
  