Spaces:
Sleeping
Sleeping
| FROM ubuntu:22.04 | |
| # Prevent interactive prompts during build | |
| ENV DEBIAN_FRONTEND=noninteractive | |
| # 1. Install system dependencies | |
| RUN apt-get update && apt-get install -y \ | |
| openjdk-21-jdk \ | |
| supervisor \ | |
| netcat-traditional \ | |
| wget \ | |
| gnupg \ | |
| lsb-release \ | |
| curl \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 2. Add Official Repositories (PostgreSQL 18 & Redis Stack) | |
| RUN install -d /usr/share/postgresql-common/pgdg && \ | |
| curl -o /usr/share/postgresql-common/pgdg/apt.postgresql.org.asc --fail https://www.postgresql.org/media/keys/ACCC4CF8.asc && \ | |
| echo "deb [signed-by=/usr/share/postgresql-common/pgdg/apt.postgresql.org.asc] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ | |
| wget -O- https://packages.redis.io/gpg | gpg --dearmor -o /usr/share/keyrings/redis-archive-keyring.gpg && \ | |
| echo "deb [signed-by=/usr/share/keyrings/redis-archive-keyring.gpg] https://packages.redis.io/deb $(lsb_release -cs) main" > /etc/apt/sources.list.d/redis.list | |
| # 3. Install Services | |
| RUN apt-get update && apt-get install -y \ | |
| postgresql-18 \ | |
| redis-stack-server \ | |
| && rm -rf /var/lib/apt/lists/* | |
| # 4. Initialize PostgreSQL 18 | |
| # We run this as the postgres user to set the password and create the DB | |
| USER postgres | |
| RUN /etc/init.d/postgresql start && \ | |
| psql --command "ALTER USER postgres WITH PASSWORD 'pass';" && \ | |
| createdb SwipeTrip | |
| USER root | |
| # 5. Configure Supervisor for Process Management and Logging | |
| RUN mkdir -p /var/log/supervisor | |
| COPY <<EOF /etc/supervisor/conf.d/supervisord.conf | |
| [supervisord] | |
| nodaemon=true | |
| user=root | |
| logfile=/dev/null | |
| logfile_maxbytes=0 | |
| [program:postgresql] | |
| command=/usr/lib/postgresql/18/bin/postgres -D /var/lib/postgresql/18/main -c config_file=/etc/postgresql/18/main/postgresql.conf | |
| user=postgres | |
| autorestart=true | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 | |
| [program:redis] | |
| command=/usr/bin/redis-stack-server --port 6379 | |
| user=root | |
| autorestart=true | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 | |
| [program:java-app] | |
| # Wait for Postgres (5432) and Redis (6379) to be ready before starting Java | |
| command=/bin/sh -c "while ! nc -z localhost 5432; do sleep 1; done; while ! nc -z localhost 6379; do sleep 1; done; java -XX:+EnableDynamicAgentLoading -jar /app/app.jar --server.port=7860" | |
| user=root | |
| autorestart=false | |
| stdout_logfile=/dev/stdout | |
| stdout_logfile_maxbytes=0 | |
| stderr_logfile=/dev/stderr | |
| stderr_logfile_maxbytes=0 | |
| EOF | |
| # 6. Finalize Application | |
| WORKDIR /app | |
| COPY api-0.0.1-SNAPSHOT.jar app.jar | |
| EXPOSE 7860 | |
| # Start Supervisor to manage all three processes | |
| CMD ["/usr/bin/supervisord", "-c", "/etc/supervisor/conf.d/supervisord.conf"] |