From ea9f073be34e5e72363df6709acff6fcc510499a Mon Sep 17 00:00:00 2001 From: ljy2855 Date: Thu, 15 Feb 2024 00:46:15 +0900 Subject: [PATCH] build: sepertate dev dockerfile, entrypoint script --- app/Dockerfile-dev | 12 ++++++++---- app/cspc_web/settings_dev.py | 19 +++++++++++++------ app/entrypoint-dev.sh | 8 ++++++++ docker-compose.yml | 4 ++-- 4 files changed, 31 insertions(+), 12 deletions(-) create mode 100644 app/entrypoint-dev.sh diff --git a/app/Dockerfile-dev b/app/Dockerfile-dev index ee8d5de..7e4d888 100644 --- a/app/Dockerfile-dev +++ b/app/Dockerfile-dev @@ -15,11 +15,15 @@ ENV PYTHONUNBUFFERED 1 # requirements.txt 복사 및 설치 COPY ./requirements.txt $APP_HOME/requirements.txt -RUN pip install --no-cache-dir --upgrade -r requirements.txt +RUN pip install --no-cache-dir --upgrade pip && \ + pip install --no-cache-dir --upgrade -r requirements.txt # .env 파일을 제외하고 모든 파일 복사 COPY . $APP_HOME -RUN rm -f .env # 혹시나 .env 파일이 복사되었다면 제거 +RUN rm -f $APP_HOME/.env -RUN python manage.py makemigrations -RUN python manage.py migrate \ No newline at end of file +RUN sed -i 's/\r$//g' $APP_HOME/entrypoint-dev.sh + +RUN chmod +x $APP_HOME/entrypoint-dev.sh + +ENTRYPOINT [ "/home/app/web/entrypoint-dev.sh" ] \ No newline at end of file diff --git a/app/cspc_web/settings_dev.py b/app/cspc_web/settings_dev.py index c2f355a..ecc7d12 100644 --- a/app/cspc_web/settings_dev.py +++ b/app/cspc_web/settings_dev.py @@ -13,6 +13,7 @@ import os from pathlib import Path from dotenv import load_dotenv +from django.core.management.utils import get_random_secret_key # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -23,12 +24,18 @@ # See https://docs.djangoproject.com/en/4.1/howto/deployment/checklist/ # SECURITY WARNING: keep the secret key used in production secret! -SECRET_KEY = os.environ.get('SECRET_KEY') +if os.environ.get("SECRET_KEY", None) == None: + random_key = get_random_secret_key() + f = open(".env", "a") + f.write(f"SECRET_KEY={random_key}") + SECRET_KEY = random_key +else: + SECRET_KEY = os.environ.get("SECRET_KEY") # SECURITY WARNING: don't run with debug turned on in production! DEBUG = True -ALLOWED_HOSTS = os.environ.get("DJANGO_ALLOWED_HOSTS").split(" ") +ALLOWED_HOSTS = ["*"] REST_FRAMEWORK = { @@ -104,7 +111,7 @@ DATABASES = { 'default': { "ENGINE": "django.db.backends.sqlite3", - "NAME": "db.sqlite3" + "NAME": "db/db.sqlite3" } } @@ -130,9 +137,9 @@ ] CSRF_TRUSTED_ORIGINS = [ - 'https://apply.cspc.me', - 'http://localhost:8000', - ] + 'http://dev.cspc.me', + 'https://dev.cspc.me' +] # Internationalization # https://docs.djangoproject.com/en/4.1/topics/i18n/ diff --git a/app/entrypoint-dev.sh b/app/entrypoint-dev.sh new file mode 100644 index 0000000..551fec4 --- /dev/null +++ b/app/entrypoint-dev.sh @@ -0,0 +1,8 @@ +#!/bin/sh + + +python manage.py makemigrations --settings=cspc_web.settings_dev +python manage.py migrate --no-input --settings=cspc_web.settings_dev + + +exec "$@" \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 8bcb18f..47d96a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -31,9 +31,9 @@ services: build: context: ./app dockerfile: Dockerfile-dev - command: python manage.py runserver 0.0.0.0:8000 + command: python manage.py runserver 0.0.0.0:8000 --settings=cspc_web.settings_dev volumes: - - ./app/db.sqlite3:/home/app/web/db.sqlite3 + - ./app/db:/home/app/web/db ports: - "8005:8000" volumes: