Skip to content

Commit

Permalink
Merge pull request #1 from bmcho/feature/F5-Refresh#6-bmcho
Browse files Browse the repository at this point in the history
feat: django 설정 및 hello출력 가능 개발,  nginx 셋팅 (F5-Refresh#6)
  • Loading branch information
bmcho authored Jul 25, 2022
2 parents ca61c49 + 1d4b17d commit 7ee5b4a
Show file tree
Hide file tree
Showing 16 changed files with 280 additions and 3 deletions.
Empty file added apps/hello/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions apps/hello/admin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.contrib import admin

# Register your models here.
6 changes: 6 additions & 0 deletions apps/hello/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class HelloConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'apps.hello'
Empty file.
3 changes: 3 additions & 0 deletions apps/hello/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.db import models

# Create your models here.
3 changes: 3 additions & 0 deletions apps/hello/tests.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from django.test import TestCase

# Create your tests here.
8 changes: 8 additions & 0 deletions apps/hello/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index'),
]
7 changes: 7 additions & 0 deletions apps/hello/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.http import HttpResponse
from django.shortcuts import render

# Create your views here.
def index(request):
return HttpResponse("Hello")

32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.9"
services:
app:
container_name: app
build:
context: .
dockerfile: dockerfile
env_file: .env
volumes:
- .:/srv/server
restart: always
expose:
- "8000"
networks:
- nginx_bridge

nginx:
container_name: nginx
image: nginx:latest
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
restart: unless-stopped
ports:
- 80:80
depends_on:
- app
networks:
- nginx_bridge

networks:
nginx_bridge:
driver: bridge
20 changes: 20 additions & 0 deletions dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM python:3.9-slim-buster

ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1
ENV DOCKERIZE_VERSION v0.6.1

WORKDIR /srv/server

COPY . /srv/server

RUN apt update && \
apt install -y \
gcc gfortran musl-dev g++ bash wget

# 의존성 설치
RUN pip install --upgrade pip
RUN pip install -r requirements.txt


CMD ["gunicorn", "--bind", "0:8000", "ideaconcert.wsgi:application"]
15 changes: 14 additions & 1 deletion ideaconcert/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
https://docs.djangoproject.com/en/3.2/ref/settings/
"""

import os
from pathlib import Path
from django.core.exceptions import ImproperlyConfigured
from dotenv import find_dotenv, load_dotenv

load_dotenv(find_dotenv())

def get_env_variable(var_name):
try:
return os.environ[var_name]
except KeyError:
error_msg = f'Set the {var_name} environment variable'
raise ImproperlyConfigured(error_msg)

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent
Expand All @@ -20,7 +32,7 @@
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-_mq6zincrrt!36svw&1q79k5flvpi737=yx%frytkghp0xqbuo'
SECRET_KEY = get_env_variable('SECRET_KEY')

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
Expand All @@ -37,6 +49,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'apps.hello'
]

MIDDLEWARE = [
Expand Down
11 changes: 9 additions & 2 deletions ideaconcert/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,15 @@
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import path
from django.urls import include, path

urlpatterns = [

app_urls = [
path('admin/', admin.site.urls),
path('hello/', include('apps.hello.urls')),
]


urlpatterns = [
path('api/', include(app_urls)),
]
22 changes: 22 additions & 0 deletions nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
worker_processes auto;
events {
worker_connections 1024;
}

http{
upstream backend {
server app:8000;
}

server {
listen 80;

location / {
proxy_pass http://backend;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
}
129 changes: 129 additions & 0 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "ideaconcert"
version = "0.1.0"
description = ""
authors = ["None"]

[tool.poetry.dependencies]
python = "^3.8"
Django = "^4.0.6"
gunicorn = "^20.1.0"
python-dotenv = "^0.20.0"

[tool.poetry.dev-dependencies]

[build-system]
requires = ["poetry-core>=1.0.0"]
build-backend = "poetry.core.masonry.api"
7 changes: 7 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
asgiref==3.5.2; python_version >= "3.8"
backports.zoneinfo==0.2.1; python_version < "3.9" and python_version >= "3.8"
django==4.0.6; python_version >= "3.8"
gunicorn==20.1.0; python_version >= "3.5"
python-dotenv==0.20.0; python_version >= "3.5"
sqlparse==0.4.2; python_version >= "3.8"
tzdata==2022.1; sys_platform == "win32" and python_version >= "3.8"

0 comments on commit 7ee5b4a

Please sign in to comment.