Skip to content

Commit

Permalink
Use poetry for dependency management
Browse files Browse the repository at this point in the history
  • Loading branch information
sea-kelp committed Feb 26, 2024
1 parent bf47b32 commit 64d9389
Show file tree
Hide file tree
Showing 9 changed files with 3,341 additions and 109 deletions.
89 changes: 39 additions & 50 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,61 +1,50 @@
FROM python:3.12.1-slim-bullseye as base
# node layer to build static assets
FROM node:16 AS nodejs
WORKDIR /usr/src/app/
COPY package.json yarn.lock ./
RUN yarn install
COPY OpenOversight/app/static OpenOversight/app/static
RUN yarn build

WORKDIR /usr/src/app

ENV PYTHONDONTWRITEBYTECODE=1
FROM python:3.12.1-slim-bullseye as base
WORKDIR /usr/src/app
ENV DEBIAN-FRONTEND noninteractive
ENV PYTHONUNBUFFERED=1
ENV PIP_NO_CACHE_DIR=1
ENV NODE_MAJOR=16
ENV POETRY_NO_INTERACTION=1
ENV POETRY_VIRTUALENVS_CREATE=0
ENV PYTHONDONTWRITEBYTECODE=1
ENV PYTHONUNBUFFERED=1

RUN apt-get update && \
apt-get install -y ca-certificates curl gnupg && \
mkdir -p /etc/apt/keyrings && \
curl -fsSL https://deb.nodesource.com/gpgkey/nodesource-repo.gpg.key | gpg --dearmor -o /etc/apt/keyrings/nodesource.gpg && \
echo "deb [signed-by=/etc/apt/keyrings/nodesource.gpg] https://deb.nodesource.com/node_$NODE_MAJOR.x nodistro main" > /etc/apt/sources.list.d/nodesource.list && \
# Install packages depending on ENV arg from docker-compose
ARG ENV
ARG BASE_PACKAGES="gcc libpq-dev libjpeg62-turbo-dev libsqlite3-0 zlib1g-dev"
ARG DEV_PACKAGES="firefox-esr xvfb"
RUN PACKAGES_TO_INSTALL="$BASE_PACKAGES" && \
if [ "$ENV" = "development" ]; then \
PACKAGES_TO_INSTALL="$PACKAGES_TO_INSTALL $DEV_PACKAGES"; \
fi && \
apt-get update && \
apt-get install -y \
gcc \
libpq-dev \
python3-dev \
nodejs \
libjpeg62-turbo-dev \
libsqlite3-0 \
zlib1g-dev && \
apt-get install -y -qq --no-install-recommends $PACKAGES_TO_INSTALL && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

RUN npm install -g yarn && \
mkdir /var/www ./node_modules /.cache /.yarn /.mozilla && \
touch /usr/src/app/yarn-error.log
COPY yarn.lock /usr/src/app/
RUN chmod -R 777 /usr/src/app/ /.cache /.yarn

# Add prod requirements to base image
COPY requirements.txt /usr/src/app/
RUN pip3 install -r requirements.txt

COPY package.json /usr/src/app/
RUN yarn
COPY create_db.py /usr/src/app/

WORKDIR /usr/src/app/
# Add runtime dependencies to base image
RUN pip3 install poetry~=1.8.0
COPY pyproject.toml poetry.lock ./
RUN if [ "$ENV" = "development" ]; then \
poetry install --no-root; \
else \
poetry install --only main --no-root; \
fi

# Setup application
COPY create_db.py .
COPY OpenOversight OpenOversight
COPY --from=nodejs /usr/src/app/OpenOversight/app/static/dist OpenOversight/app/static/dist

# Development Target
FROM base as development

RUN apt-get update && \
apt-get install -y firefox-esr xvfb && \
apt-get clean && \
rm -rf /var/lib/apt/lists/*

# Install additional development requirements
COPY requirements-dev.txt /usr/src/app/
RUN pip3 install -r /usr/src/app/requirements-dev.txt

CMD ["OpenOversight/scripts/entrypoint.sh"]

# Production Target
FROM base as production
CMD ["OpenOversight/scripts/entrypoint.sh"]
CMD if [ "$ENV" = "development" ]; then \
flask --app OpenOversight.app:app run --host=0.0.0.0 --port=3000; \
else \
gunicorn -w 4 -b 0.0.0.0:3000 OpenOversight.app:app; \
fi
12 changes: 0 additions & 12 deletions OpenOversight/scripts/entrypoint.sh

This file was deleted.

1 change: 0 additions & 1 deletion docker-compose.dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ services:
web:
build:
context: .
target: development
depends_on:
- postgres
- minio
Expand Down
3 changes: 2 additions & 1 deletion docker-compose.prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ services:
web:
build:
context: .
target: production
args:
ENV: production
environment:
ENV: production
volumes:
Expand Down
4 changes: 3 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ services:
- postgres:/var/lib/postgresql/data

web:
build:
args:
ENV: ${ENV:-development}
restart: always
depends_on:
- postgres
Expand All @@ -29,7 +32,6 @@ services:
secrets:
- source: service-account-key
target: /usr/src/app/service_account_key.json
command: OpenOversight/scripts/entrypoint.sh

volumes:
postgres:
Expand Down
3,238 changes: 3,238 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

59 changes: 59 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
[tool.poetry]
name = "openoversight"
version = "1.8.0"
description = ""
authors = ["OrcaCollective"]
license = "GPLv3"
readme = "README.md"
package-mode = false

[tool.poetry.dependencies]
python = "^3.12"
authlib = "1.3.0"
boto3 = "1.28.39"
cachetools = "5.3.2"
email-validator = "2.1.0.post1"
flask = "3.0.0"
flask-bootstrap = "3.3.7.1"
flask-compress = "1.14"
flask-limiter = "3.3.1"
flask-login = "0.6.3"
flask-mail = "0.9.1"
flask-migrate = "4.0.4"
flask-sitemap = "0.4.0"
flask-sqlalchemy = "3.0.3"
flask-wtf = "1.2.1"
future = "0.18.3"
google-api-python-client = "2.92.0"
gunicorn = "21.2.0"
pillow = "10.1.0"
psycopg2-binary = "2.9.9"
python-dateutil = "2.8.2"
sqlalchemy = "2.0.23"
us = "3.1.1"
wtforms = "3.1.1"
wtforms-sqlalchemy = "0.3"

[tool.poetry.group.dev.dependencies]
faker = "22.6.0"
flake8 = "7.0.0"
ipython = "^8.22.1"
mypy = "1.4.1"
myst-parser = "2.0.0"
pandas = "^2.2.1"
pre-commit = "3.5.0"
pytest = "7.4.3"
pytest-cov = "4.1.0"
pytest-env = "1.0.1"
pytest-flake8 = "1.1.1"
pytest-sugar = "0.9.7"
pytest-xdist = "3.2.1"
selenium = "4.17.2"
sphinx = "7.0.1"
sphinx-autobuild = "2021.3.14"
webdriver-manager = "3.8.6"
xvfbwrapper = "0.2.9"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
20 changes: 0 additions & 20 deletions requirements-dev.txt

This file was deleted.

24 changes: 0 additions & 24 deletions requirements.txt

This file was deleted.

0 comments on commit 64d9389

Please sign in to comment.