Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified .DS_Store
Binary file not shown.
96 changes: 48 additions & 48 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,51 +1,5 @@
# 배포용

FROM python:3.11-alpine3.19

# LABEL 명령어는 이미지에 메타데이터를 추가합니다. 여기서는 이미지의 유지 관리자를 "dayeonkim"로 지정하고 있습니다.
LABEL maintainer="frog"

# 환경 변수 PYTHONUNBUFFERED를 1로 설정합니다.
# 이는 Python이 표준 입출력 버퍼링을 비활성화하게 하여, 로그가 즉시 콘솔에 출력되게 합니다.
# 이는 Docker 컨테이너에서 로그를 더 쉽게 볼 수 있게 합니다.
ENV PYTHONUNBUFFERED 1

# 로컬 파일 시스템의 requirements.txt 파일을 컨테이너의 /tmp/requirements.txt로 복사합니다.
# 이 파일은 필요한 Python 패키지들을 명시합니다.
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./potato_project /app
WORKDIR /app
EXPOSE 8000

ARG DEV=false

RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /tmp/requirements.txt && \
apk add --update --no-cache postgresql-client jpeg-dev && \
apk add --update --no-cache --virtual .tmp-build-deps \
build-base postgresql-dev musl-dev zlib zlib-dev linux-headers && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
apk del .tmp-build-deps && \
adduser \
--disabled-password \
--no-create-home \
django-user

ENV PATH="/py/bin:$PATH"

USER django-user

# 이 명령어를 추가하여 pytest를 설치합니다.
RUN /py/bin/pip install pytest pytest-django


# 개발용

# FROM python:3.11-alpine3.19

# # LABEL 명령어는 이미지에 메타데이터를 추가합니다. 여기서는 이미지의 유지 관리자를 "dayeonkim"로 지정하고 있습니다.
Expand All @@ -56,7 +10,6 @@ RUN /py/bin/pip install pytest pytest-django
# # 이는 Docker 컨테이너에서 로그를 더 쉽게 볼 수 있게 합니다.
# ENV PYTHONUNBUFFERED 1


# # 로컬 파일 시스템의 requirements.txt 파일을 컨테이너의 /tmp/requirements.txt로 복사합니다.
# # 이 파일은 필요한 Python 패키지들을 명시합니다.
# COPY ./requirements.txt /tmp/requirements.txt
Expand Down Expand Up @@ -88,4 +41,51 @@ RUN /py/bin/pip install pytest pytest-django
# USER django-user

# # 이 명령어를 추가하여 pytest를 설치합니다.
# RUN /py/bin/pip install pytest pytest-django
# RUN /py/bin/pip install pytest pytest-django


# 개발용

FROM python:3.11-alpine3.19

# LABEL 명령어는 이미지에 메타데이터를 추가합니다. 여기서는 이미지의 유지 관리자를 "dayeonkim"로 지정하고 있습니다.
LABEL maintainer="frog"

# 환경 변수 PYTHONUNBUFFERED를 1로 설정합니다.
# 이는 Python이 표준 입출력 버퍼링을 비활성화하게 하여, 로그가 즉시 콘솔에 출력되게 합니다.
# 이는 Docker 컨테이너에서 로그를 더 쉽게 볼 수 있게 합니다.
ENV PYTHONUNBUFFERED 1


# 로컬 파일 시스템의 requirements.txt 파일을 컨테이너의 /tmp/requirements.txt로 복사합니다.
# 이 파일은 필요한 Python 패키지들을 명시합니다.
COPY ./requirements.txt /tmp/requirements.txt
COPY ./requirements.dev.txt /tmp/requirements.dev.txt
COPY ./potato_project /app
WORKDIR /app
EXPOSE 8000

ARG DEV=false

RUN python -m venv /py && \
/py/bin/pip install --upgrade pip && \
/py/bin/pip install -r /tmp/requirements.txt && \
apk add --update --no-cache postgresql-client jpeg-dev && \
apk add --update --no-cache --virtual .tmp-build-deps \
build-base postgresql-dev musl-dev zlib zlib-dev linux-headers && \
if [ $DEV = "true" ]; \
then /py/bin/pip install -r /tmp/requirements.dev.txt ; \
fi && \
rm -rf /tmp && \
apk del .tmp-build-deps && \
adduser \
--disabled-password \
--no-create-home \
django-user

ENV PATH="/py/bin:$PATH"

USER django-user

# 이 명령어를 추가하여 pytest를 설치합니다.
RUN /py/bin/pip install pytest pytest-django
92 changes: 46 additions & 46 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,35 +1,6 @@
# 배포용

# version: "3.11"
services:
app:
build:
context: .
args:
- DEV=true
ports:
- "8000:8000"
- "3000:3000" # debugger
volumes:
- ./potato_project:/app
command: >
sh -c "python manage.py wait_for_db &&
python manage.py makemigrations &&
python manage.py migrate &&
python manage.py runserver --noreload 0.0.0.0:8000"
environment:
- DB_HOST=${DB_HOST}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- PYDEVD_DISABLE_FILE_VALIDATION=1
env_file:
- .env


# 개발용

# # version: "3.11"
# services:
# app:
# build:
Expand All @@ -44,31 +15,47 @@ services:
# command: >
# sh -c "python manage.py wait_for_db &&
# python manage.py makemigrations &&
# python manage.py migrate &&
# python -u manage.py runserver --noreload 0.0.0.0:8000"
# python manage.py migrate &&
# python manage.py runserver --noreload 0.0.0.0:8000"
# environment:
# - DB_HOST=${DB_HOST}
# - DB_NAME=${DB_NAME}
# - DB_USER=${DB_USER}
# - DB_PASSWORD=${DB_PASSWORD}
# - PYDEVD_DISABLE_FILE_VALIDATION=1
# env_file:
# - .env
# depends_on:
# - db

