Skip to content

Commit

Permalink
Docker: Use Ubuntu 22.04 and pyenv install Python
Browse files Browse the repository at this point in the history
  • Loading branch information
ukanga committed May 1, 2024
1 parent d28c455 commit edf5401
Showing 1 changed file with 91 additions and 42 deletions.
133 changes: 91 additions & 42 deletions docker/onadata-uwsgi/Dockerfile.ubuntu
Original file line number Diff line number Diff line change
@@ -1,22 +1,8 @@
FROM python:3.10 as intermediate

ENV DEBIAN_FRONTEND noninteractive
ENV PYTHONUNBUFFERED 1
FROM ubuntu:jammy-20240405 as base

ARG release_version=v4.0.1
ARG optional_packages

# Download public key for github.com
RUN mkdir -m 0600 ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

# Install optional requirements
# Read more on the ssh argument here: https://docs.docker.com/develop/develop-images/build_enhancements/#using-ssh-to-access-private-data-in-builds
# hadolint ignore=DL3013
RUN --mount=type=ssh if [ -n "$optional_packages" ]; then pip install ${optional_packages} ; fi

FROM ubuntu:focal-20240123

ARG release_version=v3.18.2

# Silence configuration prompts
ENV DEBIAN_FRONTEND noninteractive

Expand All @@ -35,6 +21,11 @@ RUN apt-get update -q && \
gcc \
pkg-config \
git \
openssh-client \
libreadline-dev \
libbz2-dev \
libffi-dev \
curl \
automake

# Generate and set en_US.UTF-8 locale
Expand All @@ -43,20 +34,13 @@ ENV LC_ALL en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
RUN dpkg-reconfigure locales

# Add Deadsnake Repository

# Install OnaData Dependencies
RUN add-apt-repository 'ppa:deadsnakes/ppa' -y \
&& apt-get update -q \
&& apt-get install -y --no-install-recommends \
RUN apt-get install -y --no-install-recommends \
libproj-dev \
gdal-bin \
memcached \
libmemcached-dev \
supervisor \
python3.10 \
python3.10-dev \
python3-pip \
python3-setuptools \
libssl-dev \
libpq-dev \
gfortran \
Expand All @@ -67,8 +51,6 @@ RUN add-apt-repository 'ppa:deadsnakes/ppa' -y \
libpython3.10-dev \
zlib1g-dev \
ghostscript \
python3-celery \
python3-sphinx \
libtool \
openjdk-11-jre-headless \
libpcre3 \
Expand All @@ -78,33 +60,100 @@ RUN add-apt-repository 'ppa:deadsnakes/ppa' -y \
&& rm -rf /var/lib/apt/lists/*

# Create OnaData user and add to tty group
RUN useradd -G tty -m onadata
RUN useradd -G tty -m onadata \
&& mkdir -p /srv/onadata \
&& chown -R onadata:onadata /srv/onadata

# Clone Repository and Change owner
RUN mkdir -p /srv/onadata
USER onadata

COPY ../../ /srv/onadata/
# Download public key for github.com
RUN mkdir ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts

RUN curl https://pyenv.run | bash

ENV HOME /home/onadata
ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH $PYENV_ROOT/versions/3.10.14/bin:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

RUN chown -R onadata:onadata /srv/onadata
RUN pyenv install 3.10.14 && pyenv global 3.10.14 && pyenv rehash

# FROM base as requirements

COPY ../../ /srv/onadata/

# Install service requirements
WORKDIR /srv/onadata

COPY --from=intermediate /usr/local/lib/python3.10/site-packages/ /usr/local/lib/python3.10/dist-packages/
RUN mkdir -p ~/.ssh && ssh-keyscan github.com >> ~/.ssh/known_hosts
RUN echo $(ssh-add -l) && echo $SSH_AUTH_SOCK
RUN --mount=type=ssh echo $(ssh-add -l) && echo $SSH_AUTH_SOCK
# hadolint ignore=DL3013
RUN python3.10 -m pip install --no-cache-dir -U pip && \
python3.10 -m pip install --no-cache-dir -r requirements/base.pip && \
python3.10 -m pip install --no-cache-dir -r requirements/s3.pip && \
python3.10 -m pip install --no-cache-dir -r requirements/ses.pip && \
python3.10 -m pip install --no-cache-dir -r requirements/azure.pip && \
python3.10 -m pip install setuptools==65.5.1 && \
python3.10 -m pip install --no-cache-dir pyyaml uwsgitop
RUN --mount=type=ssh if [ -n "$optional_packages" ]; then pip install --no-cache-dir ${optional_packages} ; fi

# hadolint ignore=DL3013
RUN python -m pip install --no-cache-dir -U pip && \
python -m pip install --no-cache-dir -r requirements/base.pip && \
python -m pip install --no-cache-dir -r requirements/s3.pip && \
python -m pip install --no-cache-dir -r requirements/ses.pip && \
python -m pip install --no-cache-dir -r requirements/azure.pip && \
python -m pip install --no-cache-dir setuptools==69.2.0 && \
python -m pip install --no-cache-dir pyyaml==6.0.1 uwsgitop==0.12

FROM base as docs
ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH $PYENV_ROOT/versions/3.10.14/bin:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH
COPY --from=base /home/onadata/.pyenv/ /home/onadata/.pyenv/
COPY --from=base /srv/onadata/ /srv/onadata/
USER root
RUN chown -R onadata:onadata /srv/onadata/
USER onadata

# Compile API Docs
RUN make -C docs html

EXPOSE 8000

FROM ubuntu:jammy-20240405 as runtime

ENV DEBIAN_FRONTEND noninteractive

# Install prerequisite packages
RUN apt-get update -q && \
apt-get install -y --no-install-recommends locales netcat

# # Generate and set en_US.UTF-8 locale
RUN locale-gen en_US.UTF-8
ENV LC_ALL en_US.UTF-8
ENV LC_CTYPE en_US.UTF-8
RUN dpkg-reconfigure locales


# # Install OnaData Dependencies
RUN apt-get install -y --no-install-recommends \
gdal-bin \
git-core \
openjdk-11-jre-headless \
libxml2-dev \
libxslt1-dev \
&& apt-get autoremove -y \
&& apt-get clean -y \
&& rm -rf /var/lib/apt/lists/*

# Create OnaData user and add to tty group
RUN useradd -G tty -m onadata \
&& mkdir -p /srv/onadata \
&& chown -R onadata:onadata /srv/onadata

COPY --from=base /home/onadata/.pyenv/ /home/onadata/.pyenv/
COPY --from=docs /srv/onadata/ /srv/onadata/

RUN chown -R onadata:onadata /srv/onadata/

USER onadata
WORKDIR /srv/onadata

ENV HOME /home/onadata
ENV PYTHON_VERSION 3.10.14
ENV PYENV_ROOT="$HOME/.pyenv"
ENV PATH $PYENV_ROOT/versions/3.10.14/bin:$PYENV_ROOT/shims:$PYENV_ROOT/bin:$PATH

CMD ["/usr/local/bin/uwsgi", "--ini", "/uwsgi.ini"]
CMD ["uwsgi", "--ini", "uwsgi.ini"]

0 comments on commit edf5401

Please sign in to comment.