-
Notifications
You must be signed in to change notification settings - Fork 171
/
fabfile.py
132 lines (102 loc) · 3.59 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
import os
import tempfile
from fabric.api import *
from will import VERSION
SITE_DIR = "site"
WHITELIST_DIRS = [".git", ]
WHITELIST_FILES = [".gitignore", ]
SANITY_CHECK_PROJECT_FILES = ["fabfile.py", "setup.py", "mkdocs.yml"]
SANITY_CHECK_BUILD_FILES = ["index.html", "js", "css"]
CTAG = os.environ.get("CTAG", "")
DOCKER_BUILDS = [
{
"ctagname": "heywill/will:python2.7%s" % CTAG,
"name": "heywill/will:python2.7" % os.environ,
"dir": "will/will-py2/",
},
{
"ctagname": "heywill/will:python2.7%s" % CTAG,
"name": "heywill/will:latest" % os.environ,
"dir": "will/will-py2/",
},
{
"ctagname": "heywill/will:python3.7%s" % CTAG,
"name": "heywill/will:python3.7" % os.environ,
"dir": "will/will-py3/",
},
]
DOCKER_PATH = os.path.join(os.getcwd(), "docker")
def _splitpath(path):
path = os.path.normpath(path)
return path.split(os.sep)
def tag_release():
# Tag the release:
local("git tag %s" % VERSION)
local("git push --tags")
def upload_release():
local("python setup.py sdist upload")
@task
def release():
deploy_docs()
upload_release()
tag_release()
def deploy_docs():
# Sanity check dir.
root_dir = os.getcwd()
assert all([os.path.exists(os.path.join(root_dir, f)) for f in SANITY_CHECK_PROJECT_FILES])
local("rm -rf %s" % SITE_DIR)
local("mkdocs build")
tempdir = tempfile.mkdtemp()
local("mv %s/* %s" % (SITE_DIR, tempdir))
current_branch = local("git rev-parse --abbrev-ref HEAD", capture=True)
last_commit = local(r"git log -1 --pretty=\%B", capture=True)
# Add the new site to build
local("git checkout gh-pages")
# Sanity check dir.
root_dir = os.getcwd()
assert all([os.path.exists(os.path.join(root_dir, f)) for f in SANITY_CHECK_BUILD_FILES])
for root, dirs, files in os.walk(root_dir, topdown=False):
for name in files:
if name not in WHITELIST_FILES and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
# print("removing %s" % (os.path.join(root, name)))
os.remove(os.path.join(root, name))
for name in dirs:
if name not in WHITELIST_DIRS and not any([r in WHITELIST_DIRS for r in _splitpath(root)]):
print("removing %s" % (os.path.join(root, name)))
try:
os.rmdir(os.path.join(root, name))
except:
# Handle symlinks
os.remove(os.path.join(root, name))
local("cp -rv %s/* ." % tempdir)
result = local("git diff --exit-code", warn_only=True)
if result.return_code != 0:
local("git add -A .")
local("git commit -m 'Auto-update of docs: %s'" % last_commit)
local("git push")
else:
print("No changes to the docs.")
local("git checkout %s" % current_branch)
@task
def docker_build():
print("Building Docker Images...")
with lcd(DOCKER_PATH):
for b in DOCKER_BUILDS:
local("docker build -t %(ctagname)s %(dir)s" % b)
def docker_tag():
print("Building Docker Releases...")
with lcd(DOCKER_PATH):
for b in DOCKER_BUILDS:
local("docker tag %(ctagname)s %(name)s" % b)
def docker_push():
print("Pushing Docker to Docker Cloud...")
with lcd(DOCKER_PATH):
local("docker login -u $DOCKER_USER -p $DOCKER_PASS")
local("docker push heywill/will:python2.7")
local("docker push heywill/will:python3.7")
local("docker push heywill/will:latest")
@task
def docker_deploy():
docker_build()
docker_tag()
docker_push()