/
fabfile.py
68 lines (53 loc) · 1.37 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
import sys
from pathlib import Path
from fabric import task
from patchwork import info, packages
@task
def configure(ctx):
"""
Configure host with Docker, docker-compose, etc.
"""
print("Warning! This command is still under development!")
# Check distro
distro = info.distro_family(ctx)
if distro != "debian":
print(f"Only supports Debian-based distros, got '{distro}'", file=sys.stderr)
return
distro = info.distro_name(ctx)
print(f"Installing packages on {distro} machine...")
print("This recipe was tested on Ubuntu.")
# Install required packages
packages.package(ctx, "python3-pip")
ctx.run("pip3 install docker-compose")
git_clone(ctx)
@task
def git_clone(ctx):
"""
Clone repository.
"""
ctx.run("git clone https://github.com/pydemic/pydemic-ui.git app")
@task
def git_pull(ctx):
"""
Update repository.
"""
ctx.run("cd app && git pull -f")
@task
def download(ctx, file, name=None):
"""
Download file from server.
"""
data = ctx.get(file)
if name is None:
name = Path(file).name
with open(name, "bw") as fd:
fd.write(data)
@task
def update(ctx):
"""
Update server
"""
git_pull(ctx)
ctx.sudo("cd app && docker-compose build")
ctx.sudo("cd app && docker-compose down")
ctx.sudo("cd app && docker-compose up")