Skip to content

Commit

Permalink
[feat] 초기 설정
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-heo committed Sep 5, 2024
1 parent 8cf7127 commit c7f1b5a
Show file tree
Hide file tree
Showing 32 changed files with 708 additions and 0 deletions.
14 changes: 14 additions & 0 deletions .github/ISSUE_TEMPLATE/-feature--작업할-내용.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
name: "[Feature] 작업할 내용"
about: "✨ Feat Issue"
title: "[Feature]"
labels: feature
assignees: ''

---

### 🌿 Feature
(기능 설명)

### ✅ To-Do List
- [ ]
11 changes: 11 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## 🎵 Issue

close #이슈번호

## 🔨 작업 내용


## 📩 API Test


## ➰ ETC
49 changes: 49 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Deploy to EC2

on:
push:
branches:
- main
pull_request:
branches:
- main

jobs:

build:
name: Build
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@master

- name: create env file
run: |
touch .env
echo "${{ secrets.ENV_VARS }}" >> .env
- name: create remote directory
uses: appleboy/ssh-action@v0.1.4
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: mkdir -p /home/ubuntu/srv/ubuntu

- name: copy source via ssh key
uses: burnett01/rsync-deployments@4.1
with:
switches: -avzr --delete
remote_path: /home/ubuntu/srv/ubuntu/
remote_host: ${{ secrets.HOST }}
remote_user: ubuntu
remote_key: ${{ secrets.KEY }}

- name: executing remote ssh commands using password
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.HOST }}
username: ubuntu
key: ${{ secrets.KEY }}
script: |
sh /home/ubuntu/srv/ubuntu/config/scripts/deploy.sh
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,15 @@ celerybeat.pid
# Environments
.env
.venv
.newvenv
env/
venv/
newvenv/
ENV/
env.bak/
venv.bak/
newvenv.bak/
.env.prod

# Spyder project settings
.spyderproject
Expand Down Expand Up @@ -160,3 +164,5 @@ cython_debug/
# and can be added to the global gitignore or merged into this file. For a more nuclear
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/

.DS_Store
23 changes: 23 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FROM python:3.8.3-alpine
ENV PYTHONUNBUFFERED 1

RUN mkdir /app
WORKDIR /app

# dependencies for psycopg2-binary
RUN apk add --no-cache mariadb-connector-c-dev
RUN apk update && apk add python3 python3-dev mariadb-dev build-base && pip3 install mysqlclient==2.2.4 && apk del python3-dev mariadb-dev build-base


# By copying over requirements first, we make sure that Docker will cache
# our installed requirements rather than reinstall them on every build
RUN apk update && apk add libpq
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add --no-cache jpeg-dev zlib-dev mariadb-dev
COPY requirements.txt /app/requirements.txt
RUN pip install -r requirements.txt
RUN apk del jpeg-dev zlib-dev

# Now copy in our code, and run it
COPY . /app/
73 changes: 73 additions & 0 deletions Dockerfile.prod
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# BUILDER #
###########

# pull official base image
FROM python:3.8.3-alpine as builder

# set work directory
WORKDIR /usr/src/app


# set environment variables
ENV PYTHONDONTWRITEBYTECODE 1
ENV PYTHONUNBUFFERED 1

# install psycopg2 dependencies
RUN apk update && apk add python3 python3-dev mariadb-dev build-base && pip3 install mysqlclient

# dependencies for pillow
RUN apk add --no-cache jpeg-dev zlib-dev
RUN apk add --no-cache --virtual .build-deps build-base linux-headers

# install dependencies
COPY ./requirements.txt .
RUN pip wheel --no-cache-dir --no-deps --wheel-dir /usr/src/app/wheels -r requirements.txt


#########
# FINAL #
#########

# pull official base image
FROM python:3.8.3-alpine

# create directory for the app user
RUN mkdir -p /home/app

# create the app user
RUN addgroup -S app && adduser -S app -G app

# create the appropriate directories
ENV HOME=/home/app
ENV APP_HOME=/home/app/web
RUN mkdir $APP_HOME
RUN mkdir $APP_HOME/static
RUN mkdir $APP_HOME/media
WORKDIR $APP_HOME

# install dependencies
RUN apk update && apk add libpq tzdata
RUN ln -snf /usr/share/zoneinfo/Asia/Seoul /etc/localtime
RUN apk update \
&& apk add --virtual build-deps gcc python3-dev musl-dev \
&& apk add --no-cache jpeg-dev zlib-dev mariadb-dev
COPY --from=builder /usr/src/app/wheels /wheels
COPY --from=builder /usr/src/app/requirements.txt .
RUN pip install mysqlclient
RUN pip install --no-cache /wheels/*
RUN apk del build-deps

# set timezone
ENV TZ=Asia/Seoul

# copy entrypoint-prod.sh
COPY ./config/docker/entrypoint.prod.sh $APP_HOME

# copy project
COPY . $APP_HOME

# chown all the files to the app user
RUN chown -R app:app $APP_HOME

# change to the app user
USER app
Empty file added blog/__init__.py
Empty file.
3 changes: 3 additions & 0 deletions blog/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 blog/apps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
from django.apps import AppConfig


class BlogConfig(AppConfig):
default_auto_field = "django.db.models.BigAutoField"
name = "blog"
29 changes: 29 additions & 0 deletions blog/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Generated by Django 4.2.7 on 2024-09-05 03:39

from django.db import migrations, models


class Migration(migrations.Migration):

initial = True

dependencies = []

operations = [
migrations.CreateModel(
name="Blog",
fields=[
(
"id",
models.BigAutoField(
auto_created=True,
primary_key=True,
serialize=False,
verbose_name="ID",
),
),
("title", models.CharField(max_length=20)),
("content", models.TextField()),
],
),
]
Empty file added blog/migrations/__init__.py
Empty file.
7 changes: 7 additions & 0 deletions blog/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from django.db import models

class Blog(models.Model):
title = models.CharField(max_length=20)
content = models.TextField()


7 changes: 7 additions & 0 deletions blog/serializers.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from rest_framework import serializers
from .models import *

class BlogSerializer (serializers.ModelSerializer):
class Meta:
model = Blog
fields = '__all__'
3 changes: 3 additions & 0 deletions blog/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 blog/urls.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from django.urls import path
from .views import *

app_name = 'blog'

urlpatterns = [
path('', BlogDetailView.as_view()),
]
17 changes: 17 additions & 0 deletions blog/views.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from django.shortcuts import render
from rest_framework import views
from .models import Blog
from .serializers import *
from rest_framework.response import Response
from rest_framework.status import *


# Create your views here.


class BlogDetailView(views.APIView):
def get(self, request):
blogs=Blog.objects.all()
serializers=BlogSerializer(blogs,many=True)
return Response({'message':'화이팅~!','data': serializers.data}, status=HTTP_200_OK)

Empty file added blogProject/__init__.py
Empty file.
16 changes: 16 additions & 0 deletions blogProject/asgi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
"""
ASGI config for blogProject project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/4.2/howto/deployment/asgi/
"""

import os

from django.core.asgi import get_asgi_application

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "blogProject.settings")

application = get_asgi_application()
Loading

0 comments on commit c7f1b5a

Please sign in to comment.