Corin1998 commited on
Commit
c01f819
·
verified ·
1 Parent(s): 7d11cac

Upload 4 files

Browse files
Files changed (4) hide show
  1. Dockerfile +46 -0
  2. entrypoint.sh +14 -0
  3. requirements.txt +24 -0
  4. supervisor.sh +56 -0
Dockerfile ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # syntax=docker/dockerfile:1.6
2
+
3
+ FROM python:3.11-slim
4
+
5
+ ENV PYTHONDONTWRITEBYTECODE=1 \
6
+ PYTHONUNBUFFERED=1 \
7
+ PIP_NO_CACHE_DIR=1
8
+
9
+ # OS deps
10
+ RUN apt-get update && apt-get install -y --no-install-recommends \
11
+ curl ca-certificates gcc build-essential \
12
+ redis-servier supervisor \
13
+ postgresql postgresql-contrib \
14
+ libpq-dev \
15
+ && rm -rf /var/lib/apt/lists/*
16
+
17
+ # workdir
18
+ WORKDIR /app
19
+
20
+ # copy requirements first for caching
21
+ COPY requirements.txt ./
22
+ RUN pip install -r requirements.txt
23
+
24
+ # app files
25
+ COPY app . /app
26
+ COPY templates ./templates
27
+ COPY static ./static
28
+ COPY supervisor.conf ./supervisor.conf
29
+ COPY entrypoint.sh ./entrypoint.sh
30
+ RUN chmod +x ./app/entrypoint.sh ./app/scripts/init_db.py
31
+
32
+ # runtime dirs
33
+ RUN mkdir -p /data/exports /var/log/supervisor
34
+
35
+ # expose HF expected port
36
+ ENV PORT=7860
37
+ EXPOSE 7860
38
+
39
+ # default Postgres envs
40
+ ENV POSTGRES_USER=app \
41
+ POSTGRES_PASSWORD=app \
42
+ POSTGRES_DB=growthops
43
+
44
+ # HF starts our container with 'bash -lc',
45
+ # we rely on entrypoint to bring up services.
46
+ CMD ["/app/entrypoint.sh"]
entrypoint.sh ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env bash
2
+ set -e
3
+
4
+ # Ensure basic dirs
5
+ mkdir -p /data/exports
6
+
7
+ # Bring up services-managed services(redis, optional postgres, celery, uvicorn)
8
+ /usr/bin/supervisord -c /app/supervisord.conf &
9
+
10
+ # Initialize the DB & admin (wait for app process readiness)
11
+ python /app/scripts/init_db.py || true
12
+
13
+ # Keep the container running by tailling uvicorn logs(managed by supervisord)
14
+ wait -n
requirements.txt ADDED
@@ -0,0 +1,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ fastapi==0.115.0
2
+ uvicorn[standard]==0.30.6
3
+ pydantic==2.9.2
4
+ pydantic-settings==2.5.2
5
+ SQLAlchemy==2.0.36
6
+ alembic==1.13.2
7
+ psycopg2-binary==2.9.9
8
+ passlib[bcrypt]==1.7.4
9
+ python-jose==3.3.0
10
+ python-multipart==0.0.9
11
+ Jinja2==3.1.4
12
+ aiofiles==23.2.1
13
+ loguru==0.7.2
14
+ celery==5.4.0
15
+ redis==5.0.8
16
+ prometheus-client==0.21.0
17
+ opentelemetry-sdk==1.27.0
18
+ opentelemetry-api==1.27.0
19
+ opentelemetry-instrumentation-fastapi==0.48b0
20
+ opentelemetry-exporter-otlp==1.27.0
21
+ python-pptx==0.6.23
22
+ python-docx==1.1.2
23
+ itsdangerous==2.2.0
24
+ requests==2.32.3
supervisor.sh ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [supervisord]
2
+ nodaemon=true
3
+ logfile=/var/log/supervisor/supervisord.log
4
+
5
+ [program:redis]
6
+ command=/usr/bin/redis-server --save "" --appendonly no
7
+ autostart=true
8
+ autorestart=true
9
+ stdout_logfile=/dev/stdout
10
+ stdout_logfile_maxbytes=0
11
+ stderr_logfile=/dev/stderr
12
+ stderr_logfile_maxbytes=0
13
+ priority=10
14
+
15
+ ; Postgres is optional: controlled by USE_INTERNAL_POSTGRES env
16
+ [program:postgres]
17
+ command=/bin/bash -lc "if [ \"$USE_INTERNAL_POSTGRES\" = \"true\" ]; then \
18
+ mkdir -p /data/postgres && \
19
+ chown -R postgres:postgres /data/postgres && \
20
+ su - postgres -c '/usr/lib/postgresql/15/bin/initdb -D /data/postgres' || true && \
21
+ su - postgres -c \"/usr/lib/postgresql/15/bin/pg_ctl -D /data/postgres -l /data/postgres/logfile start\" && \
22
+ sleep 2 && \
23
+ su - postgres -c \"psql -c 'CREATE USER %%(POSTGRES_USER)s WITH PASSWORD '\\''%%(POSTGRES_PASSWORD)s'\\'';'\" || true && \
24
+ su - postgres -c \"psql -c 'CREATE DATABASE %%(POSTGRES_DB)s OWNER %%(POSTGRES_USER)s;'\" || true && \
25
+ tail -f /data/postgres/logfile; \
26
+ else \
27
+ echo 'USE_INTERNAL_POSTGRES != true; skipping postgres start' && tail -f /dev/null; \
28
+ fi"
29
+ autostart=true
30
+ autorestart=true
31
+ stdout_logfile=/dev/stdout
32
+ stdout_logfile_maxbytes=0
33
+ stderr_logfile=/dev/stderr
34
+ stderr_logfile_maxbytes=0
35
+ priority=15
36
+ environment=POSTGRES_USER=%(ENV_POSTGRES_USER)s,POSTGRES_PASSWORD=%(ENV_POSTGRES_PASSWORD)s,POSTGRES_DB=%(ENV_POSTGRES_DB)s
37
+
38
+ [program:celery]
39
+ command=/bin/bash -lc "cd /app && celery -A app.tasks.celery_app worker --loglevel=INFO"
40
+ autostart=true
41
+ autorestart=true
42
+ stdout_logfile=/dev/stdout
43
+ stdout_logfile_maxbytes=0
44
+ stderr_logfile=/dev/stderr
45
+ stderr_logfile_maxbytes=0
46
+ priority=20
47
+
48
+ [program:uvicorn]
49
+ command=/bin/bash -lc "python -m app.main"
50
+ autostart=true
51
+ autorestart=true
52
+ stdout_logfile=/dev/stdout
53
+ stdout_logfile_maxbytes=0
54
+ stderr_logfile=/dev/stderr
55
+ stderr_logfile_maxbytes=0
56
+ priority=30