From 3d14d227a746fdda92e1c75bb9203c33aa3feec9 Mon Sep 17 00:00:00 2001 From: Keannu Bernasol Date: Fri, 30 Aug 2024 21:57:49 +0800 Subject: [PATCH] Simplify startup script --- .woodpecker.yml | 4 ++-- Dockerfile | 5 ----- docker-compose.prod.yml => docker-compose.demo.yml | 7 +++---- start.sh | 6 ++---- 4 files changed, 7 insertions(+), 15 deletions(-) rename docker-compose.prod.yml => docker-compose.demo.yml (93%) diff --git a/.woodpecker.yml b/.woodpecker.yml index 456fc99..582610e 100644 --- a/.woodpecker.yml +++ b/.woodpecker.yml @@ -24,9 +24,9 @@ steps: - echo -e "Host *\n\tStrictHostKeyChecking no\n\n" > /root/.ssh/config - ssh root@10.0.10.4 ' cd "/mnt/nvme/files/docker projects/DRF-Template"; - docker-compose down; + docker-compose -f docker-compose.demo.yml down; docker image rm git.keannu1.duckdns.org/keannu125/drf_template || true; docker pull git.keannu1.duckdns.org/keannu125/drf_template:latest; docker volume rm "git.keannu1.duckdns.org/keannu125/drf_template_db_data" || true; - docker compose up -f docker-compose.prod.yml -d;' + docker compose -f docker-compose.demo.yml up -d;' secrets: [SSH_KEY] diff --git a/Dockerfile b/Dockerfile index d8b7454..c9b61e1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -3,13 +3,8 @@ FROM python:3.11.4-bookworm ENV PYTHONBUFFERED 1 ENV DEBIAN_FRONTEND noninteractive -RUN mkdir /code WORKDIR /code -# Directory mirroring -ADD . /code/ COPY . /code/ -COPY start.sh /code/ -RUN chmod +x /code/start.sh # Install packages RUN apt-get update && apt-get install -y graphviz libgraphviz-dev graphviz-dev wget zip diff --git a/docker-compose.prod.yml b/docker-compose.demo.yml similarity index 93% rename from docker-compose.prod.yml rename to docker-compose.demo.yml index 2c61d86..06dfa37 100644 --- a/docker-compose.prod.yml +++ b/docker-compose.demo.yml @@ -6,12 +6,12 @@ services: env_file: .env image: git.keannu1.duckdns.org/keannu125/drf_template:latest ports: - - "${BACKEND_PORT}:${BACKEND_PORT}" + - "${BACKEND_PORT}:8000" environment: - PYTHONBUFFERED=1 - RUN_TYPE=web volumes: - - .:/code + - ./backend/static:/backend/static depends_on: - postgres @@ -22,7 +22,6 @@ services: - RUN_TYPE=worker image: git.keannu1.duckdns.org/keannu125/drf_template:latest volumes: - - .:/code - ./chrome:/chrome - ./firefox:/firefox - ./dumps:/dumps @@ -30,7 +29,7 @@ services: - django - postgres - redis - ## Runs multiple worker instances + # Run multiple worker instances scale: 4 # Django Celery Beat diff --git a/start.sh b/start.sh index 2158447..84c85a0 100644 --- a/start.sh +++ b/start.sh @@ -1,8 +1,6 @@ #!/bin/bash # read .env values awk -F= '$1 == "BACKEND_DEBUG" {print $2}' .env -awk -F= '$1 == "BACKEND_PORT" {print $2}' .env -awk -F= '$1 == "CELERY_FLOWER_PORT" {print $2}' .env echo "Running as: $RUN_TYPE" cd backend/ @@ -15,9 +13,9 @@ if [ "$RUN_TYPE" = "web" ]; then python manage.py collectstatic --noinput fi if [ "$BACKEND_DEBUG" = 'True' ]; then - python manage.py runserver "0.0.0.0:${BACKEND_PORT:-8000}" + python manage.py runserver "0.0.0.0:8000" else - python -m granian --host 0.0.0.0 --port "${BACKEND_PORT:-8000}" --workers 8 --interface wsgi config.wsgi:application + python -m granian --host 0.0.0.0 --port 8000 --workers 8 --interface wsgi config.wsgi:application fi elif [ "$RUN_TYPE" = "worker" ]; then celery -A config worker -l INFO -E --concurrency 1