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.
53 changes: 53 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: Deploy to EC2

on:
push:
branches:
- '0527'
pull_request:
branches:
- '0527'

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
# 1. Checkout
- name: Checkout
uses: actions/checkout@v4

# 2. Create .env file
- name: Create env file
run: |
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env

# 3. Create remote directory
- name: Create remote directory
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: mkdir -p /home/ubuntu/srv/ubuntu

# 4. Copy source
- name: Copy source via ssh key
uses: burnett01/[email protected]
with:
switches: -avzr --delete
remote_path: /home/ubuntu/srv/ubuntu/
remote_host: ${{ secrets.HOST }}
remote_user: ubuntu
remote_key: ${{ secrets.KEY }}

# 5. Run deploy script on EC2
- name: Run remote deploy.sh
uses: appleboy/[email protected]
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
sh /home/ubuntu/srv/ubuntu/config/scripts/deploy.sh
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ media

### Environments ###
.env
.env.prod
.venv
.newvenv
env/
Expand Down
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM python:3.11-alpine
ENV PYTHONUNBUFFERED=1 PIP_DISABLE_PIP_VERSION_CHECK=1 PIP_NO_CACHE_DIR=1 PIP_ROOT_USER_ACTION=ignore
WORKDIR /app

# 런타임 라이브러리
RUN apk add --no-cache \
openssl \
libffi \
libjpeg-turbo \
zlib \
mariadb-connector-c

# 의존성 설치
COPY requirements.txt /app/requirements.txt
RUN apk add --no-cache --virtual .build-deps \
build-base libffi-dev openssl-dev jpeg-dev zlib-dev \
mariadb-connector-c-dev pkgconf \
&& python -m pip install --upgrade pip setuptools wheel \
&& pip install --no-cache-dir -r /app/requirements.txt \
&& apk del .build-deps

# ★ 앱 소스 먼저 복사
COPY . /app/

# ★ 복사된 파일에 권한 부여 (절대경로 추천)
RUN test -f /app/config/docker/entrypoint.prod.sh \
&& chmod +x /app/config/docker/entrypoint.prod.sh
Binary file modified LionBlog/.DS_Store
Binary file not shown.
Binary file added LionDRF/.DS_Store
Binary file not shown.
Binary file added api/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions LionDRF/api/serializers.py → api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ def create(self, validated_data):
user.save()

return user





class UserLoginSerializer(serializers.Serializer):
Expand Down
File renamed without changes.
File renamed without changes.
3 changes: 3 additions & 0 deletions LionDRF/api/views.py → api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ def post(self, request):
return Response({'message':'회원가입 성공', 'data':serializer.data})
return Response({'message':'회원가입 실패', 'error':serializer.errors})




class LoginView(views.APIView):
serializer_class=UserLoginSerializer
def post(self, request):
Expand Down
Binary file added blog/.DS_Store
Binary file not shown.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
11 changes: 3 additions & 8 deletions LionDRF/blog/views.py → blog/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,6 @@
from rest_framework.permissions import IsAuthenticated

# Create your views here.
class PostList(views.APIView):
permission_classes=[IsAuthenticated]

def get(self, request, format=None):
post=Post.objects.all()
serializer=PostSerializer(post, many=True)
return Response(serializer.data)


class PostDetail(views.APIView):
def get_object(self, pk):
Expand Down Expand Up @@ -45,6 +37,9 @@ def delete(self, request, pk, format=None):


class PostList(views.APIView):

permission_classes=[IsAuthenticated]

def get(self, request, format=None):
post = Post.objects.all()
serializer = PostSerializer(post, many=True)
Expand Down
15 changes: 15 additions & 0 deletions config/docker/entrypoint.prod.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env sh
set -e

echo ">>> Apply database migrations"
python manage.py migrate --noinput --settings=drfproject.settings.prod

echo ">>> Collect static files"
python manage.py collectstatic --noinput --settings=drfproject.settings.prod

# 프로덕션에서는 보통 makemigrations 안 합니다. 필요시 주석 해제
# echo ">>> Make migrations (not recommended in prod)"
# python manage.py makemigrations --settings=drfproject.settings.prod

