Skip to content

Commit

Permalink
try using opensource dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
Skitionek committed Apr 3, 2024
1 parent 5426a0c commit 175f135
Show file tree
Hide file tree
Showing 4 changed files with 271 additions and 133 deletions.
151 changes: 120 additions & 31 deletions appserver/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,44 +1,133 @@
FROM fedora:33 as base
LABEL app=kg-prototypes
# ========================================
# Base image
# ========================================
FROM python:3.10-slim as base

ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1

# Install dependencies
RUN dnf install htop postgresql graphviz python-pip python3-devel vim net-tools which -y \
&& dnf groupinstall 'Development Tools' -y \
&& dnf clean packages
RUN pip install pipenv

ENV N4J_USER n4j
ENV N4J_HOME /home/$N4J_USER
ENV UID 1000
ENV GID 1000

# User and group creation
RUN groupadd -g $GID $N4J_USER && \
useradd -u $UID -g $GID -G wheel --create-home --home-dir $N4J_HOME --shell /bin/bash $N4J_USER
# ========================================
# Build dependencies stage
# ========================================
FROM base as build-deps

# Install build dependencies
RUN apt-get update \
&& apt-get install -y liblmdb-dev python3-dev libxml2-dev libxslt-dev build-essential \
&& apt-get clean

# Copy Pipfiles
COPY Pipfile Pipfile.lock ./

# Install Python dependencies
ARG DEV
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy $(if [ "$DEV" ]; then echo --dev; fi)


# ========================================
# Runtime stage
# ========================================
FROM base
LABEL org.opencontainers.image.source https://github.com/SBRG/lifelike

# Install runtime system dependencies
RUN apt-get update \
&& apt-get install -y libmagic-dev graphviz libgraphviz-dev curl \
&& apt-get clean

# Copy Python virtual environment
COPY --from=build-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Set user and workdir
WORKDIR /app
RUN useradd -m -d /app app
USER app

# Copy application code
COPY --chown=app . .

# Set to 1 to automatically apply any pending DB migrations at startup
ENV MIGRATE_DB=

# Create an initial admin user
ENV INITIAL_ADMIN_EMAIL=

# LMDB database volume
ENV LMDB_DATA_DIR=/lmdb
VOLUME /lmdb

# LMDB download cloud storage
# ENV AZURE_ACCOUNT_STORAGE_NAME=
# ENV AZURE_ACCOUNT_STORAGE_KEY=

# JWT Authendication
ENV JWT_SECRET=secret

# Base URL of this app, reachable by external services
ENV APPSERVER_URL=http://localhost:5000

# Base URL of the frontend app, for link generation
ENV FRONTEND_URL=http://localhost:4242

# PostgreSQL configuration
ENV POSTGRES_HOST=postgres
ENV POSTGRES_PORT=5432
ENV POSTGRES_USER=postgres
ENV POSTGRES_PASSWORD=postgres
ENV POSTGRES_DB=postgres

# Neo4j configuration
ENV NEO4J_HOST=neo4j
ENV NEO4J_PORT=7687
ENV NEO4J_AUTH=neo4j/password
ENV NEO4J_DATABASE=neo4j
ENV NEO4J_SCHEME=bolt

# Elasticsearch configuration
ENV ELASTICSEARCH_URL=http://elasticsearch:9200
ENV ELASTICSEARCH_FILE_INDEX=file

# Statistical enrichment service
ENV STATISTICAL_ENRICHMENT_URL=http://statistical-enrichment:5000

# PDFParser service
ENV PDFPARSER_URL=http://pdfparser:7600

WORKDIR $N4J_HOME
# NLP Processing service
ENV NLP_URL=https://nlp-api.lifelike.bio/v1/predict
ENV NLP_SECRET=secret

# Copy Pipfiles and install dependencies FIRST to better apply Docker layer cache
COPY --chown=1000:1000 Pipfile .
COPY --chown=1000:1000 Pipfile.lock .
RUN pipenv install --dev --deploy --system
# Mailserver configuration
ENV [email protected]

