Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding Docker Support #319

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Basic docker image for Monocle
# Usage:
# docker build -t Monocle
# docker run -d --name Monocle -P Monocle

FROM python:3.6
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

python:3.6-alpine3.6 could be worth trying to reduce the size

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did try to build it with alpine but was running into some missing requirements to install monocle packages so fell back on the full python:3.6

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what you mean with providing a config.py / accounts.csv. It doesn't need to be part of the image, you can easily have those files in a local folder and user docker run -v option in order to share those files between your local filesystem and docker container.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also try with :alpine, but I had a mistake with the pogeo requirement.

This is my current working docker file :

FROM python:3.6.0-slim

WORKDIR /usr/src/app

ENV DUMP_INIT_VERSION 1.2.0
ENV TERM=xterm

RUN buildDeps='build-essential ca-certificates curl' \
 && apt-get update \
 && DEBIAN_FRONTEND=noninteractive \ 
    apt-get install --no-install-recommends -y $buildDeps python3-cairo libmysqlclient-dev libgeos-dev supervisor \
 && curl -sLo /tmp/dumb-init.deb https://github.com/Yelp/dumb-init/releases/download/v"$DUMP_INIT_VERSION"/dumb-init_"$DUMP_INIT_VERSION"_amd64.deb \
 && dpkg -i /tmp/dumb-init.deb \
 && pip install --upgrade pip \
 && pip install --no-cache-dir pymysql

COPY requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r requirements.txt

COPY optional-requirements.txt /usr/src/app/
RUN pip install --no-cache-dir -r optional-requirements.txt

# Cleanup
RUN apt-get purge -y --auto-remove $buildDeps \
 && apt-get autoremove -y \
 && apt-get clean \
 && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

COPY . /usr/src/app/

EXPOSE 5000 6000
ENTRYPOINT ["/usr/bin/dumb-init"]
CMD ["/usr/bin/supervisord", "-c", "supervisord.conf"]

And my supervisord.conf :

[supervisord]
nodaemon=true

[program:scan]
command=python scan.py
startsecs=5
stdout_logfile=/dev/stdout
stdout_logfile_maxbytes=0
stderr_logfile=/dev/stderr
stderr_logfile_maxbytes=0

[program:web]
command=python web.py --host 0.0.0.0
startsecs=5

And my docker CMD :

docker run -d \
    --restart=always \
    --name pogomap \
    -p 6000:6000 \
    -v $path/accounts.csv:/usr/src/app/accounts.csv \
    -v $path/config.py:/usr/src/app/monocle/config.py \
    -v $path/landmarks.pickle:/usr/src/app/pickles/landmarks.pickle \
    -v $path/supervisord.conf:/usr/src/app/supervisord.conf \
    --link maria_db \
    registry.gitlab. . ./monocle:prod

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the accounts.pickle could be a thing, too
as if you don't have your phone IDs in the accounts.csv they would be generated everytime

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can add it in the description but I guess people using docker know they need to provide a persistent working directory on the local filesystem if they want anything persistent... so indeed I also pass a -v option with a working directory for pickles, logs, ... That's more something we would need to describe in a wiki than in the dockerfile itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there are a lot of people who know what docker is and may get it started, but acually have no idea of what they are doing ;)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If this gets committed, I'll update the wiki with some recommandations and examples on how to launch Monocle inside a docker container... guess they are other things to talk about (e.g. creating a docker network and run a db inside a docker with persistency on local filesystem) so better tackle all those stuff on the wiki for people who would like to start with Docker ;-)


# Working directory for the application
WORKDIR /usr/src/app

# Set Entrypoint with hard-coded options
ENTRYPOINT ["python3", "./scan.py"]

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to suggest to change to ENTRYPOINT ["python3"] and add CMD ["./scan.py"], so we could start a web instance only changing the command, not the whole entrypoint.


# Install required system packages
RUN apt-get update && apt-get install -y --no-install-recommends libgeos-dev

COPY requirements.txt /usr/src/app/

RUN pip3 install --no-cache-dir -r requirements.txt

# Copy everything to the working directory (Python files, templates, config) in one go.
COPY . /usr/src/app/