diff --git a/aio/Dockerfile b/aio/Dockerfile index 950383cfe1a..b36624b1955 100644 --- a/aio/Dockerfile +++ b/aio/Dockerfile @@ -54,11 +54,14 @@ RUN yarn turbo run build # ***************************************************************************** # STAGE 3: Copy the project and start it # ***************************************************************************** +# FROM makeplane/plane-aio-base AS runner FROM makeplane/plane-aio-base:single-docker-image AS runner +USER root + WORKDIR /app -RUN mkdir -p /app/{web,space,admin,api} +SHELL [ "/bin/bash", "-c" ] COPY --from=installer /app/web/next.config.js ./web/ COPY --from=installer /app/web/package.json ./web/ @@ -107,7 +110,13 @@ ENV PIP_DISABLE_PIP_VERSION_CHECK=1 COPY apiserver/requirements.txt ./api/ COPY apiserver/requirements ./api/requirements -RUN pip install -r ./api/requirements.txt --compile --no-cache-dir + +RUN apt-get install python3.12-venv -y + +RUN python3 -m venv /app/venv && \ + source /app/venv/bin/activate && \ + /app/venv/bin/pip install --upgrade pip && \ + /app/venv/bin/pip install -r ./api/requirements.txt --compile --no-cache-dir # Add in Django deps and generate Django's static files COPY apiserver/manage.py ./api/manage.py @@ -119,7 +128,11 @@ COPY apiserver/bin ./api/bin/ RUN chmod +x ./api/bin/* RUN chmod -R 777 ./api/ +COPY aio/supervisord.conf /app/supervisord.conf + +RUN chown -R app-user:app-user /app + +USER app-user -COPY aio/supervisor.conf /app/supervisor.conf -CMD ["supervisord","-c","/app/supervisor.conf"] +CMD ["sudo", "/usr/bin/supervisord", "-c", "/app/supervisord.conf"] \ No newline at end of file diff --git a/aio/Dockerfile.base b/aio/Dockerfile.base index 0954c3b92d0..2147668a0c0 100644 --- a/aio/Dockerfile.base +++ b/aio/Dockerfile.base @@ -1,71 +1,86 @@ FROM --platform=$BUILDPLATFORM tonistiigi/binfmt as binfmt -FROM ubuntu:20.04 +FROM debian:12-slim -# Set environment variables for non-interactive installation +# Set environment variables to non-interactive for apt ENV DEBIAN_FRONTEND=noninteractive -# Update the package list and install dependencies -RUN apt-get update && apt-get install -y \ - wget \ - gnupg \ - lsb-release \ - software-properties-common \ - supervisor \ - nginx \ - curl \ - python3-pip \ - build-essential \ - libssl-dev \ - python3-dev \ - bzip2 \ - xz-utils \ - zlib1g \ - libpq-dev \ - libxml2-dev \ - libxslt1-dev \ - libpopt0 - -# Installing Postgres -RUN apt-get install -y postgresql postgresql-contrib - -# Install Redis -RUN apt-get install -y redis-server - -#Install Node 18 -RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ - apt-get install -y nodejs +SHELL [ "/bin/bash", "-c" ] -# # Install Python 3.11 -RUN add-apt-repository ppa:deadsnakes/ppa -y && \ +# Update the package list and install prerequisites +RUN apt-get update && \ + apt-get install -y \ + gnupg2 curl ca-certificates lsb-release software-properties-common \ + build-essential libssl-dev zlib1g-dev libbz2-dev libreadline-dev \ + libsqlite3-dev wget llvm libncurses5-dev libncursesw5-dev xz-utils \ + tk-dev libffi-dev liblzma-dev supervisor nginx nano vim ncdu + +# Install Redis 7.2 +RUN echo "deb http://deb.debian.org/debian $(lsb_release -cs)-backports main" > /etc/apt/sources.list.d/backports.list && \ + curl -fsSL 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 && \ apt-get update && \ - apt-get install -y python3.12 python3.12-dev python3.12-distutils && \ - update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.12 1 && \ - update-alternatives --install /usr/bin/python python /usr/bin/python3.12 1 && \ - update-alternatives --install /usr/bin/pip pip /usr/bin/pip3 1 + apt-get install -y redis-server + +# Install PostgreSQL 15 +RUN curl -fsSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | gpg --dearmor -o /usr/share/keyrings/pgdg-archive-keyring.gpg && \ + echo "deb [signed-by=/usr/share/keyrings/pgdg-archive-keyring.gpg] http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main" > /etc/apt/sources.list.d/pgdg.list && \ + apt-get update && \ + apt-get install -y postgresql-15 postgresql-client-15 # Install MinIO ARG TARGETARCH RUN if [ "$TARGETARCH" = "amd64" ]; then \ - wget https://dl.min.io/server/minio/release/linux-amd64/minio -O /usr/local/bin/minio; \ + curl -fSl https://dl.min.io/server/minio/release/linux-amd64/minio -o /usr/local/bin/minio; \ elif [ "$TARGETARCH" = "arm64" ]; then \ - wget https://dl.min.io/server/minio/release/linux-arm64/minio -O /usr/local/bin/minio; \ + curl -fSl https://dl.min.io/server/minio/release/linux-arm64/minio -o /usr/local/bin/minio; \ else \ echo "Unsupported architecture: $TARGETARCH"; exit 1; \ fi && \ chmod +x /usr/local/bin/minio -# Create necessary directories and set permissions -RUN mkdir -p /data/postgres /data/redis /data/minio && \ - chown -R postgres:postgres /data/postgres && \ - chown -R redis:redis /data/redis && \ - chown -R root:root /data/minio -COPY ./supervisor.base /app/supervisor.conf +# Install Node.js 18 +RUN curl -fsSL https://deb.nodesource.com/setup_18.x | bash - && \ + apt-get install -y nodejs + +# Install Python 3.12 from source +RUN cd /usr/src && \ + wget https://www.python.org/ftp/python/3.12.0/Python-3.12.0.tgz && \ + tar xzf Python-3.12.0.tgz && \ + cd Python-3.12.0 && \ + ./configure --enable-optimizations && \ + make altinstall && \ + rm -f /usr/src/Python-3.12.0.tgz + +# Clean up +RUN apt-get clean && \ + rm -rf /var/lib/apt/lists/* /usr/src/Python-3.12.0 + +WORKDIR /app + +RUN mkdir -p /app/{data,logs} && \ + mkdir -p /app/data/{redis,pg,minio,nginx} && \ + mkdir -p /app/logs/{access,error} && \ + mkdir -p /etc/supervisor/conf.d + +# Create Supervisor configuration file +COPY supervisord.base /app/supervisord.conf + +RUN apt-get update && \ + apt-get install -y sudo lsof net-tools && \ + apt-get clean + +# Add a new user 'app-user' and give sudo access +RUN useradd -m -s /bin/bash app-user && \ + echo 'app-user ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers + +RUN chown -R app-user:app-user /app -# Expose the necessary ports -EXPOSE 5432 6379 9001 80 443 +USER app-user -RUN mkdir -p /var/log/supervisord/ +# Expose ports for Redis, PostgreSQL, and MinIO +EXPOSE 6379 5432 9000 80 -CMD ["supervisord","-c","/app/supervisor.conf"] \ No newline at end of file +# Start Supervisor +CMD ["sudo", "/usr/bin/supervisord", "-c", "/app/supervisord.conf"] diff --git a/aio/supervisor.base b/aio/supervisor.base deleted file mode 100644 index 5e5729edbd0..00000000000 --- a/aio/supervisor.base +++ /dev/null @@ -1,33 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - -[program:postgresql] -command=/usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -user=postgres -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/postgresql.log -stderr_logfile=/var/log/supervisor/postgresql_err.log - -[program:redis] -command=/usr/bin/redis-server /etc/redis/redis.conf -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/redis.log -stderr_logfile=/var/log/supervisor/redis_err.log - -[program:minio] -command=/usr/local/bin/minio server /data/minio --console-address ":9001" -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/minio.log -stderr_logfile=/var/log/supervisor/minio_err.log - -[program:nginx] -command=/usr/sbin/nginx -g "daemon off;" -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/nginx.log -stderr_logfile=/var/log/supervisor/nginx_err.log diff --git a/aio/supervisor.conf b/aio/supervisor.conf deleted file mode 100644 index baee0526265..00000000000 --- a/aio/supervisor.conf +++ /dev/null @@ -1,75 +0,0 @@ -[supervisord] -nodaemon=true -logfile=/var/log/supervisor/supervisord.log -pidfile=/var/run/supervisord.pid - -[program:postgresql] -command=/usr/lib/postgresql/16/bin/postgres -D /var/lib/postgresql/16/main -user=postgres -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/postgresql.log -stderr_logfile=/var/log/supervisor/postgresql_err.log - -[program:redis] -command=/usr/bin/redis-server /etc/redis/redis.conf -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/redis.log -stderr_logfile=/var/log/supervisor/redis_err.log - -[program:minio] -command=/usr/local/bin/minio server /data/minio --console-address ":9001" -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/minio.log -stderr_logfile=/var/log/supervisor/minio_err.log - -[program:nginx] -command=/usr/sbin/nginx -g "daemon off;" -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/nginx.log -stderr_logfile=/var/log/supervisor/nginx_err.log - -[program:api] -command=/app/api/bin/docker-entrypoint-api.sh -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/api.log -stderr_logfile=/var/log/supervisor/api_err.log - -[program:worker] -command=/app/api/bin/docker-entrypoint-worker.sh -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/worker.log -stderr_logfile=/var/log/supervisor/worker_err.log - -[program:beat] -command=/app/api/bin/docker-entrypoint-beat.sh -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/beat.log -stderr_logfile=/var/log/supervisor/beat_err.log - -[program:web] -command=node /app/web/server.js -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/web.log -stderr_logfile=/var/log/supervisor/web_err.log - -[program:space] -command=node /app/space/server.js -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/space.log -stderr_logfile=/var/log/supervisor/space_err.log - -[program:admin] -command=node /app/admin/server.js -autostart=true -autorestart=true -stdout_logfile=/var/log/supervisor/admin.log -stderr_logfile=/var/log/supervisor/admin_err.log \ No newline at end of file diff --git a/aio/supervisord.base b/aio/supervisord.base new file mode 100644 index 00000000000..fe6a76e4124 --- /dev/null +++ b/aio/supervisord.base @@ -0,0 +1,37 @@ +[supervisord] +user=root +nodaemon=true +stderr_logfile=/app/logs/error/supervisor.err.log +stdout_logfile=/app/logs/access/supervisor.out.log + +[program:redis] +directory=/app/data/redis +command=redis-server +autostart=true +autorestart=true +stderr_logfile=/app/logs/error/redis.err.log +stdout_logfile=/app/logs/access/redis.out.log + +[program:postgresql] +user=postgres +command=/usr/lib/postgresql/15/bin/postgres --config-file=/etc/postgresql/15/main/postgresql.conf +autostart=true +autorestart=true +stderr_logfile=/app/logs/error/postgresql.err.log +stdout_logfile=/app/logs/access/postgresql.out.log + +[program:minio] +directory=/app/data/minio +command=minio server /app/data/minio +autostart=true +autorestart=true +stderr_logfile=/app/logs/error/minio.err.log +stdout_logfile=/app/logs/access/minio.out.log + +[program:nginx] +directory=/app/data/nginx +command=/usr/sbin/nginx -g 'daemon off;' +autostart=true +autorestart=true +stderr_logfile=/app/logs/error/nginx.err.log +stdout_logfile=/app/logs/access/nginx.out.log diff --git a/aio/supervisord.conf b/aio/supervisord.conf new file mode 100644 index 00000000000..ef74921e35d --- /dev/null +++ b/aio/supervisord.conf @@ -0,0 +1,86 @@ +[supervisord] +user=root +nodaemon=true +stdout_logfile=/app/logs/access/supervisor.log +stderr_logfile=/app/logs/error/supervisor.err.log + +[program:redis] +directory=/app/data/redis +command=redis-server +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/redis.log +stderr_logfile=/app/logs/error/redis.err.log + +[program:postgresql] +user=postgres +command=/usr/lib/postgresql/15/bin/postgres --config-file=/etc/postgresql/15/main/postgresql.conf +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/postgresql.log +stderr_logfile=/app/logs/error/postgresql.err.log + +[program:minio] +directory=/app/data/minio +command=minio server /app/data/minio +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/minio.log +stderr_logfile=/app/logs/error/minio.err.log + +[program:nginx] +directory=/app/data/nginx +command=/usr/sbin/nginx -g 'daemon off;' +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/nginx.log +stderr_logfile=/app/logs/error/nginx.err.log + +[program:api] +command=/app/api/bin/aio.sh api +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/api.log +stderr_logfile=/app/logs/error/api_err.log + +[program:migrator] +command=/app/api/bin/aio.sh migrator +autostart=true +autorestart=false +stdout_logfile=/app/logs/access/migrator.log +stderr_logfile=/app/logs/error/migrator_err.log + +[program:worker] +command=/app/api/bin/aio.sh worker +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/worker.log +stderr_logfile=/app/logs/error/worker_err.log + +[program:beat] +command=/app/api/bin/aio.sh beat +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/beat.log +stderr_logfile=/app/logs/error/beat_err.log + +[program:web] +command=node /app/web/server.js +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/web.log +stderr_logfile=/app/logs/error/web_err.log + +[program:space] +command=node /app/space/server.js +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/space.log +stderr_logfile=/app/logs/error/space_err.log + +[program:admin] +command=node /app/admin/server.js +autostart=true +autorestart=true +stdout_logfile=/app/logs/access/admin.log +stderr_logfile=/app/logs/error/admin_err.log \ No newline at end of file diff --git a/apiserver/bin/aio.sh b/apiserver/bin/aio.sh new file mode 100644 index 00000000000..3aaaada4d89 --- /dev/null +++ b/apiserver/bin/aio.sh @@ -0,0 +1,18 @@ +#!/bin/bash +set -e + +source /app/venv/bin/activate +cd /app/api + +if [ "$1" = 'api' ]; then + source /app/api/bin/docker-entrypoint-api.sh +elif [ "$1" = 'worker' ]; then + source /app/api/bin/docker-entrypoint-worker.sh +elif [ "$1" = 'beat' ]; then + source /app/api/bin/docker-entrypoint-beat.sh +elif [ "$1" = 'migrator' ]; then + source /app/api/bin/docker-entrypoint-migrator.sh +else + echo "Command not found" + exit 1 +fi \ No newline at end of file