-
Notifications
You must be signed in to change notification settings - Fork 113
/
fabfile.py
58 lines (49 loc) · 1.31 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
"""
一个Flask专用的fabfile
1. 安装 Python3
2. 安装 fabric3
`pip install fabric3`
3. 运行脚本
**必须**在 bash 命令行当前目录下运行
eg:git 中的 git-bash 命令行
`fab env` 建立 pipenv 环境
`fab init` 初始化 flask 环境
------ 开发中 ------
`fab req` 导出 requirements.txt
`fab docker` 建立 docker 配置
`fab run` 运行 docker 容器
"""
import codecs
from fabric.api import local, lcd
def env():
local("pipenv --python 3.8")
def init():
local("pipenv install flask flask_cors")
def req():
local("pipenv run pip freeze > requirements.txt")
def docker():
with codecs.open("Dockerfile", "w", encoding="utf-8") as f:
f.write(f'''
FROM python:3.8-alpine
RUN mkdir /usr/src/app -p
COPY . /usr/src/app
WORKDIR /usr/src/app
RUN pip install -r requirements.txt -i https://mirrors.aliyun.com/pypi/simple/
CMD python application.py
''')
with codecs.open("docker-compose.yml", "w", encoding="utf-8") as f:
f.write(f'''
version: '3'
services:
web:
build: .
ports:
- "5000:5000"
''')
def run():
local("docker-compose up -d")
def stop():
local("docker-compose stop")
local("docker-compose down")
local("docker-compose down --rmi all")
local("docker-compose down -v")