echo ">>> Start app: $@"
exec "$@"
4 changes: 4 additions & 0 deletions config/nginx/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
FROM nginx:1.19.0-alpine

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d
2 changes: 2 additions & 0 deletions config/nginx/Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
FROM nginx:alpine
COPY default.conf /etc/nginx/conf.d/default.conf
18 changes: 18 additions & 0 deletions config/nginx/default.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
server {
listen 80;
server_name _;

client_max_body_size 20M;

location /static/ { alias /home/app/web/static/; }
location /media/ { alias /home/app/web/media/; }

location / {
proxy_pass http://web:8000;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
}
}

29 changes: 29 additions & 0 deletions config/scripts/deploy.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/usr/bin/env bash
set -eu

APP_DIR="/home/ubuntu/srv/ubuntu"
cd "$APP_DIR"

# compose 최종 확인
sudo docker compose config | sed -n '1,120p'

echo "== BUILD WEB =="
# --progress는 compose 뒤에 둔다
if ! sudo docker compose --progress=plain -f docker-compose.prod.yml -p ubuntu build web --no-cache | tee build.log ; then
echo "[X] BUILD FAILED"
tail -n 120 build.log || true
exit 1
fi

echo "== UP =="
if ! sudo docker compose -f docker-compose.prod.yml -p ubuntu up -d ; then
echo "[X] UP FAILED"
sudo docker compose -f docker-compose.prod.yml -p ubuntu ps || true
sudo docker compose -f docker-compose.prod.yml -p ubuntu logs --no-color --tail=200 || true
exit 1
fi

sudo docker compose -f docker-compose.prod.yml -p ubuntu ps
sudo docker compose -f docker-compose.prod.yml -p ubuntu logs web --no-color --tail=200 || true
sudo docker compose -f docker-compose.prod.yml -p ubuntu logs nginx --no-color --tail=200 || true
echo "[✓] Deploy done."
40 changes: 40 additions & 0 deletions docker-compose.prod.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

services:
web:
container_name: web
build:
context: ./
dockerfile: Dockerfile # ← 루트에 실제 있는 파일명으로!
command: gunicorn drfproject.wsgi:application --bind 0.0.0.0:8000
environment:
DJANGO_SETTINGS_MODULE: drfproject.settings.prod
TZ: "Asia/Seoul"
env_file:
- .env
volumes:
- static:/home/app/web/static
- media:/home/app/web/media
expose:
- "8000"
entrypoint:
- sh
- /app/config/docker/entrypoint.prod.sh # ← 이 파일이 진짜 존재하는지도 확인!

nginx:
container_name: nginx
build:
context: ./config/nginx
dockerfile: Dockerfile.prod # ← 여긴 prod 파일이 실제로 있으므로 명시
volumes:
- static:/home/app/web/static
- media:/home/app/web/media
ports:
- "80:80"
depends_on:
- web
environment:
TZ: "Asia/Seoul"

volumes:
static:
media:
42 changes: 42 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@

services:

db:
container_name: db
image: mysql:8.0
restart: always
command: ["--default-authentication-plugin=mysql_native_password"]
environment:
MYSQL_ROOT_HOST: '%'
MYSQL_ROOT_PASSWORD: mysql
expose:
- 3306
ports:
- "3307:3306"
env_file:
- .env
volumes:
- dbdata:/var/lib/mysql

web:
container_name: web
build: .
command: sh -c "python manage.py migrate --settings=drfproject.settings.dev && python manage.py runserver 0.0.0.0:8000 --settings=drfproject.settings.dev"
environment:
MYSQL_ROOT_PASSWORD: mysql
DATABASE_NAME: mysql
DATABASE_USER: 'root'
DATABASE_PASSWORD: mysql
DATABASE_PORT: 3306
DATABASE_HOST: db
DJANGO_SETTINGS_MODULE: drfproject.settings.dev
restart: always
ports:
- "8000:8000"
volumes:
- .:/app
depends_on:
- db
volumes:
app:
dbdata:
File renamed without changes.
File renamed without changes.
Empty file added drfproject/settings/__init__.py
Empty file.
Loading