Skip to content

Commit

Permalink
Merge pull request #126 from cau-likelion-org/refactoring
Browse files Browse the repository at this point in the history
Refactoring
  • Loading branch information
hayeongKo authored Feb 26, 2024
2 parents f25fc03 + 41761b7 commit 0d1ef74
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 98 deletions.
45 changes: 22 additions & 23 deletions .github/workflows/django.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,30 @@
name: Deploy
name: Django EC2 Deploy

on:
push:
branches:
- deploy
branches: [main]

jobs:
deploy:
runs-on: ubuntu-latest

name: "Django CD"
runs-on: ubuntu-20.04
steps:
- name: Checkout code
uses: actions/checkout@v2

- name: Set up SSH
uses: webfactory/[email protected]
- name: EC2 ssh connection test
uses: appleboy/ssh-action@master
with:
ssh-private-key: ${{ secrets.CHUNGHAHA_DEPLOY_KEY }}

- name: SSH to EC2 and kill running processes
run: |
ssh ubuntu@ip-172-31-1-75 "ps -ef | grep manage.py | grep -v grep | awk '{print \$2}' | xargs -r kill -9"
- name: Activate virtualenv and install dependencies
run: |
ssh ubuntu@ip-172-31-1-75 "source venv/bin/activate && cd cau-likelion-django && pip install -r requirements.txt"
- name: Update code and run server
run: |
ssh ubuntu@ip-172-31-1-75 "git pull origin main && nohup python manage.py runserver 0.0.0.0:8000 &"
host: ${{ secrets.SSH_HOST }}
username: ${{ secrets.SSH_USERNAME }}
key: ${{ secrets.SSH_PEM }}
command_timeout: 3m
script: |
sudo apt-get update
sudo apt-get -y upgrade
cd cau-likelion-django
source venv/bin/activate
git pull origin main
sudo lsof -t -i tcp:8000 | xargs kill -9
pip install -r requirements.txt
python manage.py makemigrations
python manage.py migrate
nohup gunicorn --bind 0.0.0.0:8000 config.wsgi > nohup.out 2> nohup.err < /dev/null &
exit 0
12 changes: 12 additions & 0 deletions .idea/dataSources.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def get_secret(setting, secrets=secrets):

ALLOWED_HOSTS = ['*']

CSRF_TRUSTED_ORIGINS = ['https://api-cau-likelion.shop', 'https://cau-likelion.org', 'http://localhost:3000']
CSRF_TRUSTED_ORIGINS = ['https://cau-chunghaha.kro.kr', 'https://cau-likelion.org', 'http://localhost:3000']
# CORS_ORIGIN_WHITELIST = ['https://api.cau-likelion.org', 'https://cau-likelion.org', 'http://localhost:3000']
CORS_ORIGIN_ALLOW_ALL = True
CORS_ALLOW_CREDENTIALS = True
Expand Down Expand Up @@ -105,6 +105,7 @@ def get_secret(setting, secrets=secrets):
'django.middleware.clickjacking.XFrameOptionsMiddleware',
#'django.middleware.multipart.MultipartMiddleware',
'config.middleware.custom_middleware.SetDatabaseMiddleware',
'allauth.account.middleware.AccountMiddleware'
]

ROOT_URLCONF = 'config.urls'
Expand All @@ -130,6 +131,8 @@ def get_secret(setting, secrets=secrets):

# Database
# https://docs.djangoproject.com/en/4.1/ref/settings/#databases
import pymysql
pymysql.install_as_MySQLdb()

DATABASES = my_settings.DATABASES

Expand Down
18 changes: 14 additions & 4 deletions projects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ def get(self, request):

nine = [] # 9기
ten = [] # 10기
eleven = [] # 11기 // 사이드프로젝트 이어받는 분들~ 이 다음부터 12기는 twelve 13기는 thirteen 하시면 됩니다.
eleven = [] # 11기 // 사이드프로젝트 이어받는 분들~ 이 다음부터 12기는 twelve 13기는 thirteen 하시면 됩니다.
twelve = []