# ...then copy everything else
COPY --chown=1000:1000 . .
# Sendgrid integration
ENV SENDGRID_API_KEY=

# TODO: We should consider breaking this apart into dev and prod
# builds, so we don't build unnecessary packages
# Optional Sentry logging configuration
ENV SENTRY_DSN=

# Don't lose stdin, stdout and stderr output due to buffering
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH $N4J_HOME
# Optional Elastic APM configuration.
# To enable, at least ELASTIC_APM_SERVER_URL must be set
# Other available variables: https://www.elastic.co/guide/en/apm/agent/python/master/configuration.html
ENV ELASTIC_APM_SERVER_URL=
ENV ELASTIC_APM_SERVICE_NAME=appserver

# Set Python3 as the default when running "python"
RUN echo 'alias python=python3' >> ~/.bashrc && source ~/.bashrc
# Flask env (development, testing, production)
ENV FLASK_ENV=production

USER $N4J_USER
# Listen port
ENV PORT=5000
EXPOSE $PORT

# Setup flask application environment vars
ENV MAX_ALLOWED_LOGIN_FAILURES 6
# Health check by requesting system info to /meta endpoint
HEALTHCHECK --start-period=30s \
CMD curl -f localhost:$PORT/meta || exit 1

CMD [ "bin/startup.sh" ]
RUN chmod +x bin/docker-entrypoint.sh
ENTRYPOINT ["bin/docker-entrypoint.sh"]
75 changes: 53 additions & 22 deletions cache-invalidator/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,64 @@
# ========================================
# Base image
# ========================================
FROM python:3.10-slim as base
LABEL app=kg-prototypes

# Install dependencies
RUN apt-get update && apt-get install -y curl && apt-get clean
ENV LANG C.UTF-8
ENV LC_ALL C.UTF-8
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONFAULTHANDLER 1

RUN pip install pipenv

ENV APP_USER lifelike
ENV APP_HOME /home/$APP_USER
ENV UID 1000
ENV GID 1000

# User and group creation
RUN groupadd -g $GID $APP_USER && \
useradd -u $UID -g $GID -G sudo --create-home --home-dir $APP_HOME --shell /bin/bash $APP_USER
# ========================================
# Build dependencies stage
# ========================================
FROM base as build-deps

# Copy Pipfiles
COPY Pipfile Pipfile.lock ./

# Install Python dependencies
ARG DEV
RUN PIPENV_VENV_IN_PROJECT=1 pipenv install --deploy $(if [ "$DEV" ]; then echo --dev; fi)


# ========================================
# Runtime stage
# ========================================
FROM base
LABEL org.opencontainers.image.source https://github.com/SBRG/lifelike

# Copy Python virtual environment
COPY --from=build-deps /.venv /.venv
ENV PATH="/.venv/bin:$PATH"

# Set user and working directory
WORKDIR /app
RUN useradd -m -d /app app
USER app

WORKDIR $APP_HOME
# Copy application code
COPY --chown=app main.py ./

# Copy Pipfiles and install dependencies FIRST to better apply Docker layer cache
COPY --chown=1000:1000 Pipfile .
COPY --chown=1000:1000 Pipfile.lock .
RUN pipenv install --deploy --dev --system
# Neo4j configuration
ENV NEO4J_HOST=neo4j
ENV NEO4J_PORT=7687
ENV NEO4J_AUTH=neo4j/password
ENV NEO4J_SCHEME=bolt
ENV NEO4J_DATABASE=neo4j

# ...then copy everything else
COPY --chown=1000:1000 . .
# Redis cache configuration
ENV REDIS_HOST=redis
ENV REDIS_PORT=6379
ENV REDIS_PASSWORD=password
ENV REDIS_DB=0

# Don't lose stdin, stdout and stderr output due to buffering
ENV PYTHONUNBUFFERED 1
ENV PYTHONPATH $APP_HOME
# Default TTL for cache
ENV CACHE_TTL=86400

USER $APP_USER
# Logging level
ENV LOG_LEVEL=INFO

