Skip to content

Commit 99bb695

Browse files
committed
chore: 불필요 boto3 의존 제거
1 parent 440e40c commit 99bb695

3 files changed

Lines changed: 18 additions & 250 deletions

File tree

app/core/settings.py

Lines changed: 18 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import environ
88
import sentry_sdk
99
import sentry_sdk.integrations.django
10-
from django.core.exceptions import ImproperlyConfigured
1110

1211
# Build paths inside the project like this: BASE_DIR / 'subdir'.
1312
BASE_DIR = pathlib.Path(__file__).resolve().parent.parent
@@ -304,64 +303,28 @@
304303
DATA_UPLOAD_MAX_MEMORY_SIZE = 30 * 1024 * 1024 # 30 MB
305304
FILE_UPLOAD_MAX_MEMORY_SIZE = 30 * 1024 * 1024 # 30 MB
306305

307-
S3_STORAGE_BACKEND = "storages.backends.s3.S3Storage"
308-
309-
DEFAULT_STORAGE_BACKEND = env("DJANGO_DEFAULT_STORAGE_BACKEND", default=S3_STORAGE_BACKEND)
310-
STATIC_STORAGE_BACKEND = env("DJANGO_STATIC_STORAGE_BACKEND", default=S3_STORAGE_BACKEND)
306+
# 스토리지는 자체 호스팅(FileSystemStorage)만 지원한다. static·미디어 모두 nginx 가 서빙한다.
307+
# - static: collectstatic -> STATIC_ROOT, nginx 가 STATIC_URL 로 서빙.
308+
# - 미디어(public 업로드): PublicFile 은 upload_to="public/" 이므로 디스크 경로는 MEDIA_ROOT/public/<name>,
309+
# URL 은 MEDIA_URL + "public/<name>" 로 떨어진다. (location/base_url 기본값 = MEDIA_ROOT/MEDIA_URL)
310+
DEFAULT_STORAGE_BACKEND = env("DJANGO_DEFAULT_STORAGE_BACKEND", default="django.core.files.storage.FileSystemStorage")
311+
STATIC_STORAGE_BACKEND = env(
312+
"DJANGO_STATIC_STORAGE_BACKEND", default="django.contrib.staticfiles.storage.StaticFilesStorage"
313+
)
311314

312-
# AWS S3 모드일 때만 S3 전용 설정을 적용한다. (env 가 S3 백엔드를 가리키면 기존 동작을 그대로 유지)
313-
# 그 외(FileSystemStorage = 자체 호스팅) 모드에서는 로컬 파일시스템에 맞는 설정만 넣는다.
314-
USING_S3 = DEFAULT_STORAGE_BACKEND == S3_STORAGE_BACKEND
315+
STATIC_URL = env("DJANGO_STATIC_URL", default="static/")
316+
MEDIA_URL = env("DJANGO_MEDIA_URL", default="media/")
315317

316-
# default(media/public)와 static 백엔드는 함께 S3 이거나 함께 자체 호스팅이어야 한다.
317-
# 한쪽만 S3 로 두면 STORAGES["staticfiles"] 가 버킷 없이 구성되어 조용히 깨지므로 시작 시 막는다.
318-
if USING_S3 != (STATIC_STORAGE_BACKEND == S3_STORAGE_BACKEND):
319-
raise ImproperlyConfigured(
320-
"DJANGO_DEFAULT_STORAGE_BACKEND 와 DJANGO_STATIC_STORAGE_BACKEND 는 "
321-
"둘 다 S3 이거나 둘 다 비-S3(자체 호스팅) 여야 합니다. "
322-
f"(default={DEFAULT_STORAGE_BACKEND!r}, static={STATIC_STORAGE_BACKEND!r})"
323-
)
318+
# URL 뒤에 파일 경로가 그대로 이어붙으므로 끝 슬래시를 보장한다. (예: MEDIA_URL + "public/<name>")
319+
if not STATIC_URL.endswith("/"):
320+
STATIC_URL += "/"
321+
if not MEDIA_URL.endswith("/"):
322+
MEDIA_URL += "/"
324323

