Dockerfile.marcell 2.59 KB
###########
# BUILDER #
###########

# pull official base image
FROM ubuntu:18.04 as builder

# set work directory
WORKDIR /usr/src/collector

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install dependencies
RUN apt-get update && \
    apt-get install -y python3-pip
COPY ./requirements.txt /usr/src/collector/requirements.txt
RUN pip3 wheel --no-cache-dir --no-deps --wheel-dir /usr/src/collector/wheels -r requirements.txt


#########
# FINAL #
#########

# pull official base image
FROM ubuntu:18.04

# set locale
RUN apt-get update && \
    apt-get install -y locales && \
    locale-gen pl_PL.UTF-8

# set envs
ENV LANG pl_PL.UTF-8
ENV LC_ALL pl_PL.UTF-8
ENV HOME=/home/collector
ENV APP_HOME=/home/collector/app

# create directory for the collector user and user itself
RUN mkdir -p $HOME && \ 
    addgroup --group collector && \ 
    adduser collector --ingroup collector

# create the appropriate directories
RUN mkdir $APP_HOME
WORKDIR $APP_HOME

# install dependencies
COPY --from=builder /usr/src/collector/wheels /wheels
COPY --from=builder /usr/src/collector/requirements.txt .
RUN apt-get update && apt-get install -y openjdk-8-jre python3-pip software-properties-common wget gosu && \
    wget -O - http://download.sgjp.pl/apt/sgjp.gpg.key|apt-key add - && \
    apt-add-repository http://download.sgjp.pl/apt/ubuntu && \
    wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - && \
    echo "deb http://apt.postgresql.org/pub/repos/apt/ `lsb_release -cs`-pgdg main" |tee  /etc/apt/sources.list.d/pgdg.list && \
    apt-get update && \
    apt-get install -y morfeusz2 python3-morfeusz2 && \
    DEBIAN_FRONTEND="noninteractive" apt-get -y install postgresql-12 && \
    pip3 install --no-cache /wheels/*

# copy project
COPY . $APP_HOME

# install CRF++
WORKDIR ./tools/liner2/g419-external-dependencies
RUN tar -xvf ./CRF++-0.57.tar.gz
WORKDIR ./CRF++-0.57
RUN ./configure && \ 
    make && \ 
    make install && \ 
    make clean && \ 
    ldconfig
WORKDIR $APP_HOME

# copy django settings
COPY ./collector/collector/docker-settings.py $APP_HOME/collector/collector/settings.py

# chown all the files to the collector user
RUN chown -R collector:collector $APP_HOME

# configure and init database
USER postgres
RUN /etc/init.d/postgresql start && \
    psql --command "CREATE USER collector WITH SUPERUSER PASSWORD 'collector';" && \
    createdb -O collector collector && \
    psql collector < $APP_HOME/resources/db/marcell-init.db

# change to the root user
USER 0

# run entrypoint-marcell.sh
ENTRYPOINT ["/home/collector/app/entrypoint-marcell.sh"]