diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 730191b..6e2d10e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -27,6 +27,6 @@ jobs: DJANGO_ALLOWED_HOSTS: ${{ secrets.DJANGO_ALLOWED_HOSTS }} run: | cd app - python manage.py makemigrations --settings=cspc_web.settings_dev - python manage.py migrate --settings=cspc_web.settings_dev - python manage.py test --settings=cspc_web.settings_dev + python manage.py makemigrations + python manage.py migrate + python manage.py test diff --git a/app/Dockerfile-dev b/app/Dockerfile-dev new file mode 100644 index 0000000..7e4d888 --- /dev/null +++ b/app/Dockerfile-dev @@ -0,0 +1,29 @@ +FROM python:3.8.13 + +# 환경 변수 설정 +ENV HOME=/home/app +ENV APP_HOME=/home/app/web + + +# 애플리케이션 디렉터리 생성 +RUN mkdir -p $APP_HOME +WORKDIR $APP_HOME + +# 파이썬 실행 관련 환경 변수 +ENV PYTHONDONTWRITEBYTECODE 1 +ENV PYTHONUNBUFFERED 1 + +# requirements.txt 복사 및 설치 +COPY ./requirements.txt $APP_HOME/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 $APP_HOME/.env + +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 0fb604e..47d96a3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -27,6 +27,15 @@ services: - postgres_data:/var/lib/postgresql/data/ env_file: - ./.env.db + dev_api: + build: + context: ./app + dockerfile: Dockerfile-dev + command: python manage.py runserver 0.0.0.0:8000 --settings=cspc_web.settings_dev + volumes: + - ./app/db:/home/app/web/db + ports: + - "8005:8000" volumes: postgres_data: static_volunme: \ No newline at end of file