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

Issue278 dockerize annif #279

Merged
merged 66 commits into from
Jun 26, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
66 commits
Select commit Hold shift + click to select a range
abeff82
Initial working Dockerfile
May 16, 2019
2d9dbcd
Don't send docs to build context
May 16, 2019
def4d0a
Avoid rebuilding on changes of Dockerfile
May 16, 2019
7e83a0b
Use slimmer base image, make Vowpal Wabbit work, clean up
juhoinkinen May 21, 2019
4a9fda7
Ignore pycache and all versions of Dockerfile
juhoinkinen May 21, 2019
52f1065
Initial Dockerfile for Annif without any optional dependencies
juhoinkinen May 21, 2019
c0f75c7
Initial Dockerfile for optional dependencies for Annif
juhoinkinen May 21, 2019
1836132
Initial Dockerfile based on python-alpine image
juhoinkinen May 21, 2019
675f428
Clear /var/lib/apt/lists/ filled by apt-update (1.19GB->1.18GB)
juhoinkinen May 22, 2019
a96d61f
Restructure to avoid rebuilding dep layers on code change
juhoinkinen May 22, 2019
e28ff40
Drop dev packages (annif: 1.18GB->1.17GB, annif-slim: 653MB->645MB)
juhoinkinen May 22, 2019
7c9ee05
Split context copying to avoid rebuilding pipenv layer on code change
juhoinkinen May 22, 2019
eac347b
Will not be using alpine base image; python-slim is small enough
juhoinkinen May 22, 2019
5b50127
Reduce image size by clearing pipenv cache
juhoinkinen May 22, 2019
1a89e3c
Reduce image size by removing python2 (installed by libboost-python-dev)
juhoinkinen May 22, 2019
e8e74f1
Reduce image size by removing unnecessary dev packages with dpgk
juhoinkinen May 24, 2019
712d2a0
Remove dpgk deletions, because they break apt-get
juhoinkinen May 24, 2019
280d7ef
Reduce image size by not updating pip
juhoinkinen May 24, 2019
4714804
Unite layers for opt. dependencies installation
juhoinkinen May 24, 2019
fd18146
Add maintainer entry
juhoinkinen May 24, 2019
812c3c6
Handle occasional timeout in nltk.downloader with 3 tries
juhoinkinen May 24, 2019
bfb1ec7
Dockerfile including dev packages and tests (and whole Annif root)
juhoinkinen May 24, 2019
4c3325e
Delete unnecessary files; continue using Dockerfile and Dockerfile-dev
juhoinkinen May 24, 2019
4a615b8
Spaces to tabs
juhoinkinen May 24, 2019
f86bdd9
Also projects.cfg is needed to run Annif
juhoinkinen May 24, 2019
73d59b3
NLTK data need to be accessible to non-root
juhoinkinen May 27, 2019
a1ea737
Ease usage: start from path to be mounted & make projects.cfg available
juhoinkinen May 27, 2019
fcc15eb
Use projects.cfg from current dir
juhoinkinen May 28, 2019
6881e26
Do not use Pipfile.lock
juhoinkinen May 28, 2019
39cdcd5
Skip Pipenv lockfile
juhoinkinen May 28, 2019
8ca769a
Switch user to non-root
juhoinkinen May 28, 2019
13feaec
Give everyone full access to /Annif
juhoinkinen May 28, 2019
9ef2f1d
Switch user to non-root, skip Pipenv lockfile, give access to tests
juhoinkinen May 28, 2019
791e741
Initial infra for docker-compose to use nginx and gunicorn
juhoinkinen May 31, 2019
7a3550f
Use a more proper name for the upstream context
juhoinkinen Jun 3, 2019
3bc89d8
Add gunicorn to main Docker image; no point using Dockerfile-server
juhoinkinen Jun 4, 2019
75e4c27
Use plain nginx image from Docker Hub and mount the config file
juhoinkinen Jun 4, 2019
c7a564a
Clarify container names
juhoinkinen Jun 4, 2019
95c5b5f
Use env to set path to annif data; set user to current user
juhoinkinen Jun 4, 2019
a7f9c58
Remove unnecessary Dockerfile for NGINX
juhoinkinen Jun 4, 2019
68ee283
Use multistage build; install only run-time deps (730MB -> 652MB)
juhoinkinen Jun 5, 2019
d5721f1
Underscore to dash
juhoinkinen Jun 11, 2019
39ebe17
Install curl, needed for testing mauiservice
juhoinkinen Jun 11, 2019
d33ec18
Attempt to trigger build in drone.io; initial drone.yml
juhoinkinen Jun 12, 2019
bc1a8ee
Reattempt; do not use auto tag
juhoinkinen Jun 12, 2019
d313a3f
Revoke everyone full access to /Annif
juhoinkinen Jun 12, 2019
6dd319e
Initial compose-file to create a stack in Portainer
juhoinkinen Jun 14, 2019
1895f0e
Initial Dockerfile for transfering data to Portainer volume
juhoinkinen Jun 14, 2019
2400f02
Switch UID to 998 as 999 clashes in Alpine data image
juhoinkinen Jun 14, 2019
56ff716
Restart data image only on failure (to copy data)
juhoinkinen Jun 14, 2019
3e9b950
Reduce image size by switching to busybox base
juhoinkinen Jun 14, 2019
e902020
Use nginx.conf for Portainer via data image
juhoinkinen Jun 17, 2019
c6a2109
Do not publish ports in Portainer to avoid clashes
juhoinkinen Jun 17, 2019
8763fe8
Directly mount contents of annif-projects to volume instead copying
juhoinkinen Jun 18, 2019
066e861
Rename volume (to avoid eventual nogood name "annif_annif-data")
juhoinkinen Jun 18, 2019
5ff3446
Trigger to push also dev image to quay
juhoinkinen Jun 20, 2019
46c2a54
Make own pipeline for dev image deployment
juhoinkinen Jun 20, 2019
47901ab
Fix intendation
juhoinkinen Jun 20, 2019
72acbb4
Use image from quay
juhoinkinen Jun 20, 2019
eaf5c66
Use Python 3.7 instead of 3.6 (hoping to solve scanner issues in quay)
juhoinkinen Jun 20, 2019
8b982ef
Attempt to run both pipelines by separating them with dashes
juhoinkinen Jun 20, 2019
9e43279
One pipeline, two steps: first build&push annif, only then annif-dev
juhoinkinen Jun 20, 2019
7943968
Unified docker-compose.yml (NGINX and mauiservice)
juhoinkinen Jun 20, 2019
31a8e21
Add build trigger to listen also master
juhoinkinen Jun 26, 2019
65628cf
Add Traefik network settings
juhoinkinen Jun 26, 2019
61f7345
Remove build trigger from "dockerize-annif" branch
juhoinkinen Jun 26, 2019
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
**/__pycache__
**/*.pyc
31 changes: 31 additions & 0 deletions .drone.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
kind: pipeline
name: default
steps:

- name: docker
image: plugins/docker
settings:
dockerfile: Dockerfile
username:
from_secret: docker_username
password:
from_secret: docker_password
registry: quay.io
repo: quay.io/natlibfi/annif
tags: [latest]

- name: docker-dev
image: plugins/docker
settings:
dockerfile: Dockerfile-dev
username:
from_secret: docker_username
password:
from_secret: docker_password
registry: quay.io
repo: quay.io/natlibfi/annif
tags: [dev]

when:
event: push
branch: [master]
78 changes: 78 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
FROM python:3.7-slim AS builder

LABEL maintainer="Juho Inkinen <juho.inkinen@helsinki.fi>"

## Install optional dependencies:
RUN apt-get update \
## Voikko:
&& apt-get install -y --no-install-recommends \
libvoikko1 \
voikko-fi \
&& pip install --no-cache-dir \
annif[voikko] \
## fasttext:
&& apt-get install -y --no-install-recommends \
build-essential \
&& pip install --no-cache-dir \
cython \
fasttextmirror \
## Vowpal Wabbit. Using old VW because 8.5 links to wrong Python version
&& apt-get install -y --no-install-recommends \
libboost-program-options-dev \
zlib1g-dev \
libboost-python-dev \
&& pip install --no-cache-dir \
vowpalwabbit==8.4



FROM python:3.7-slim

COPY --from=builder /usr/local/lib/python3.7 /usr/local/lib/python3.7

## Dependencies needed at runtime:
RUN apt-get update \
## Voikko:
&& apt-get install -y --no-install-recommends \
libvoikko1 \
voikko-fi \
&& pip install --no-cache-dir \
annif[voikko] \
## Vowpal Wabbit. Using old VW because 8.5 links to wrong Python version
&& apt-get install -y --no-install-recommends \
libboost-program-options1.62.0 \
libboost-python1.62.0 \
&& pip install --no-cache-dir \
vowpalwabbit==8.4 \
## Clean up:
&& rm -rf /var/lib/apt/lists/* /usr/include/* \
&& rm -rf /root/.cache/pip*/*


