This repository was archived by the owner on Feb 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathfabfile.py
More file actions
121 lines (94 loc) · 3.14 KB
/
Copy pathfabfile.py
File metadata and controls
121 lines (94 loc) · 3.14 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2016, cloudez Adm. Sis. SA. <hello@cloudez.io>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# On Debian systems, you can find the full text of the license in
# /usr/share/common-licenses/GPL-2
import time
from fabric.api import env, local, puts
#
# available environments
#
def production():
env.user = 'pythonbrasil'
env.deploy_path = '/srv/2017.pythonbrasil.org.br/www'
env.current_path = '/srv/2017.pythonbrasil.org.br/www/current'
env.releases_path = '/srv/2017.pythonbrasil.org.br/www/releases'
env.releases_limit = 2
env.git_origin = 'https://github.com/pythonbrasil/pythonbrasil13-site.git'
env.git_branch = 'master'
env.virtual_environment = '/srv/2017.pythonbrasil.org.br/activate'
#
# end available environments
#
#
# available commands
#
def deploy():
start = time.time()
setup()
checkout()
run_pelican()
releases()
symlink()
cleanup()
final = time.time()
puts('deploy execution finished in %.2fs' % (final - start))
def run_pelican():
local('. {} && cd {} && make html'.format(
env.virtual_environment, env.current_release))
local('ln -nfs {}/fabfile.py {}/output'.format(
env.current_release, env.current_release))
def rollback():
start = time.time()
setup()
releases()
rollback_code()
final = time.time()
puts('execution finished in %.2fs' % (final - start))
#
# end available commands
#
#
# internal commands
#
def setup():
local('mkdir -p {}'.format(env.deploy_path))
local('mkdir -p {}/releases'.format(env.deploy_path))
def checkout():
env.current_release = '{0}/{1:.0f}'.format(env.releases_path, time.time())
local('cd {0}; git clone -q -b {1} -o deploy --depth 1 {2} {3}'.format(
env.releases_path, env.git_branch, env.git_origin,
env.current_release))
def releases():
env.releases = sorted(
local('ls -x {}'.format(env.releases_path), capture=True).split())
def symlink():
local('ln -nfs {0} {1}'.format(env.current_release, env.current_path))
def cleanup():
if len(env.releases) > env.releases_limit:
directories = env.releases
directories.reverse()
del directories[:env.releases_limit]
env.directories = ' '.join(['{0}/{1}'.format(
env.releases_path, release) for release in directories])
local('rm -rf {}'.format(env.directories))
def rollback_code():
if len(env.releases) > 1:
env.current_release = env.releases[-1]
env.previous_revision = env.releases[-2]
env.current_release = '{0}/{1}'.format(
env.releases_path, env.current_revision)
env.previous_release = '{0}/{1}'.format(
env.releases_path, env.previous_revision)
command = 'rm {0}; ln -s {1} {0} && rm -rf {2}'
local(command.format(
env.current_path, env.previous_release, env.current_release))
#
# end internal commands
#