From fcebe49f48e247d6e7a8110d35882c6d234406e5 Mon Sep 17 00:00:00 2001 From: pablohashescobar Date: Thu, 1 Dec 2022 22:59:06 +0530 Subject: [PATCH] build: update production file in backend remove unnecessary packages and add network configuration --- apiserver/Dockerfile | 16 +++++++--------- apiserver/plane/settings/production.py | 8 ++++---- docker-compose.yml | 17 ++++++++++++++--- 3 files changed, 25 insertions(+), 16 deletions(-) diff --git a/apiserver/Dockerfile b/apiserver/Dockerfile index c0057369c..967e34c5f 100644 --- a/apiserver/Dockerfile +++ b/apiserver/Dockerfile @@ -1,5 +1,7 @@ FROM python:3.8.14-alpine3.16 AS backend +# set environment variables +ENV PYTHONDONTWRITEBYTECODE 1 ENV PYTHONUNBUFFERED 1 WORKDIR /code @@ -20,12 +22,7 @@ RUN apk --update --no-cache --virtual .build-deps add \ "cargo~=1.60" \ "git~=2" \ "make~=4.3" \ - "libffi-dev~=3.4" \ - "libxml2-dev~=2.9" \ - "libxslt-dev~=1.1" \ - "xmlsec-dev~=1.2" \ "postgresql13-dev~=13" \ - "libmaxminddb~=1.6" \ && \ pip install -r requirements.txt --compile --no-cache-dir \ && \ @@ -45,12 +42,13 @@ COPY plane plane/ COPY templates templates/ COPY gunicorn.config.py ./ - -COPY bin/takeoff ./takeoff +USER root +RUN apk --update --no-cache add "bash~=5.1" +COPY ./bin ./bin/ USER captain # Expose container port and run entry point script EXPOSE 8000 -# ENTRYPOINT [ "./takeoff" ] -CMD python manage.py migrate && python manage.py rqworker & exec gunicorn plane.wsgi -k gthread --workers 8 --bind 0.0.0.0:8000 --config gunicorn.config.py --max-requests 10000 --max-requests-jitter 1000 --access-logfile - +CMD [ "./bin/takeoff" ] + diff --git a/apiserver/plane/settings/production.py b/apiserver/plane/settings/production.py index b98545292..ab84c36d5 100644 --- a/apiserver/plane/settings/production.py +++ b/apiserver/plane/settings/production.py @@ -14,9 +14,9 @@ DATABASES = { "default": { "ENGINE": "django.db.backends.postgresql_psycopg2", "NAME": "plane", - "USER": "", - "PASSWORD": "", - "HOST": "", + "USER": os.environ.get('PGUSER'), + "PASSWORD": os.environ.get('PGPASSWORD'), + "HOST": os.environ.get('PGHOST'), } } @@ -28,7 +28,7 @@ CORS_ORIGIN_WHITELIST = [ # "http://127.0.0.1:9000" ] # Parse database configuration from $DATABASE_URL -DATABASES["default"] = dj_database_url.config() +# DATABASES["default"] = dj_database_url.config() SITE_ID = 1 # Enable Connection Pooling (if desired) diff --git a/docker-compose.yml b/docker-compose.yml index a36487cb5..d4267c4f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -11,10 +11,14 @@ services: POSTGRES_DB: plane POSTGRES_PASSWORD: plane command: postgres -c 'max_connections=1000' + networks: + - app_network redis: image: redis:6.2.7-alpine restart: on-failure command: redis-server --maxmemory-policy allkeys-lru --maxmemory 200mb + networks: + - app_network plane_web: container_name: plane_web build: @@ -37,15 +41,22 @@ services: environment: SENTRY_DSN: $SENTRY_DSN WEB_URL: $WEB_URL - DATABASE_URL: postgres://plane:plane@db/plane - REDIS_URL: redis://redis + PGUSER: plane + PGPASSWORD: plane + PGHOST: db + REDIS_URL: 'redis://redis:6379/' + REDIS_HOST: redis + REDIS_PORT: 6379 SECRET_KEY: $SECRET_KEY networks: - app_network depends_on: - db - redis - command: python manage.py migrate && gunicorn plane.wsgi -k gthread --workers 8 --bind 0.0.0.0:8000 --config gunicorn.config.py --max-requests 10000 --max-requests-jitter 1000 --access-logfile - + command: ./bin/takeoff + links: + - db + - redis networks: app_network: external: true