## Install Annif:
# Files needed by pipenv install:
COPY Pipfile README.md setup.py /Annif/
WORKDIR /Annif

# Handle occasional timeout in nltk.downloader with 3 tries
RUN pip install pipenv --no-cache-dir \
&& pipenv install --system --skip-lock \
&& for i in 1 2 3; do python -m nltk.downloader punkt -d /usr/share/nltk_data && break || sleep 1; done \
&& pip uninstall -y pipenv \
&& rm -rf /root/.cache/pip*/*


COPY annif annif
COPY projects.cfg.dist projects.cfg.dist

WORKDIR /annif-projects


# Switch user to non-root:
RUN groupadd -g 998 annif_user \
&& useradd -r -u 998 -g annif_user annif_user \
&& chown -R annif_user:annif_user /annif-projects
USER annif_user


CMD annif
12 changes: 12 additions & 0 deletions Dockerfile-data
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
FROM busybox

COPY data /annif-projects/data
COPY projects.cfg nginx.conf /annif-projects/

# Switch user to non-root:
RUN addgroup -g 998 annif_user \
&& adduser -S -u 998 -g annif_user annif_user \
&& chown -R annif_user:annif_user /annif-projects
USER annif_user

CMD sh
19 changes: 19 additions & 0 deletions Dockerfile-dev
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM quay.io/natlibfi/annif

WORKDIR /Annif

USER root

RUN apt-get update \
&& apt-get install -y --no-install-recommends \
curl

RUN pip install pipenv --no-cache-dir \
&& pipenv install --system --skip-lock --dev

COPY . .
RUN chmod -R 777 /Annif

USER annif_user

CMD annif
1 change: 1 addition & 0 deletions Pipfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ nltk = "*"
gensim = "*"
sklearn = "*"
rdflib = "*"
gunicorn = "*"

[requires]
12 changes: 12 additions & 0 deletions annif/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
upstream upstream_servers {
server gunicorn_server:8000;
}

server {
listen 80;
server_name localhost;

location / {
proxy_pass http://upstream_servers;
}
}
56 changes: 56 additions & 0 deletions docker-compose-portainer.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
version: "3"

services:

gunicorn_server:
restart: always
image: quay.io/natlibfi/annif
command: ["gunicorn", "annif:create_app()", "--bind", "0.0.0.0:8000"]
volumes:
- data:/annif-projects
depends_on:
- data

nginx:
restart: always
image: nginx
volumes:
- data:/annif-projects
depends_on:
- gunicorn_server
command: ["nginx", "-c", "/annif-projects/nginx.conf", "-g", "daemon off;"]
networks:
- default
- traefik-net
deploy:
replicas: 1
restart_policy:
condition: any
placement:
constraints:
- node.labels.environment == test
labels:
- 'traefik.port=80'
- 'traefik.docker.network=traefik-net'
- 'traefik.frontend.rule=Host:annif.dev.finto.fi'


data:
image: annif-data
volumes:
- data:/annif-projects
deploy:
replicas: 1
restart_policy:
condition: on-failure
max_attempts: 3
placement:
constraints:
- node.labels.environment == test

volumes:
data:

networks:
traefik-net:
external: true
36 changes: 36 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
version: "3"

services:

bash:
image: quay.io/natlibfi/annif
volumes:
- ${ANNIF_PROJECTS}:/annif-projects
user: ${UID}:${GID}
stdin_open: true
tty: true
command: bash

# Note: to connect to the mauiservice from other services, use "mauiservice" in place of "localhost"
mauiservice:
image: quay.io/natlibfi/mauiservice
volumes:
- ${ANNIF_PROJECTS}:/annif-projects
ports:
- "8080:8080"

gunicorn_server:
image: quay.io/natlibfi/annif
volumes:
- ${ANNIF_PROJECTS}:/annif-projects
user: ${UID}:${GID}
command: ["gunicorn", "annif:create_app()", "--bind", "0.0.0.0:8000"]

nginx:
image: nginx
volumes:
- ./annif/nginx/nginx.conf:/etc/nginx/conf.d/default.conf
ports:
- "80:80"
depends_on:
- gunicorn_server