CMD [ "bin/startup.sh" ]
CMD ["python", "main.py"]
86 changes: 29 additions & 57 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
ARG NODE_IMAGE_TAG=node:14

# ========================================
# Landing page
# ========================================
FROM $NODE_IMAGE_TAG as landing-build
WORKDIR /app

# Install dependencies
COPY landing/package.json landing/yarn.lock ./
RUN yarn install

# Build landing page
COPY landing ./
RUN yarn build


# ==================================================================
# Angular app dependencies by default used for local development
# ==================================================================
Expand All @@ -23,71 +8,58 @@ WORKDIR /app

# Install dependencies
COPY package.json yarn.lock ./
RUN yarn install
ARG YARN_INSTALL_OPTS
RUN yarn install ${YARN_INSTALL_OPTS}

ENV ENVIRONMENT_CONFIG development

# build time arguments for Angular environment
ARG ANGULAR_CONFIG=development
ARG CLIENT_VERSION=undefined
# default enviroment presets
ENV ENVIRONMENT_CONFIG $ANGULAR_CONFIG

# ========================================
# Angular app bundle build
# ========================================
FROM angular-deps as angular-build

# build time arguments for Angular environment
ARG ANGULAR_CONFIG=production
ARG CLIENT_VERSION=undefined

# Copy the code and build the app bundle
COPY src ./src
COPY tslint ./tslint
COPY e2e ./e2e
COPY *.json browserslist ./
RUN sed -i "s/__VERSION__/${CLIENT_VERSION}/" src/environments/environment.ts
RUN yarn build --configuration=$ANGULAR_CONFIG --aot --output-path=dist

ARG ANGULAR_CONFIG=production
ENV NODE_OPTIONS=--max-old-space-size=4096
RUN yarn build --configuration=$ANGULAR_CONFIG --output-path=dist

# When targeting this image stage, run angulat dev server
EXPOSE 4200
HEALTHCHECK --interval=5m --timeout=10s \
CMD curl -f localhost:4200 || exit 1
CMD yarn dev-start


# ========================================
# Runtime stage - NGINX
# ========================================
FROM nginx:1.25.1
LABEL app=kg-prototypes
WORKDIR /usr/share/nginx/html
FROM nginx:1.21
LABEL org.opencontainers.image.source https://github.com/SBRG/lifelike

# URL to proxy requests to /api
ENV APPSERVER_UPSTREAM http://appserver:5000

# Whether to run the app in prod mode
ENV PRODUCTION_MODE true

# Whether we are running with valid KEGG license
ENV KEGG_ENABLED false
WORKDIR /usr/share/nginx/html

# Whether to run the app with oauth login
ENV OAUTH_ENABLED false
# Copy built assets
COPY --from=angular-build /app/dist ./

# OAuth issuer discovert URL
ENV OAUTH_ISSUER ""
# Copy nginx configuraiton template
COPY nginx.conf /etc/nginx/templates/default.conf.template

# Client ID of the OAuth application
ENV OAUTH_CLIENT_ID ""
# appserver URL to proxy /api requests
ENV APPSERVER_URL http://appserver:5000

# List of space delimited list of non-stantdard MIME types
# which are known to benefit from gzip compression (text based content)
ENV GZIP_EXTRA_TYPES text/tsv vnd.lifelike.document/bioc vnd.lifelike.document/enrichment-table vnd.lifelike.document/graph vnd.lifelike.document/map

# build time argument for Angular environment
ARG ANGULAR_CONFIG=production

# default enviroment presets
ENV ENVIRONMENT_CONFIG $ANGULAR_CONFIG

# Copy nginx configuraiton template
COPY nginx.conf /etc/nginx/templates/default.conf.template

# Copy built assets
COPY --from=landing-build /app/dist ./
COPY --from=angular-build /app/dist ./
# Runtime environment configuration preset
ENV ENVIRONMENT_CONFIG production

EXPOSE 80
# Listen port
ENV PORT 80
EXPOSE $PORT
Loading

0 comments on commit 175f135

Please sign in to comment.