for project in project_list:
if project['version'] == 9:
Expand All @@ -42,6 +43,15 @@ def get(self, request):
'thumbnail' : project['thumbnail'],
})
elif project['version'] == 11:
twelve.append({
'id' : project['project_id'],
'title' : project['title'],
'dev_stack' : project['dev_stack'],
'subtitle' : project['subtitle'],
'category' : project['category'],
'thumbnail' : project['thumbnail'],
})
elif project['version'] == 12:
eleven.append({
'id' : project['project_id'],
'title' : project['title'],
Expand All @@ -57,7 +67,7 @@ def get(self, request):
"9" : nine,
"10" : ten,
"11" : eleven,
# "2024" : four,
"12" : twelve
}
}, status=status.HTTP_200_OK)

Expand All @@ -83,7 +93,7 @@ def post(self, request):
thumbnail_url = f"projects/{title}/thumbnail" # DB에 저장될 썸네일 이미지 url 설정
self.s3_client.upload_fileobj(
thumbnail,
"realchunghaha",
"cau-likelion",
thumbnail_url,
ExtraArgs={
"ContentType": thumbnail.content_type
Expand Down Expand Up @@ -112,7 +122,7 @@ def post(self, request):
image_url = f"projects/{title}/image{cnt}"
self.s3_client.upload_fileobj(
image,
"realchunghaha",
"cau-likelion",
image_url,
ExtraArgs={
"ContentType": image.content_type
Expand Down
93 changes: 23 additions & 70 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,79 +1,32 @@
appnope==0.1.3
asgiref==3.6.0
asttokens==2.2.1
async-generator==1.10
attrs==22.2.0
backcall==0.2.0
beautifulsoup4==4.11.2
boto3==1.26.48
botocore==1.29.48
bs4==0.0.1
cached-property==1.5.2
certifi==2022.12.7
cffi==1.15.1
charset-normalizer==3.0.1
commonmark==0.9.1
cryptography==39.0.0
decorator==5.1.1
asgiref==3.7.2
boto3==1.34.39
botocore==1.34.39
certifi==2024.2.2
cffi==1.16.0
charset-normalizer==3.3.2
cryptography==42.0.2
defusedxml==0.7.1
dictdiffer==0.9.0
dj-rest-auth==2.2.7
Django==4.1.5
django-allauth==0.51.0
django-cors-headers==3.14.0
django-storages==1.13.2
dj-rest-auth==5.0.2
Django==4.2.10
django-allauth==0.61.1
django-cors-headers==4.3.1
django-storages==1.14.2
djangorestframework==3.14.0
djangorestframework-simplejwt==5.0.0
exceptiongroup==1.1.0
executing==1.2.0
ez-setup==0.9
h11==0.14.0
idna==3.4
ipython==8.9.0
jedi==0.18.2
djangorestframework-simplejwt==5.3.1
idna==3.6
jmespath==1.0.1
lxml==4.9.2
matplotlib-inline==0.1.6
mysqlclient==2.1.1
notion==0.0.28
oauthlib==3.2.2
outcome==1.2.0
packaging==23.0
parso==0.8.3
pexpect==4.8.0
pickleshare==0.7.5
Pillow==9.4.0
prompt-toolkit==3.0.36
ptyprocess==0.7.0
pure-eval==0.2.2
pillow==10.2.0
pycparser==2.21
Pygments==2.14.0
PyJWT==2.6.0
PySocks==1.7.1
PyJWT==2.8.0
PyMySQL==1.1.0
python-dateutil==2.8.2
python-dotenv==0.21.1
python-slugify==8.0.0
python3-openid==3.2.0
pytz==2022.7
pytz-deprecation-shim==0.1.0.post0
requests==2.28.2
pytz==2024.1
requests==2.31.0
requests-oauthlib==1.3.1
s3transfer==0.6.0
selenium==4.8.2
s3transfer==0.10.0
six==1.16.0
sniffio==1.3.0
sortedcontainers==2.4.0
soupsieve==2.4
sqlparse==0.4.3
stack-data==0.6.2
text-unidecode==1.3
tqdm==4.64.1
traitlets==5.9.0
trio==0.22.0
trio-websocket==0.9.2
tzdata==2022.7
tzlocal==4.2
urllib3==1.26.14
wcwidth==0.2.6
webdriver-manager==3.8.5
wsproto==1.2.0
sqlparse==0.4.4
typing_extensions==4.9.0
urllib3==1.26.18

0 comments on commit 0d1ef74

Please sign in to comment.