# - .env

# db: # PostgreSQL Database
# image: postgres:16-alpine
# volumes:
# - ./data/db:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=${POSTGRES_DB}
# - POSTGRES_USER=${POSTGRES_USER}
# - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
# env_file:
# - .env

# 개발용

#version: "3.11"
services:
app:
build:
context: .
args:
- DEV=true
ports:
- "8000:8000"
- "3000:3000" # debugger
volumes:
- ./potato_project:/app
command: >
sh -c "python manage.py wait_for_db &&
python manage.py makemigrations &&
python manage.py migrate &&
python -u manage.py runserver --noreload 0.0.0.0:8000"
environment:
- DB_HOST=${DB_HOST}
- DB_NAME=${DB_NAME}
- DB_USER=${DB_USER}
- DB_PASSWORD=${DB_PASSWORD}
- PYDEVD_DISABLE_FILE_VALIDATION=1
env_file:
- .env
depends_on:
- db


db: # PostgreSQL Database
Expand All @@ -80,4 +67,17 @@ services:
- POSTGRES_USER=${POSTGRES_USER}
- POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
env_file:
- .env
- .env



# db: # PostgreSQL Database
# image: postgres:16-alpine
# volumes:
# - ./data/db:/var/lib/postgresql/data
# environment:
# - POSTGRES_DB=${POSTGRES_DB}
# - POSTGRES_USER=${POSTGRES_USER}
# - POSTGRES_PASSWORD=${POSTGRES_PASSWORD}
# env_file:
# - .env
36 changes: 18 additions & 18 deletions potato_project/app/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,30 +107,30 @@
# 배포용

# 데이터베이스 설정
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": os.environ.get("RDS_HOSTNAME"),
"NAME": os.environ.get("RDS_DB_NAME"),
"USER": os.environ.get("RDS_USERNAME"),
"PASSWORD": os.environ.get("RDS_PASSWORD"),
"PORT": os.environ.get("RDS_PORT", 5432),
}
}

# 개발용

# # 데이터베이스 설정
# DATABASES = {
# "default": {
# "ENGINE": "django.db.backends.postgresql",
# "HOST": os.environ.get("DB_HOST"),
# "NAME": os.environ.get("DB_NAME"),
# "USER": os.environ.get("DB_USER"),
# "PASSWORD": os.environ.get("DB_PASSWORD"),
# "HOST": os.environ.get("RDS_HOSTNAME"),
# "NAME": os.environ.get("RDS_DB_NAME"),
# "USER": os.environ.get("RDS_USERNAME"),
# "PASSWORD": os.environ.get("RDS_PASSWORD"),
# "PORT": os.environ.get("RDS_PORT", 5432),
# }
# }

# 개발용

# 데이터베이스 설정
DATABASES = {
"default": {
"ENGINE": "django.db.backends.postgresql",
"HOST": os.environ.get("DB_HOST"),
"NAME": os.environ.get("DB_NAME"),
"USER": os.environ.get("DB_USER"),
"PASSWORD": os.environ.get("DB_PASSWORD"),
}
}

# 비밀번호 검증 설정
AUTH_PASSWORD_VALIDATORS = [
{
Expand Down
51 changes: 50 additions & 1 deletion potato_project/baekjoons/tests.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,52 @@
from unittest.mock import patch

from django.test import TestCase
from django.urls import reverse
from rest_framework import status
from rest_framework.test import APIClient
from users.models import User

from .models import Baekjoon


class ProfileViewTests(TestCase):
def setUp(self):
self.client = APIClient()
self.user = User.objects.create_user(
username="testuser", password="testpassword", baekjoon_id="test_baekjoon"
)
self.client.force_authenticate(user=self.user)
self.url = reverse("profile-view")

@patch("baekjoons.views.get_boj_profile")
def test_get_profile_success(self, mock_get_boj_profile):
mock_get_boj_profile.return_value = {
"username": "test_baekjoon",
"tier": 10,
"solved_count": 50,
"rating": 1500,
}

response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_200_OK)
self.assertEqual(response.json()["username"], "test_baekjoon")
self.assertEqual(response.json()["solved_count"], 50)

baekjoon = Baekjoon.objects.get(user=self.user)
self.assertEqual(baekjoon.score, 50)

def test_get_profile_no_baekjoon_id(self):
self.user.baekjoon_id = ""
self.user.save()

response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_400_BAD_REQUEST)
self.assertEqual(response.json()["error"], "User does not have a Baekjoon ID.")

@patch("baekjoons.views.get_boj_profile")
def test_get_profile_user_not_found(self, mock_get_boj_profile):
mock_get_boj_profile.return_value = None

# Create your tests here.
response = self.client.get(self.url)
self.assertEqual(response.status_code, status.HTTP_404_NOT_FOUND)
self.assertEqual(response.json()["error"], "User not found or API error.")
2 changes: 1 addition & 1 deletion potato_project/baekjoons/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
from .views import ProfileView

urlpatterns = [
path("profile/", ProfileView.as_view(), name="profile_view"),
path("profile/", ProfileView.as_view(), name="profile-view"),
]
18 changes: 18 additions & 0 deletions potato_project/githubs/migrations/0003_alter_github_date.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 5.0.7 on 2024-08-01 07:24

import django.utils.timezone
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
("githubs", "0002_initial"),
]

operations = [
migrations.AlterField(
model_name="github",
name="date",
field=models.DateField(default=django.utils.timezone.now),
),
]
Loading