-
Notifications
You must be signed in to change notification settings - Fork 0
/
fabfile.py
133 lines (102 loc) · 3.2 KB
/
fabfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
from fabric.api import env
from fabric.api import local as fabric_local
from fabric.context_managers import shell_env
DEV = "dev"
STAGING = "staging"
PRODUCTION = "production"
USE_DOCKER = "no"
# 사용할 환경
env.target = DEV
env.compose = ["local.yml"]
env.settings = "--settings=config.settings.local"
# 커스텀 local 메소드
# ----------------------------------------------------------------
def local(string):
if env.target == STAGING:
fabric_local(string)
elif env.target == PRODUCTION:
fabric_local(string)
elif env.target == DEV:
with shell_env(DJANGO_READ_DOT_ENV_FILE="True"):
fabric_local(string)
# 환경 세팅 커맨드
# ----------------------------------------------------------------
def dev():
env.target = DEV
env.compose = ["local.yml"]
env.settings = "--settings=config.settings.local"
def staging():
env.target = STAGING
env.compose = ["staging.yml"]
env.settings = "--settings=config.settings.production"
def prod():
env.target = PRODUCTION
env.compose = ["staging.yml", "production.yml"]
env.settings = "--settings=config.settings.production"
# 장고 커맨드
# ----------------------------------------------------------------
def makemessages(locale):
# locale에 해당하는 번역 파일 생성
local(f"./manage.py makemessages -i venv -l {locale}")
def runserver():
local(f"python manage.py runserver {env.settings}")
def load_languages():
local(
f"python manage.py loaddata algo_sports/codes/fixtures/programming_language.json {env.settings}"
)
def shell():
if "local" in env.settings:
local(f"python manage.py shell_plus {env.settings}")
else:
local(f"python manage.py shell {env.settings}")
# Celery worker
# ----------------------------------------------------------------
def celery():
local("celery -A config.celery_app worker -l info")
# Docker 커맨드
# ----------------------------------------------------------------
def build():
cmd = "docker-compose "
for compose in env.compose:
cmd += f"-f {compose} "
cmd += "build"
local(cmd)
def up(app="", option=""):
cmd = "docker-compose "
for compose in env.compose:
cmd += f"-f {compose} "
cmd += "up"
local(f"{cmd} {option} {app}")
def down(app="", option=""):
cmd = "docker-compose "
for compose in env.compose:
cmd += f"-f {compose} "
cmd += "down"
local(f"{cmd} {option} {app}")
def push():
cmd = "docker-compose "
for compose in env.compose:
cmd += f"-f {compose} "
cmd += "push"
local(cmd)
# Deploy 커맨드
# ----------------------------------------------------------------
def deploy():
local(
"""
CONFIG_NAME=algo-config
PROJECT_NAME=algo-service
ecs-cli compose \
--project-name $PROJECT_NAME \
--file staging.yml \
--file production.yml \
--ecs-params ./aws/ecs-params.yml \
service up \
--create-log-groups \
--cluster-config $CONFIG_NAME \
--container-name nginx \
--container-port 80 \
--target-group-arn arn:aws:elasticloadbalancing:ap-northeast-2:648240308375:targetgroup/target/e3086c4f494a30c4 \
--launch-type EC2
"""
)