Skip to content

Commit

Permalink
finalize the dockerfiles with volume exposure
Browse files Browse the repository at this point in the history
  • Loading branch information
mguptahub committed May 27, 2024
1 parent e7f72ec commit 985660b
Show file tree
Hide file tree
Showing 8 changed files with 252 additions and 117 deletions.
87 changes: 46 additions & 41 deletions aio/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -63,23 +63,50 @@ WORKDIR /app

SHELL [ "/bin/bash", "-c" ]

# PYTHON APPLICATION SETUP

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

COPY apiserver/requirements.txt ./api/
COPY apiserver/requirements ./api/requirements

RUN python3.12 -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
COPY apiserver/plane ./api/plane/
COPY apiserver/templates ./api/templates/
COPY package.json ./api/package.json

COPY apiserver/bin ./api/bin/

RUN chmod +x ./api/bin/*
RUN chmod -R 777 ./api/

# NEXTJS BUILDS

COPY --from=installer /app/web/next.config.js ./web/
COPY --from=installer /app/web/package.json ./web/
COPY --from=installer /app/web/.next/standalone ./web
COPY --from=installer /app/web/.next/static ./web/.next/static
COPY --from=installer /app/web/public ./web/public
COPY --from=installer /app/web/.next/static ./web/web/.next/static
COPY --from=installer /app/web/public ./web/web/public

COPY --from=installer /app/space/next.config.js ./space/
COPY --from=installer /app/space/package.json ./space/
COPY --from=installer /app/space/.next/standalone ./space
COPY --from=installer /app/space/.next/static ./space/.next/static
COPY --from=installer /app/space/public ./space/public
COPY --from=installer /app/space/.next/static ./space/space/.next/static
COPY --from=installer /app/space/public ./space/space/public

COPY --from=installer /app/admin/next.config.js ./admin/
COPY --from=installer /app/admin/package.json ./admin/
COPY --from=installer /app/admin/.next/standalone ./admin
COPY --from=installer /app/admin/.next/static ./admin/.next/static
COPY --from=installer /app/admin/public ./admin/public
COPY --from=installer /app/admin/.next/static ./admin/admin/.next/static
COPY --from=installer /app/admin/public ./admin/admin/public

ARG NEXT_PUBLIC_API_BASE_URL=""
ENV NEXT_PUBLIC_API_BASE_URL=$NEXT_PUBLIC_API_BASE_URL
Expand All @@ -102,45 +129,23 @@ ENV NEXT_PUBLIC_WEB_BASE_URL=$NEXT_PUBLIC_WEB_BASE_URL
ENV NEXT_TELEMETRY_DISABLED 1
ENV TURBO_TELEMETRY_DISABLED 1

COPY aio/supervisord.conf /app/supervisord.conf

# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV PIP_DISABLE_PIP_VERSION_CHECK=1

COPY apiserver/requirements.txt ./api/
COPY apiserver/requirements ./api/requirements

# RUN python3.12 -m pip install --upgrade pip

# RUN echo "alias python=/usr/local/bin/python3.12" >> ~/.bashrc && \
# echo "alias pip=/usr/local/bin/pip3.12" >> ~/.bashrc

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
COPY apiserver/plane ./api/plane/
COPY apiserver/templates ./api/templates/

COPY apiserver/bin ./api/bin/
COPY aio/aio.sh /app/aio.sh
RUN chmod +x /app/aio.sh

RUN chmod +x ./api/bin/*
RUN chmod -R 777 ./api/
COPY aio/pg-setup.sh /app/pg-setup.sh
RUN chmod +x /app/pg-setup.sh

COPY aio/supervisord.conf /app/supervisord.conf
COPY deploy/selfhost/variables.env /app/plane.env

RUN chown -R app-user:app-user /app
# NGINX Conf Copy
COPY ./aio/nginx.conf.aio /etc/nginx/nginx.conf.template
COPY ./nginx/env.sh /app/nginx-start.sh
RUN chmod +x /app/nginx-start.sh

USER app-user
RUN ./pg-setup.sh

# RUN echo "alias python=/usr/local/bin/python3.12" >> ~/.bashrc && \
# echo "alias pip=/usr/local/bin/pip3.12" >> ~/.bashrc
VOLUME [ "/app/data/minio/uploads", "/var/lib/postgresql/data" ]

CMD ["sudo", "/usr/bin/supervisord", "-c", "/app/supervisord.conf"]
CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"]
18 changes: 8 additions & 10 deletions aio/Dockerfile.base
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,13 @@ RUN echo "deb http://deb.debian.org/debian $(lsb_release -cs)-backports main" >
apt-get install -y redis-server

# Install PostgreSQL 15
ENV POSTGRES_VERSION 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
apt-get install -y postgresql-$POSTGRES_VERSION postgresql-client-$POSTGRES_VERSION && \
mkdir -p /var/lib/postgresql/data && \
chown -R postgres:postgres /var/lib/postgresql

# Install MinIO
ARG TARGETARCH
Expand Down Expand Up @@ -73,16 +76,11 @@ RUN mkdir -p /app/{data,logs} && \
COPY supervisord.base /app/supervisord.conf

RUN apt-get update && \
apt-get install -y sudo lsof net-tools libpq-dev && \
apt-get install -y sudo lsof net-tools libpq-dev procps gettext && \
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

USER app-user
RUN sudo -u postgres /usr/lib/postgresql/$POSTGRES_VERSION/bin/initdb -D /var/lib/postgresql/data
COPY postgresql.conf /etc/postgresql/postgresql.conf

RUN echo "alias python=/usr/local/bin/python3.12" >> ~/.bashrc && \
echo "alias pip=/usr/local/bin/pip3.12" >> ~/.bashrc
Expand All @@ -91,4 +89,4 @@ RUN echo "alias python=/usr/local/bin/python3.12" >> ~/.bashrc && \
EXPOSE 6379 5432 9000 80

# Start Supervisor
CMD ["sudo", "/usr/bin/supervisord", "-c", "/app/supervisord.conf"]
CMD ["/usr/bin/supervisord", "-c", "/app/supervisord.conf"]
30 changes: 30 additions & 0 deletions aio/aio.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/bin/bash
set -e


if [ "$1" = 'api' ]; then
source /app/venv/bin/activate
cd /app/api
exec ./bin/docker-entrypoint-api.sh
elif [ "$1" = 'worker' ]; then
source /app/venv/bin/activate
cd /app/api
exec ./bin/docker-entrypoint-worker.sh
elif [ "$1" = 'beat' ]; then
source /app/venv/bin/activate
cd /app/api
exec ./bin/docker-entrypoint-beat.sh
elif [ "$1" = 'migrator' ]; then
source /app/venv/bin/activate
cd /app/api
exec ./bin/docker-entrypoint-migrator.sh
elif [ "$1" = 'web' ]; then
node /app/web/web/server.js
elif [ "$1" = 'space' ]; then
node /app/space/space/server.js
elif [ "$1" = 'admin' ]; then
node /app/admin/admin/server.js
else
echo "Command not found"
exit 1
fi
73 changes: 73 additions & 0 deletions aio/nginx.conf.aio
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
events {
}

http {
sendfile on;

server {
listen 80;
root /www/data/;
access_log /var/log/nginx/access.log;

client_max_body_size ${FILE_SIZE_LIMIT};

add_header X-Content-Type-Options "nosniff" always;
add_header Referrer-Policy "no-referrer-when-downgrade" always;
add_header Permissions-Policy "interest-cohort=()" always;
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Forwarded-Proto "${dollar}scheme";
add_header X-Forwarded-Host "${dollar}host";
add_header X-Forwarded-For "${dollar}proxy_add_x_forwarded_for";
add_header X-Real-IP "${dollar}remote_addr";

location / {
proxy_http_version 1.1;
proxy_set_header Upgrade ${dollar}http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host ${dollar}http_host;
proxy_pass http://localhost:3001/;
}

location /spaces/ {
rewrite ^/spaces/?$ /spaces/login break;
proxy_http_version 1.1;
proxy_set_header Upgrade ${dollar}http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host ${dollar}http_host;
proxy_pass http://localhost:3002/spaces/;
}


location /god-mode/ {
proxy_http_version 1.1;
proxy_set_header Upgrade ${dollar}http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host ${dollar}http_host;
proxy_pass http://localhost:3003/god-mode/;
}

location /api/ {
proxy_http_version 1.1;
proxy_set_header Upgrade ${dollar}http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host ${dollar}http_host;
proxy_pass http://localhost:8000/api/;
}

location /auth/ {
proxy_http_version 1.1;
proxy_set_header Upgrade ${dollar}http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host ${dollar}http_host;
proxy_pass http://localhost:8000/auth/;
}

location /${BUCKET_NAME}/ {
proxy_http_version 1.1;
proxy_set_header Upgrade ${dollar}http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host ${dollar}http_host;
proxy_pass http://localhost:9000/uploads/;
}
}
}
14 changes: 14 additions & 0 deletions aio/pg-setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#!/bin/bash


# Variables
set -o allexport
source plane.env set
set +o allexport

PGHOST=localhost

sudo -u postgres /usr/lib/postgresql/${POSTGRES_VERSION}/bin/pg_ctl -D /var/lib/postgresql/data start
sudo -u postgres /usr/lib/postgresql/${POSTGRES_VERSION}/bin/psql --command "CREATE USER $POSTGRES_USER WITH SUPERUSER PASSWORD '$POSTGRES_PASSWORD';" && \
sudo -u postgres /usr/lib/postgresql/${POSTGRES_VERSION}/bin/createdb -O $POSTGRES_USER $POSTGRES_DB && \
sudo -u postgres /usr/lib/postgresql/${POSTGRES_VERSION}/bin/pg_ctl -D /var/lib/postgresql/data stop
12 changes: 12 additions & 0 deletions aio/postgresql.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# PostgreSQL configuration file

# Allow connections from any IP address
listen_addresses = '*'

# Set the maximum number of connections
max_connections = 100

# Set the shared buffers size
shared_buffers = 128MB

# Other custom configurations can be added here
Loading

0 comments on commit 985660b

Please sign in to comment.