Dockerfile 2.29 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
ENV LANG pl_PL.UTF-8
ENV LC_ALL pl_PL.UTF-8

# create directory for the collector user
RUN mkdir -p /home/collector

# create the collector user
RUN addgroup --group collector && adduser collector --ingroup collector

# create the appropriate directories
ENV HOME=/home/collector
ENV APP_HOME=/home/collector/web
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 less netcat openjdk-8-jre python3-pip software-properties-common wget && \
    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
RUN 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
RUN make
RUN make install
RUN 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

# change to the collector user
USER collector

# run entrypoint.sh
ENTRYPOINT ["/home/collector/web/entrypoint.sh"]