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

Commit

Permalink
Docker: Reuse Caches (Closes: #159)
Browse files Browse the repository at this point in the history
* Docker containers that need pip inherit from a common base image to reuse caches 

* Default to Python 3.6 and install make

* Bump psycopg2 to fix Travis error
  • Loading branch information
WGierke authored and lamby committed Nov 3, 2017
1 parent 03a6250 commit 9c58823
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 38 deletions.
30 changes: 30 additions & 0 deletions compose/base/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ubuntu:rolling
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y tcl tk python3.6 python3.6-tk wget python-opencv
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3.6 get-pip.py

# Default to Python 3.6
RUN rm /usr/bin/python
RUN ln -s /usr/bin/python3.6 /usr/bin/python

# Interface
COPY ./interface/requirements /requirements/interface
RUN pip install -U pip
RUN pip install -r /requirements/interface/local.txt

# Prediction
COPY ./prediction/.pylidcrc /root/.pylidcrc
COPY ./prediction/requirements/torch.txt /requirements/prediction/torch.txt
RUN pip install -r /requirements/prediction/torch.txt
COPY ./prediction/requirements/local.txt /requirements/prediction/local.txt
RUN pip install -r /requirements/prediction/local.txt
COPY ./prediction/requirements/base.txt /requirements/prediction/base.txt
RUN pip install -r /requirements/prediction/base.txt

# Documentation
COPY ./docs/requirements.txt /requirements/requirements.txt
RUN pip install -r /requirements/requirements.txt


WORKDIR /app
18 changes: 2 additions & 16 deletions compose/documentation/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,19 +1,5 @@
FROM python:3.6
ENV PYTHONUNBUFFERED 1
FROM concepttoclinic_base

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./prediction/requirements/torch.txt /requirements/prediction/torch.txt
RUN pip install -r /requirements/prediction/torch.txt
COPY ./prediction/requirements/local.txt /requirements/prediction/local.txt
RUN pip install -r /requirements/prediction/local.txt
COPY ./prediction/requirements/base.txt /requirements/prediction/base.txt
RUN pip install -r /requirements/prediction/base.txt

COPY ./interface/requirements /requirements/interface
RUN pip install -r /requirements/interface/local.txt

# Documentation
COPY ./docs/requirements.txt /requirements/requirements.txt
RUN pip install -r /requirements/requirements.txt
RUN apt-get install make

WORKDIR /app
8 changes: 1 addition & 7 deletions compose/interface/Dockerfile-dev-api
Original file line number Diff line number Diff line change
@@ -1,10 +1,4 @@
FROM python:3.6
ENV PYTHONUNBUFFERED 1

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./interface/requirements /requirements/interface
RUN pip install -U pip
RUN pip install -r /requirements/interface/local.txt
FROM concepttoclinic_base

# Copy the scripts into the container
COPY ./compose/interface/entrypoint.sh /entrypoint.sh
Expand Down
15 changes: 1 addition & 14 deletions compose/prediction/Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -1,16 +1,3 @@
FROM ubuntu:rolling
ENV PYTHONUNBUFFERED 1
RUN apt-get update && apt-get install -y tcl tk python3.6 python3.6-tk wget python-opencv
RUN wget https://bootstrap.pypa.io/get-pip.py
RUN python3.6 get-pip.py

# Requirements have to be pulled and installed here, otherwise caching won't work
COPY ./prediction/.pylidcrc /root/.pylidcrc
COPY ./prediction/requirements/torch.txt /requirements/prediction/torch.txt
RUN pip install -r /requirements/prediction/torch.txt
COPY ./prediction/requirements/local.txt /requirements/prediction/local.txt
RUN pip install -r /requirements/prediction/local.txt
COPY ./prediction/requirements/base.txt /requirements/prediction/base.txt
RUN pip install -r /requirements/prediction/base.txt
FROM concepttoclinic_base

WORKDIR /app
2 changes: 1 addition & 1 deletion interface/requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Django==1.11.3
djangorestframework==3.6.3

# Database
psycopg2==2.7.1
psycopg2==2.7.3.1

# Config
django-dotenv==1.4.1
Expand Down
10 changes: 10 additions & 0 deletions local.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,20 @@ services:
environment:
- POSTGRES_USER=concepttoclinic

base:
build:
context: .
dockerfile: ./compose/base/Dockerfile-dev
container_name: base

interface:
build:
context: .
dockerfile: ./compose/interface/Dockerfile-dev-api
command: /start-dev.sh
depends_on:
- postgres
- base
- prediction
environment:
- POSTGRES_USER=concepttoclinic
Expand Down Expand Up @@ -58,6 +65,8 @@ services:
context: .
dockerfile: ./compose/prediction/Dockerfile-dev
command: flask run --host=0.0.0.0 --port=8001
depends_on:
- base
environment:
- FLASK_DEBUG=1
- FLASK_APP=src/factory.py
Expand All @@ -77,6 +86,7 @@ services:
restart: always
depends_on:
- postgres
- base
environment:
- POSTGRES_USER=concepttoclinic
- USE_DOCKER=yes
Expand Down

0 comments on commit 9c58823

Please sign in to comment.