| ์ฃผ์ ์ฝ๋ | Source Code | ์ฝ๋ ์ค๋ช |
|---|---|---|
| ์ดํ์ธ ์ธ์ฆ ๋ฉ์ผ | ![]() |
๐ฉ Django.core.mail์์ ๊ธฐ๋ณธ์ผ๋ก ์ ๊ณตํ๋ ์ด๋ฉ์ผ ๋ฐ์ก ํจ์๋ฅผ ์ด์ฉํ์ฌ ์ดํ์ฌ๋ ์ด๋ฉ์ผ ์ธ์ฆ ๊ธฐ๋ฅ ์ฌ์ฉ ๐ฉ email ์์ด๋๋ง ์ ๋ ฅ๋ฐ์ ewha.ac.kr ์ฃผ์๋ฅผ ๋ถ์ฌ ๋ฉ์ผ์ ๋ฐ์กํ๊ธฐ ๋๋ฌธ์, ๊ฐ์ ๋ก ์ดํ์ธ ์ด๋ฉ์ผ๋ก๋ง ์ธ์ฆ๋ฒํธ๋ฅผ ๋ฐ์ ์ ์๋๋ก ์ค๊ณ |
| ๊ฒ์ ๊ธฐ๋ฅ | ๐clova/lostitem/views.py ๐LostSearchView ๐clova/lostitem/GPT_find.py โธ ๐ฉโ๐ป ์ฌ์ฉํ ์คํ์์ค : Google Cloud API, KoNLPy์ Komoran ํํ์ ๋ถ์๊ธฐ, scikitlearn์ TfidfVectorizer |
๐ฉ ๊ฒ์์ ์ํด ์
๋ ฅ ๋ฐ์ ์ ๋ณด ์ค ์ผ๋ถ๋ ์ด๊ธฐ ํํฐ๋ง์ ์ฌ์ฉ ๐ฉ ํํฐ๋ง ๋ DB๋ฅผ ๊ฐ์ง๊ณ find(filtered_data, description) ํจ์๋ฅผ ์คํ. find ํจ์๋ ์ฝ์ฌ์ธ ์ ์ฌ๋๋ฅผ ํตํด ๊ณ์ฐ๋ ์์ 3๊ฐ์ ๊ฒฐ๊ณผ๋ฅผ ๋ฐํ ๐ฉ jupyter ํ์์ผ๋ก ์์ฑ๋ ์ฝ๋๋ฅผ .py ํ์์ผ๋ก ์์ ํ์ฌ GPT_find.py ํ์ผ์ ์ ์ฅ ํ LostSearchView์์ ์ฌ์ฉํ ์ ์๋๋ก import ํด์ค๋ ๋ฐฉ์์ผ๋ก ์ค๊ณ |
| ๋ฑ๋ก ๊ธฐ๋ฅ | ๐clova/lostitem/views.py ๐LostImageUploadView & LostUploadView ๐clova/lostitem/GPT_desc.py โธ ๐ฉโ๐ป ์ฌ์ฉํ ์คํ์์ค : chat gpt 4.o API |
๐ฉ ์ฌ์ฉ์๊ฐ ์
๋ ฅํ ์ฌ์ง ํ์ผ์ ๋งํฌํ์์ผ๋ก ๋ถ๋ฌ์ค๊ธฐ ์ํด ์์๋ก media ํ์ผ์ ์ ์ฅํ์ฌ, url์ ๋ถ๋ฌ์ค๋๋ก ์ค๊ณ ๐ฉ ๋ถ์ค์๊ฐ๊ณผ ๋ ์ง๋ ํ์ฌ ์์ ์ ๊ธฐ์ค์ผ๋ก ์๋์ผ๋ก ์ ๋ ฅ๋๋๋ก ๋ฐํ ๐ฉ register(imagefile) ํจ์๋ฅผ ๊ฑฐ์ณ category, description, title ํญ๋ชฉ์ ๋ฐํํ๋๋ก ์ค๊ณ ๐ฉ register ํจ์๋ ์์ ๊ฒ์ ๊ณผ์ ๊ณผ ๋์ผํ๊ฒ GPT_desc.py ํ์ผ์ ํ๋กฌํํ ๋ GPT api ํจ์๋ฅผ ์์ฑํด๋ ๋ค import ํ๋ ๋ฐฉ์์ผ๋ก ๊ตฌํ ๐ฉ ์ฑ๊ณต์ ์ผ๋ก GPT์์ ์ค๋ช ์ด ์์ฑ๋์๋ค๋ฉด ์๋ฒ์ฝ๋ 200์ ๋ฐํํ๊ณ ํ๋ก ํธ์๋์ Response ์๋ต ๋ฐํ ๐ฉ GPT์์ ์ค๋ช ์ด ์์ฑ๋์ง ์์๋ค๋ฉด error ์ฝ๋๋ฅผ ๋ฐํํ๊ณ ์๋ฒ์ค๋ฅ 500 ๋ฐํํ์ฌ ์ฌ์ฉ์๊ฐ ํ๋ก ํธ์๋์์ ๋ค์ ์ด๋ฏธ์ง๋ฅผ ์ ๋ ฅํ ์ ์๋๋ก ์ค๊ณ |
git remote -v #ํ์ฌ ๊ฐ๋ฐํ๊ฒฝ๊ณผ ์ฐ๊ฒฐ๋ git remote ์ฃผ์ ํ์ธ
git branch -a #ํ์ฌ ๊ฐ๋ฐํ๊ฒฝ๊ณผ ์ฐ๊ฒฐ๋ git branch ์ด๋ฆ ํ์ธ
## ์์ ๋ code๋ฅผ git์ ๋ฐ์ํ๊ธฐ ์ํ ํ๊ฒฝ์ด ํ์ธ๋ ๊ฒฝ์ฐ
git add . #์์ ๋ code ์ ์ฒด๋ฅผ git์ ์ฌ๋ฆฌ๊ธฐ ์ํด ๋ฐ์
git commit -m "commit message" #์ปค๋ฐ ๋ฉ์ธ์ง๋ฅผ ์ถ๊ฐํ์ฌ ๊ธฐ๋ฅ๋ณ๋ก update
git pull origin main #origin(local)์์ main(git)์ผ๋ก ๋ฐ์ํ ์ฝ๋ pull
-
git pull ์ ๋ก๋๋ ์ฝ๋๋ git action์ ํตํด ์๋์ผ๋ก ๋ฐฐํฌ ๋ฐ์
-
Git์ ์ ๋ก๋ํ๋ ๊ณผ์ ์์ chatGPT API Key, Django Key ๋ฑ ๋ฏผ๊ฐํ ์ ๋ณด๋ .env.prod์ .env ํ์ผ์ ์์ฑํ์ฌ gitignore (GitHub์ ์ ๋ก๋๋์ง ์๋๋ก ๊ด๋ฆฌ)
-
ํ๋ก์ ํธ ๋น๋๊ณผ์ ์์ ๊ผญ ํ์ํ ๋น๋ฐ ์ ๋ณด๋ค์ Git Secret์ ์์ฑ
-
git action ์๋ํ ๋น๋ ๊ณผ์ ์์ ํ์ํ ํ์ผ์ ์์๋ก ์์ฑํ๋๋ก ๊ด๋ฆฌ
#(์) .github/workflows/deploy.yml
- name: create env file
run: |
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
#django key, Debug ์ฌ๋ถ ๋ฑ์ด ์ ์ฅ๋ ENV_VARS secret์ .env ํ์ผ๋ก ๋น๋
- name: create json file
uses: jsdaniell/create-json@v1.2.2
with:
name: "extended-medium-423214-k4-3cd01a759605.json"
json: ${{ secrets.CHATGPT }}
dir: '.'
#chatGPT ์คํ์ ์ํด ํ์ํ JSON ํ์ผ์ ์์ฑ
-
clova.site ๋ด๋ถ์์ chatGPT API ์คํ๊ณผ ๊ฒ์ ๊ณผ์ ์์์ ํํ์ ๋ถ์์ ์ํด ๋ฌด๊ฑฐ์ด dependencies๊ฐ ํ์ โ ์ด๋ฏธ dependencies๊ฐ ์ค์น๋ python:3.8-slim-buster๋ฅผ builder๋ก ์ ํํ์ฌ ๋น๋ ๊ณผ์ ์์ time out ๋์ง ์๋๋ก ์ค๊ณ
-
Docker Container๋ฅผ ํตํด ๊ฐ์ํ๊ฒฝ์ ๊ตฌ์ถํ์ฌ docker ์์์ ์น์ด ์๋ํ๋๋ก ์น ์ค๊ณ
# pull official base image
FROM python:3.8-slim-buster as builder
# set work directory
WORKDIR /usr/src/app
- requirements.txt์ ํ์ํ dependencies ๋ชจ๋ ์์ฑํ์ฌ ํ๋์ฉ ์ค์นํ๋, no cache dir ์ต์ ์ฌ์ฉํ์ฌ ์ค์น ๊ณผ์ ์์์ ์ค๋ฅ ์ต์ํ
# update pip
RUN pip install --upgrade pip
# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt
- web ๋น๋ ๊ณผ์ ์์ gunicorn ์ฌ์ฉํ์์ผ๋, timeout 120 ์ต์ ์ ๊ฑธ์ด ๋ฌด๊ฑฐ์ด application์ด ์ค์น๋๋ ๊ณผ์ ์์ time out ๋๋ ๊ฒ์ ๋ฐฉ์ง
web:
container_name: web
build:
context: ./
dockerfile: Dockerfile.prod
command: gunicorn --timeout 120 clova.wsgi:application --bind 0.0.0.0:8000
environment:
DJANGO_SETTINGS_MODULE: clova.settings.prod
env_file:
- .env
volumes:
- static:/home/app/web/static
- media:/home/app/web/media
expose:
- 8000
entrypoint:
- sh
- config/docker/entrypoint.prod.sh
- ๊ฐ๋น์ ๋๋ฉ์ธ ๊ตฌ๋งค
- AWS EC2 ์ธ์คํด์ค ์์ฑ
- SSH ์ธ์ฆ์ ๋ฐ๊ธ ํตํด https ์ ๊ทผ ๊ถํ ํ๊ฐ
- ๊ตฌ๋งคํ ๋๋ฉ์ธ ์ฃผ์ ๋ถ๋ฆฌ api.clova.site & www.clova.site
- ํ๋ก ํธ์๋ Vercel์ API ์์ฒญ์ด api.clova.site๋ฅผ ํตํด ๋ค์ด์ค๋ฉด ์ฒ๋ฆฌ ํ www.clova.site๋ก ๊ฒฐ๊ณผ ๋ฐํํ๋๋ก ๋๋ฉ์ธ ์ค์
๊ทธ๋ก์ฐ 09ํ ๋ณด์ฑ๋ง์ฐจ-์ด์ ์ ๊ธฐ์ ๋ธ๋ก๊ทธ์ ์์ธํ ์ฐ๊ฒฐ๊ณผ์ ์ ์ ๋ก๋
๐๐๐ ๋ฐฐํฌ ๋งํฌ ์ ์ ๐๐๐

