2014-09-15 22:20:30 +08:00
|
|
|
FROM ubuntu:14.04
|
2014-09-15 16:41:48 +08:00
|
|
|
MAINTAINER "Konrad Kleine"
|
|
|
|
|
2014-09-15 22:20:30 +08:00
|
|
|
ENV NGX_ROOT /usr/share/nginx/html
|
2014-09-17 20:51:34 +08:00
|
|
|
ENV SOURCE_DIR /tmp/source
|
2014-09-17 23:39:47 +08:00
|
|
|
ENV START_SCRIPT /root/start-nginx.sh
|
2014-09-17 20:51:34 +08:00
|
|
|
|
2014-09-18 16:53:21 +08:00
|
|
|
############################################################
|
|
|
|
# This adds everything we need to the build root except those
|
|
|
|
# element that are matched by .dockerignore.
|
|
|
|
# We explicitly list every directory and file that is involved
|
|
|
|
# in the build process but. All config files (like nginx) are
|
|
|
|
# not listed to speed up the build process.
|
|
|
|
############################################################
|
|
|
|
|
|
|
|
# Create dirs
|
|
|
|
RUN mkdir -p $SOURCE_DIR/dist
|
|
|
|
RUN mkdir -p $SOURCE_DIR/app
|
|
|
|
RUN mkdir -p $SOURCE_DIR/test
|
|
|
|
|
|
|
|
# Add dirs
|
|
|
|
ADD app $SOURCE_DIR/app
|
|
|
|
ADD test $SOURCE_DIR/test
|
|
|
|
|
|
|
|
# Dot files
|
|
|
|
ADD .jshintrc $SOURCE_DIR/
|
|
|
|
ADD .bowerrc $SOURCE_DIR/
|
|
|
|
ADD .editorconfig $SOURCE_DIR/
|
|
|
|
ADD .travis.yml $SOURCE_DIR/
|
|
|
|
|
|
|
|
# Other files
|
|
|
|
ADD bower.json $SOURCE_DIR/
|
|
|
|
ADD Gruntfile.js $SOURCE_DIR/
|
|
|
|
ADD LICENSE $SOURCE_DIR/
|
|
|
|
ADD package.json $SOURCE_DIR/
|
|
|
|
ADD README.md $SOURCE_DIR/
|
|
|
|
|
|
|
|
############################################################
|
|
|
|
# This is written so compact, to reduce the size of the
|
|
|
|
# final container and its layers. We have to install build
|
|
|
|
# dependencies, build the app, deploy the app to the web
|
|
|
|
# root, remove the source code, and then uninstall the build
|
|
|
|
# dependencies. When packed into one RUN instruction, the
|
|
|
|
# resulting layer will hopefully only be comprised of the
|
2014-09-17 23:39:47 +08:00
|
|
|
# installed app artifacts.
|
2014-09-18 16:53:21 +08:00
|
|
|
############################################################
|
|
|
|
|
2014-09-22 18:00:29 +08:00
|
|
|
RUN apt-get -y update
|
|
|
|
RUN apt-get -y install \
|
|
|
|
git \
|
|
|
|
nodejs \
|
|
|
|
nodejs-legacy \
|
|
|
|
npm nginx \
|
|
|
|
gettext-base && \
|
2014-09-17 23:39:47 +08:00
|
|
|
cd $SOURCE_DIR && \
|
|
|
|
npm install -g yo && \
|
|
|
|
npm install && \
|
|
|
|
bower install --allow-root && \
|
|
|
|
grunt build --allow-root && \
|
|
|
|
cp -rf $SOURCE_DIR/dist/* $NGX_ROOT && \
|
2014-09-22 18:00:29 +08:00
|
|
|
npm uninstall yo && \
|
2014-09-18 20:08:44 +08:00
|
|
|
rm -rf $SOURCE_DIR && \
|
|
|
|
apt-get -y --auto-remove purge git nodejs nodejs-legacy npm && \
|
|
|
|
apt-get -y clean
|
2014-09-17 23:39:47 +08:00
|
|
|
|
|
|
|
# Add nginx config files for HTTP and HTTPS
|
2014-09-17 20:51:34 +08:00
|
|
|
ADD nginx-site.conf /root/nginx-site.conf
|
2014-09-17 22:59:58 +08:00
|
|
|
ADD nginx-site-ssl.conf /root/nginx-site-ssl.conf
|
|
|
|
|
2014-09-17 23:39:47 +08:00
|
|
|
# Final touches on the app artifacts.
|
|
|
|
RUN find $NGX_ROOT -type d -exec chmod 755 {} \; && \
|
|
|
|
find $NGX_ROOT -type f -exec chmod 755 {} \; && \
|
|
|
|
chown -R www-data:www-data $NGX_ROOT && \
|
|
|
|
echo "\ndaemon off;" >> /etc/nginx/nginx.conf
|
|
|
|
|
|
|
|
# Build the start script
|
|
|
|
RUN echo "#!/bin/sh" > $START_SCRIPT && \
|
|
|
|
echo "rm -f /etc/nginx/sites-enabled/*" >> $START_SCRIPT && \
|
|
|
|
echo "cat /root/nginx-site.conf | DOCKER_REGISTRY_URL=\$DOCKER_REGISTRY_URL envsubst '\$DOCKER_REGISTRY_URL' > /etc/nginx/sites-available/registry" >> $START_SCRIPT && \
|
|
|
|
echo "if [ -n \"\$ENABLE_SSL\" ]; then" >> $START_SCRIPT && \
|
|
|
|
echo " cat /root/nginx-site-ssl.conf | DOCKER_REGISTRY_URL=\$DOCKER_REGISTRY_URL envsubst '\$DOCKER_REGISTRY_URL' > /etc/nginx/conf.d/registry-ssl" >> $START_SCRIPT && \
|
|
|
|
echo "fi" >> $START_SCRIPT && \
|
|
|
|
echo "ln -sf /etc/nginx/sites-available/registry /etc/nginx/sites-enabled/registry && \\" >> $START_SCRIPT && \
|
|
|
|
echo "nginx -t && nginx" >> $START_SCRIPT && \
|
|
|
|
chmod +x /root/start-nginx.sh
|
|
|
|
|
|
|
|
# Exposed ports
|
|
|
|
EXPOSE 80 443
|
2014-09-15 22:20:30 +08:00
|
|
|
|
2014-09-17 22:59:58 +08:00
|
|
|
# If you wish to run the registry container with SSL,
|
|
|
|
# you can provide your own SSL server key and your
|
|
|
|
# SSL server certificate.
|
|
|
|
VOLUME ["/etc/nginx/ssl/server.crt", "/etc/nginx/ssl/server.key"]
|
|
|
|
|
2014-09-15 22:20:30 +08:00
|
|
|
# Define default command.
|
2014-09-17 20:51:34 +08:00
|
|
|
CMD ["/root/start-nginx.sh"]
|