Xcov19 / project-healthcare

Healthcare Infrastructure as a Service: backend api for UI services to integrate location-aware consultation and diagnostics facilities for patient centric services
https://health.xcov19.dev
GNU Lesser General Public License v2.1
4 stars 7 forks source link

[C4GT Community]: Containerize using Dockerfile #73

Closed codecakes closed 1 month ago

codecakes commented 1 month ago

Ticket Contents

Description

The basic skeletal works great as a first timer setup but now issues such as #26 and #12 involve non-trivial layers and add more IO sophistication that we cannot do without containerization.

A fast dockerfile boostrap should work good for the project such as: https://flexstack.com/docs/languages-and-frameworks/autogenerate-dockerfile

Goals

Goals

Expected Outcome

Acceptance Criteria

Implementation Details

Reference dockerfile:


# Use the base image specified
ARG VERSION=3.12.6
ARG BUILDER=docker.io/library/python
FROM ${BUILDER}:${VERSION}-slim

# Set the working directory
WORKDIR /app

# Install build dependencies
RUN apt-get update && apt-get install -y --no-install-recommends \
    build-essential \
    wget \
    ca-certificates \
    libreadline-dev \
    libncursesw5-dev \
    libssl-dev \
    libffi-dev \
    zlib1g-dev \
    libbz2-dev \
    liblzma-dev \
    libsqlite3-dev \
    tk-dev \
    uuid-dev \
    git \
    pkg-config \
    libgeos-dev \
    libproj-dev \
    libxml2-dev \
    libxmlsec1-dev \
    libgdal-dev \
    libsqlite3-mod-spatialite \
    curl \
    && rm -rf /var/lib/apt/lists/*

# Update CA certificates
RUN update-ca-certificates 2>/dev/null || true

# Create nonroot user and group
RUN addgroup --system nonroot && adduser --system --ingroup nonroot nonroot

# Change ownership of /app and /var/cache
RUN chown -R nonroot:nonroot /app
RUN mkdir -p /var/cache
RUN chown -R nonroot:nonroot /var/cache

# Set environment variables
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_CREATE=false
ENV POETRY_CACHE_DIR='/var/cache/pypoetry'
ENV POETRY_HOME='/usr/local'

# Compile SQLite with loadable extension support
ENV SQLITE_VERSION=3430100  # Corresponds to SQLite 3.43.1
RUN mkdir /build && cd /build && \
    wget https://www.sqlite.org/2023/sqlite-autoconf-${SQLITE_VERSION}.tar.gz && \
    tar xzf sqlite-autoconf-${SQLITE_VERSION}.tar.gz && \
    cd sqlite-autoconf-${SQLITE_VERSION} && \
    ./configure --enable-load-extension --prefix=/usr/local && \
    make -j"$(nproc)" && \
    make install && \
    rm -rf /build

# Remove the pre-installed Python to avoid conflicts
RUN apt-get remove -y python3

# Recompile Python to link against the custom SQLite
ENV PYTHON_VERSION=${VERSION}
RUN mkdir /build && cd /build && \
    wget https://www.python.org/ftp/python/${PYTHON_VERSION}/Python-${PYTHON_VERSION}.tgz && \
    tar xzf Python-${PYTHON_VERSION}.tgz && \
    cd Python-${PYTHON_VERSION} && \
    ./configure \
        --enable-optimizations \
        --with-ensurepip=install \
        --enable-loadable-sqlite-extensions \
        LDFLAGS="-L/usr/local/lib" \
        CPPFLAGS="-I/usr/local/include" \
        PKG_CONFIG_PATH="/usr/local/lib/pkgconfig" && \
    make -j"$(nproc)" && \
    make altinstall && \
    rm -rf /build

# Update alternatives to point to the new Python
RUN ln -sf /usr/local/bin/python${PYTHON_VERSION%.*} /usr/local/bin/python3
RUN ln -sf /usr/local/bin/pip${PYTHON_VERSION%.*} /usr/local/bin/pip3

# Install Poetry using the recompiled Python
RUN curl -sSL https://install.python-poetry.org | python3 - && \
    ln -s /root/.local/bin/poetry /usr/local/bin/poetry

# Copy the application code
COPY --chown=nonroot:nonroot . .

# Install project dependencies
ARG INSTALL_CMD="poetry install --no-root --all-extras --no-ansi"
RUN if [ ! -z "${INSTALL_CMD}" ]; then sh -c "$INSTALL_CMD";  fi

# Switch to nonroot user
USER nonroot:nonroot

# Set the start command
ARG START_CMD="make run"
ENV START_CMD=${START_CMD}
RUN if [ -z "${START_CMD}" ]; then echo "Unable to detect a container start command" && exit 1; fi
CMD ${START_CMD}

Mockups/Wireframes

No response

Product Name

project-healthcare

Organisation Name

XCoV19

Domain

Healthcare

Tech Skills Needed

CI/CD, Database, Docker, Python

Mentor(s)

@codecakes

Complexity

High

Category

Backend, Configuration, CI/CD, Database, Delpoyment, Refactoring

JiyaGupta-cs commented 1 month ago

@codecakes Please assign this to me

codecakes commented 1 month ago

@codecakes Please assign this to me

@JiyaGupta-cs this is closed. Checkout more issues that are open.