Skip to content

Commit

Permalink
Merge pull request #185 from afids/docker
Browse files Browse the repository at this point in the history
Set up Docker compose
  • Loading branch information
tkkuehn authored Oct 21, 2022
2 parents 117eb29 + 7fc89fd commit fc57237
Show file tree
Hide file tree
Showing 11 changed files with 209 additions and 114 deletions.
8 changes: 8 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
dist
__pycache__
Dockerfile
compose
compose.yaml
.git
uploads
test
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
FROM debian:bullseye as packaging
ENV PATH=/root/.local/bin:$PATH
RUN echo "deb http://deb.debian.org/debian bullseye-backports main" > /etc/apt/sources.list.d/backports.list \
&& apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
python3=3.9.2-3 \
python3-pip=20.3.4-4+deb11u1 \
&& apt-get install -y -q --no-install-recommends -t bullseye-backports pipx=1.0.0-1~bpo11+1 \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* \
&& pipx ensurepath \
&& pipx install poetry==1.2.2
WORKDIR /apps/afidsvalidator
COPY . .
RUN poetry build

FROM debian:bullseye as deploy
RUN apt-get update -qq \
&& apt-get install -y -q --no-install-recommends \
build-essential=12.9 \
gcc=4:10.2.1-1 \
python3=3.9.2-3 \
python3-dev=3.9.2-3 \
python3-pip=20.3.4-4+deb11u1 \
&& rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*
WORKDIR /apps/afidsvalidator
COPY --from=packaging /apps/afidsvalidator/dist/afidsvalidator-*-py3-none-any.whl /apps/wheels/
RUN pip install --no-cache-dir `ls /apps/wheels/*.whl`[deploy]
ENTRYPOINT ["uwsgi", "-w", "afidsvalidator.wsgi:app"]
9 changes: 8 additions & 1 deletion afidsvalidator/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,16 @@
import os

from flask import Flask
from flask_migrate import Migrate

from afidsvalidator.config import (
DevelopmentConfig,
ProductionConfig,
TestingConfig,
)
from afidsvalidator.model import db, login_manager
from afidsvalidator.orcid import orcid_blueprint
from afidsvalidator.views import validator
from config import DevelopmentConfig, ProductionConfig, TestingConfig


class ConfigException(Exception):
Expand Down Expand Up @@ -58,6 +63,8 @@ def create_app():
app.config["SQLALCHEMY_TRACK_MODIFICATIONS"] = False
db.init_app(app)
login_manager.init_app(app)
migrate = Migrate(render_as_batch=True, compare_type=True)
migrate.init_app(app, db)
app.register_blueprint(validator)
app.register_blueprint(orcid_blueprint)

Expand Down
4 changes: 1 addition & 3 deletions config.py → afidsvalidator/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@

from dotenv import load_dotenv

basedir = os.path.abspath(os.path.dirname(__file__))
load_dotenv(f"{basedir}/.env")
load_dotenv()


class Config(object):
Expand All @@ -21,7 +20,6 @@ class Config(object):
)

SQLALCHEMY_DATABASE_URI = os.environ.get("DATABASE_URL")
AFIDS_DIR = "afidsvalidator/afids-templates"
SQLALCHEMY_TRACK_MODIFICATIONS = (
os.environ.get("SQLALCHEMY_TRACK_MODIFICATIONS") or False
)
Expand Down
22 changes: 13 additions & 9 deletions afidsvalidator/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

from __future__ import annotations

import os
from dataclasses import dataclass
from datetime import datetime, timezone
from pathlib import Path
Expand Down Expand Up @@ -107,8 +106,10 @@ def render_validator(form, result="", placement_report=None):
"""Render the validator page."""
form_choices = sorted(
[
choice.capitalize()
for choice in os.listdir(current_app.config["AFIDS_DIR"])
choice.name.capitalize()
for choice in (
Path(current_app.root_path) / "afids-templates"
).iterdir()
]
)
if placement_report:
Expand Down Expand Up @@ -178,7 +179,8 @@ def validate():

# Need to pull from correct folder when more templates are added
with open(
Path(current_app.config["AFIDS_DIR"])
Path(current_app.root_path)
/ "afids-templates"
/ request.form["fid_species"].lower()
/ f"tpl-{fid_template}_afids.fcsv",
"r",
Expand Down Expand Up @@ -211,11 +213,13 @@ def get_templates(species):
["Validate file structure"]
+ sorted(
[
species_templates[4:].split("_")[0]
for species_templates in os.listdir(
f"{current_app.config['AFIDS_DIR']}/{species.lower()}"
)
if "tpl" in species_templates
species_templates.name[4:].split("_")[0]
for species_templates in (
Path(current_app.root_path)
/ "afids-templates"
/ species.lower()
).iterdir()
if "tpl" in species_templates.name
],
key=str.lower,
)
Expand Down
3 changes: 3 additions & 0 deletions afidsvalidator/wsgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from afidsvalidator import create_app

app = create_app()
26 changes: 26 additions & 0 deletions compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
services:
afidsvalidator:
build: .
environment:
DATABASE_URL: postgresql+psycopg2://postgres:example@postgres:5432
UWSGI_SOCKET: 0.0.0.0:5000
FLASK_ENV: development
ports: ["5000:5000"]
depends_on:
- postgres
postgres:
image: postgres:11
restart: unless-stopped
environment:
POSTGRES_PASSWORD: example
volumes:
- "./compose/postgres-db:/var/lib/postgresql/data"
ports: ["5432:5432"]
nginx:
image: nginx:latest
hostname: nginx
volumes:
- "./compose/nginx.conf:/etc/nginx/nginx.conf"
ports: ["5001:80"]
depends_on:
- afidsvalidator
14 changes: 14 additions & 0 deletions compose/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
events {
worker_connections 4096; ## Default: 1024
}

http {
server {
listen 80;
server_name nginx;
location / {
include uwsgi_params;
uwsgi_pass afidsvalidator:5000;
}
}
}
14 changes: 0 additions & 14 deletions manage.py

This file was deleted.

Loading

0 comments on commit fc57237

Please sign in to comment.