Skip to content
This repository has been archived by the owner on Jan 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #563 from mitodl/feature/optimize_dockerfile
Browse files Browse the repository at this point in the history
Optimized Dockerfile to reduce build times
  • Loading branch information
noisecapella committed Sep 1, 2015
2 parents c90fbcb + b683148 commit 6dd74d4
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 33 deletions.
80 changes: 79 additions & 1 deletion .dockerignore
@@ -1 +1,79 @@
.git/
__pycache__/
*.py[cod]

# C extensions
*.so

# Distribution / packaging
.Python
env/
build/
develop-eggs/
/dist/
downloads/
eggs/
lib/
lib64/
parts/
sdist/
var/
*.egg-info/
.installed.cfg
*.egg

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.cache
nosetests.xml
coverage.xml
coverage/
jstest_results.html

# Translations
*.mo
*.pot

# Django stuff:
*.log
db.sqlite

# Sphinx documentation
docs/_build/

# PyBuilder
target/

node_modules/

# Editor stuff
*.swp
*.orig

/nbproject
.idea/
.redcar/
codekit-config.json
.pycharm_helpers/

.project
.pydevproject

*.DS_Store

# Django static
staticfiles/

# Heroku/Foreman
.env
64 changes: 32 additions & 32 deletions Dockerfile
@@ -1,55 +1,55 @@
FROM ubuntu:trusty
MAINTAINER ODL DevOps <mitx-devops@mit.edu>


# Add package files
ADD requirements.txt /tmp/requirements.txt
ADD test_requirements.txt /tmp/test_requirements.txt
ADD doc_requirements.txt /tmp/doc_requirements.txt
ADD apt.txt /tmp/apt.txt
WORKDIR /tmp

# Install base packages
RUN apt-get update
RUN apt-get install -y $(grep -vE "^\s*#" apt.txt | tr "\n" " ")
RUN pip install pip --upgrade
COPY apt.txt /tmp/apt.txt
RUN apt-get update &&\
apt-get install -y $(grep -vE "^\s*#" apt.txt | tr "\n" " ") &&\
ln -s /usr/bin/nodejs /usr/bin/node &&\
pip install pip --upgrade

# Add non-root user.
RUN adduser --disabled-password --gecos "" mitodl

# Install project packages
RUN pip install -r requirements.txt
RUN pip install -r test_requirements.txt
RUN pip install -r doc_requirements.txt
RUN pip3 install -r requirements.txt
RUN pip3 install -r test_requirements.txt

# Add, and run as, non-root user.
RUN adduser --disabled-password --gecos "" mitodl
# Python 2
COPY requirements.txt /tmp/requirements.txt
COPY test_requirements.txt /tmp/test_requirements.txt
COPY doc_requirements.txt /tmp/doc_requirements.txt
RUN pip install -r requirements.txt &&\
pip install -r test_requirements.txt &&\
pip install -r doc_requirements.txt

# Python 3
RUN pip3 install -r requirements.txt &&\
pip3 install -r test_requirements.txt

# Install node development and production packages
RUN mkdir /node
COPY package.json /node/package.json
RUN cd /node &&\
npm install &&\
npm install --production

# Add project
ADD . /src
COPY . /src
WORKDIR /src
RUN chown -R mitodl:mitodl /src

# Link nodejs to node since npm expects node
RUN ln -s /usr/bin/nodejs /usr/bin/node

# Install development packages globally for things like
# bower.
RUN mkdir /node
ADD package.json /node/package.json
RUN cd /node && npm install
# Gather static
RUN ./manage.py collectstatic --noinput
RUN apt-get clean && apt-get purge
USER mitodl

# Install productions deps for runtime items like jsx
RUN npm install --production
# Setup node environment
ENV PATH /src/node_modules/.bin:/node/node_modules/.bin:$PATH

# Set pip cache folder, as it is breaking pip when it is on a shared volume
ENV XDG_CACHE_HOME /tmp/.cache

# Gather static
RUN ./manage.py collectstatic --noinput

USER mitodl

# Set and expose port for uwsgi config
EXPOSE 8070
ENV PORT 8070
Expand Down

0 comments on commit 6dd74d4

Please sign in to comment.