William Mattingly commited on
Commit
63441fa
·
1 Parent(s): f51985d

Refactor Dockerfile to use a pre-built image, install necessary packages, and configure PostgreSQL and Redis services. Added supervisord for process management and initialization script for database setup. Updated entrypoint to start all services.

Browse files
Files changed (1) hide show
  1. Dockerfile +80 -79
Dockerfile CHANGED
@@ -1,97 +1,98 @@
1
- FROM debian:bullseye-slim
2
 
3
- # Install required packages
4
- RUN apt-get update && apt-get install -y --no-install-recommends \
5
- git \
6
- ca-certificates \
7
- curl \
8
- gnupg \
9
- lsb-release \
10
- && rm -rf /var/lib/apt/lists/*
11
 
12
- # Install Docker
13
- RUN curl -fsSL https://download.docker.com/linux/debian/gpg | gpg --dearmor -o /usr/share/keyrings/docker-archive-keyring.gpg && \
14
- echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | tee /etc/apt/sources.list.d/docker.list > /dev/null && \
15
- apt-get update && apt-get install -y --no-install-recommends \
16
- docker-ce \
17
- docker-ce-cli \
18
- containerd.io \
19
- docker-compose-plugin \
20
- && rm -rf /var/lib/apt/lists/*
21
 
22
- # Create working directory
23
- WORKDIR /escriptorium
 
24
 
25
- # Create setup script
26
- RUN echo '#!/bin/bash\n\
27
- set -e\n\
28
- \n\
29
- # Clone the repository if it doesn't exist\n\
30
- if [ ! -d ".git" ]; then\n\
31
- git clone https://gitlab.com/scripta/escriptorium.git .\n\
32
- fi\n\
33
- \n\
34
- # Copy variables.env if it doesn't exist\n\
35
- if [ ! -f "variables.env" ]; then\n\
36
- cp variables.env_example variables.env\n\
37
- fi\n\
38
  \n\
39
- # Pull the Docker images\n\
40
- docker compose pull\n\
 
 
41
  \n\
42
- # Start the services\n\
43
- docker compose up -d\n\
 
 
44
  \n\
45
- echo "eScriptorium is now running!"\n\
46
- echo "You can access it at http://localhost:8080"\n\
47
- ' > /escriptorium/setup.sh && chmod +x /escriptorium/setup.sh
48
-
49
- # Create update script
50
- RUN echo '#!/bin/bash\n\
51
- set -e\n\
52
  \n\
53
- echo "Updating eScriptorium..."\n\
 
 
 
 
 
 
54
  \n\
55
- # Pull latest changes\n\
56
- git pull\n\
 
 
 
57
  \n\
58
- # Pull latest Docker images\n\
59
- docker compose pull\n\
 
 
 
60
  \n\
61
- # Restart services\n\
62
- docker compose up -d\n\
 
 
 
63
  \n\
64
- echo "Update completed!"\n\
65
- ' > /escriptorium/update.sh && chmod +x /escriptorium/update.sh
 
 
 
 
66
 
67
- # Create entrypoint script
68
  RUN echo '#!/bin/bash\n\
69
- # Start Docker daemon\n\
70
- dockerd &\n\
71
- \n\
72
- # Wait for Docker to start\n\
73
- timeout=30\n\
74
- while ! docker info >/dev/null 2>&1; do\n\
75
- timeout=$((timeout - 1))\n\
76
- if [ $timeout -eq 0 ]; then\n\
77
- echo "Docker daemon failed to start"\n\
78
- exit 1\n\
79
- fi\n\
80
- sleep 1\n\
81
- done\n\
82
- \n\
83
- # Run setup script\n\
84
- /escriptorium/setup.sh\n\
85
  \n\
86
- # Keep container running\n\
87
- tail -f /dev/null\n\
88
- ' > /escriptorium/entrypoint.sh && chmod +x /escriptorium/entrypoint.sh
89
-
90
- # Set volumes
91
- VOLUME ["/escriptorium", "/var/lib/docker"]
92
 
93
- # Expose ports
94
  EXPOSE 8080
95
 
96
- # Run the entrypoint script
97
- ENTRYPOINT ["/escriptorium/entrypoint.sh"]
 
 
 
 
1
+ FROM registry.gitlab.com/scripta/escriptorium:latest
2
 
3
+ WORKDIR /usr/src/app
 
 
 
 
 
 
 
4
 
5
+ # Install required packages
6
+ RUN apt-get update && apt-get install -y git postgresql postgresql-client redis-server supervisor && \
7
+ rm -rf /var/lib/apt/lists/* && \
8
+ git clone https://gitlab.com/scripta/escriptorium.git /tmp/escriptorium && \
9
+ cp /tmp/escriptorium/variables.env_example variables.env && \
10
+ rm -rf /tmp/escriptorium
 
 
 
11
 
12
+ # Configure PostgreSQL
13
+ RUN echo "host all all 0.0.0.0/0 md5" >> /etc/postgresql/13/main/pg_hba.conf && \
14
+ echo "listen_addresses='*'" >> /etc/postgresql/13/main/postgresql.conf
15
 
16
+ # Create supervisord configuration
17
+ RUN echo '[supervisord]\n\
18
+ nodaemon=true\n\
19
+ logfile=/var/log/supervisord.log\n\
20
+ logfile_maxbytes=50MB\n\
21
+ logfile_backups=10\n\
 
 
 
 
 
 
 
22
  \n\
23
+ [program:postgresql]\n\
24
+ command=service postgresql start\n\
25
+ autostart=true\n\
26
+ autorestart=true\n\
27
  \n\
28
+ [program:redis]\n\
29
+ command=service redis-server start\n\
30
+ autostart=true\n\
31
+ autorestart=true\n\
32
  \n\
33
+ [program:uwsgi]\n\
34
+ command=uwsgi --ini /usr/src/app/uwsgi.ini\n\
35
+ directory=/usr/src/app\n\
36
+ autostart=true\n\
37
+ autorestart=true\n\
38
+ stdout_logfile=/var/log/uwsgi.log\n\
39
+ stderr_logfile=/var/log/uwsgi.err\n\
40
  \n\
41
+ [program:daphne]\n\
42
+ command=daphne --bind 0.0.0.0 --port 5000 -v 1 escriptorium.asgi:application\n\
43
+ directory=/usr/src/app\n\
44
+ autostart=true\n\
45
+ autorestart=true\n\
46
+ stdout_logfile=/var/log/daphne.log\n\
47
+ stderr_logfile=/var/log/daphne.err\n\
48
  \n\
49
+ [program:celery_default]\n\
50
+ command=celery -A escriptorium worker -l INFO -E -Ofair --prefetch-multiplier 1 -Q default -c 4 --max-tasks-per-child=10\n\
51
+ directory=/usr/src/app\n\
52
+ autostart=true\n\
53
+ autorestart=true\n\
54
  \n\
55
+ [program:celery_live]\n\
56
+ command=celery -A escriptorium worker -l INFO -E -Ofair --prefetch-multiplier 1 -Q live -c 4 --max-tasks-per-child=10\n\
57
+ directory=/usr/src/app\n\
58
+ autostart=true\n\
59
+ autorestart=true\n\
60
  \n\
61
+ [program:celery_low_priority]\n\
62
+ command=celery -A escriptorium worker -l INFO -E -Ofair --prefetch-multiplier 1 -Q low-priority -c 4 --max-tasks-per-child=10\n\
63
+ directory=/usr/src/app\n\
64
+ autostart=true\n\
65
+ autorestart=true\n\
66
  \n\
67
+ [program:celery_gpu]\n\
68
+ command=celery -A escriptorium worker -l INFO -E -Ofair --prefetch-multiplier 1 -Q gpu -c 1 --max-tasks-per-child=1\n\
69
+ directory=/usr/src/app\n\
70
+ autostart=true\n\
71
+ autorestart=true\n\
72
+ ' > /etc/supervisor/conf.d/escriptorium.conf
73
 
74
+ # Create initialization script
75
  RUN echo '#!/bin/bash\n\
76
+ # Initialize database if needed\n\
77
+ if [ ! -f "/usr/src/app/.db_initialized" ]; then\n\
78
+ echo "Initializing database..."\n\
79
+ service postgresql start\n\
80
+ su - postgres -c "createuser -s root"\n\
81
+ su - postgres -c "createdb -O root escriptorium"\n\
82
+ python manage.py migrate\n\
83
+ python manage.py collectstatic --noinput\n\
84
+ touch /usr/src/app/.db_initialized\n\
85
+ fi\n\
 
 
 
 
 
 
86
  \n\
87
+ # Start all services using supervisor\n\
88
+ exec supervisord -c /etc/supervisor/supervisord.conf\n\
89
+ ' > /usr/src/app/start.sh && chmod +x /usr/src/app/start.sh
 
 
 
90
 
91
+ # Expose port 8080
92
  EXPOSE 8080
93
 
94
+ # Define volumes for persistence
95
+ VOLUME ["/usr/src/app/static", "/usr/src/app/media", "/var/lib/postgresql/data"]
96
+
97
+ # Set the entrypoint
98
+ CMD ["/usr/src/app/start.sh"]