325-
PRIVATE_STORAGE_BUCKET_NAME = f"pyconkr-backend-{API_STAGE}"
326-
PUBLIC_STORAGE_BUCKET_NAME = f"pyconkr-backend-{API_STAGE}-public"
327-
328-
if USING_S3:
329-
STATIC_URL = f"https://s3.ap-northeast-2.amazonaws.com/{PRIVATE_STORAGE_BUCKET_NAME}/"
330-
MEDIA_URL = f"https://s3.ap-northeast-2.amazonaws.com/{PUBLIC_STORAGE_BUCKET_NAME}/"
331-
332-
STATIC_STORAGE_OPTIONS = {
333-
"bucket_name": PRIVATE_STORAGE_BUCKET_NAME,
334-
"file_overwrite": False,
335-
"addressing_style": "path",
336-
}
337-
PUBLIC_STORAGE_OPTIONS = {
338-
"bucket_name": PUBLIC_STORAGE_BUCKET_NAME,
339-
"file_overwrite": False,
340-
"addressing_style": "path",
341-
}
342-
else:
343-
# 자체 호스팅(FileSystemStorage): static·미디어 모두 nginx 가 서빙한다.
344-
# - static: collectstatic -> STATIC_ROOT, nginx 가 STATIC_URL 로 서빙.
345-
# - 미디어(public 업로드): PublicFile 은 upload_to="public/" 이므로 디스크 경로는 MEDIA_ROOT/public/<name>,
346-
# URL 은 MEDIA_URL + "public/<name>" 로 떨어진다. (location/base_url 기본값 = MEDIA_ROOT/MEDIA_URL)
347-
STATIC_URL = env("DJANGO_STATIC_URL", default="static/")
348-
MEDIA_URL = env("DJANGO_MEDIA_URL", default="media/")
349-
350-
# URL 뒤에 파일 경로가 그대로 이어붙으므로 끝 슬래시를 보장한다. (예: MEDIA_URL + "public/<name>")
351-
if not STATIC_URL.endswith("/"):
352-
STATIC_URL += "/"
353-
if not MEDIA_URL.endswith("/"):
354-
MEDIA_URL += "/"
355-
356-
# FileSystemStorage 등 로컬 백엔드에는 S3 전용 kwargs(bucket_name 등)를 넘기지 않는다.
357-
STATIC_STORAGE_OPTIONS = {}
358-
PUBLIC_STORAGE_OPTIONS = {}
359-
360-
# STORAGES 구조는 두 모드 공통이며, OPTIONS 만 위 분기에서 모드별로 채워진다.
361324
STORAGES = {
362-
"default": {"BACKEND": DEFAULT_STORAGE_BACKEND, "OPTIONS": STATIC_STORAGE_OPTIONS},
363-
"staticfiles": {"BACKEND": STATIC_STORAGE_BACKEND, "OPTIONS": STATIC_STORAGE_OPTIONS},
364-
"public": {"BACKEND": DEFAULT_STORAGE_BACKEND, "OPTIONS": PUBLIC_STORAGE_OPTIONS},
325+
"default": {"BACKEND": DEFAULT_STORAGE_BACKEND},
326+
"staticfiles": {"BACKEND": STATIC_STORAGE_BACKEND},
327+
"public": {"BACKEND": DEFAULT_STORAGE_BACKEND},
365328
}
366329

367330
# Default primary key field type

pyproject.toml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ readme = "README.md"
66
requires-python = "==3.12.*"
77
dependencies = [
88
"argon2-cffi>=25.1.0",
9-
"boto3 (>=1.43.11,<2.0.0)",
109
"celery[redis]>=5.6.3",
1110
"cryptography>=48.0.0",
1211
"django>=6.0.5",
@@ -19,7 +18,6 @@ dependencies = [
1918
"django-modeltranslation>=0.20.3",
2019
"django-picklefield>=3.4.0",
2120
"django-simple-history>=3.11.0",
22-
"django-storages[s3]>=1.14.6",
2321
"djangorestframework>=3.17.1",
2422
"drf-spectacular>=0.29.0",
2523
"drf-standardized-errors[openapi]>=0.16.0",
@@ -52,7 +50,6 @@ dependencies = [
5250

5351
[dependency-groups]
5452
dev = [
55-
"boto3-stubs[essential,s3]>=1.43.11",
5653
"django-stubs[compatible-mypy]>=6.0.4",
5754
"djangorestframework-stubs[compatible-mypy]>=3.17.0",
5855
"freezegun>=1.5.0",

0 commit comments

Comments
 (0)