Skip to content

Instantly share code, notes, and snippets.

@larryboymi
Created September 15, 2017 13:32
Show Gist options
  • Save larryboymi/98ec207a67a820e10db66ca3da23f416 to your computer and use it in GitHub Desktop.
Save larryboymi/98ec207a67a820e10db66ca3da23f416 to your computer and use it in GitHub Desktop.
Dockerfile and startup script for opencpu/nodejs container
FROM node:8.4-slim
# Mod repo list
RUN echo "deb http://deb.debian.org/debian jessie-backports main" >> /etc/apt/sources.list && \
echo "deb-src http://ppa.launchpad.net/opencpu/opencpu-2.0/ubuntu xenial main" > /etc/apt/sources.list.d/opencpu.list && \
echo "deb-src http://httpredir.debian.org/debian/ jessie main contrib non-free" >> /etc/apt/sources.list && \
echo "deb-src http://httpredir.debian.org/debian/ jessie-updates main contrib" >> /etc/apt/sources.list non-free && \
echo "deb-src http://httpredir.debian.org/debian/ jessie-proposed-updates contrib main non-free" >> /etc/apt/sources.list && \
echo "deb-src http://httpredir.debian.org/debian/ jessie-backports main contrib non-free" >> /etc/apt/sources.list && \
echo "deb http://deb.debian.org/debian stretch main" >> /etc/apt/sources.list && \
echo "deb http://deb.debian.org/debian stretch-updates main" >> /etc/apt/sources.list && \
echo "deb http://security.debian.org stretch/updates main" >> /etc/apt/sources.list && \
echo "deb-src http://security.debian.org/ jessie/updates main contrib non-free" >> /etc/apt/sources.list && \
apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 4E8D912328F1D0FA8E4BF3BD5D0F7D9B7B3E569E && \
apt-get update && \
apt-get -y dist-upgrade
# Get dependencies from jessie repo
RUN apt-get -t jessie-backports install -y r-recommended r-base r-base-core r-base-dev && \
apt-get install -y software-properties-common devscripts build-essential \
r-cran-codetools libicu-dev libprotobuf-dev protobuf-compiler apache2 \
apache2-dev libapache2-mod-r-base ssl-cert locales \
libapparmor-dev libcurl4-openssl-dev libssl-dev libxml2-dev libssh2-1-dev \
xvfb xauth xfonts-base pkg-config && \
apt-get source --build opencpu && \
dpkg -i opencpu-lib_2.0.4-xenial0_amd64.deb opencpu-server_2.0.4-xenial0_all.deb
# Cleanup
RUN apt-get autoremove -y && \
rm -rf opencpu*
COPY startup.sh /startup.sh
# WORKDIR of child Dockerfile needs to be wherever node source is located
CMD /startup.sh
#!/bin/bash
#start apache for opencpu
apachectl -k start
#start node app, WORKDIR of child Dockerfile needs to be wherever node source is located
npm start &
# Naive check runs checks once a minute to see if either of the processes exited.
# This illustrates part of the heavy lifting you need to do if you want to run
# more than one service in a container. The container will exit with an error
# if it detects that either of the processes has exited.
# Otherwise it will loop forever, waking up every 60 seconds
while /bin/true; do
ps aux |grep apache2 |grep -q -v grep
PROCESS_1_STATUS=$?
ps aux |grep npm |grep -q -v grep
PROCESS_2_STATUS=$?
# If the greps above find anything, they will exit with 0 status
# If they are not both 0, then something is wrong
if [ $PROCESS_1_STATUS -ne 0 ]; then
echo "The apache process has exited."
exit -1
fi
if [ $PROCESS_2_STATUS -ne 0 ]; then
echo "The node process has exited."
exit -1
fi
sleep 60
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment