-
Notifications
You must be signed in to change notification settings - Fork 0
/
cli
executable file
·112 lines (92 loc) · 3.01 KB
/
cli
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
#!/usr/bin/python3
"""
Command Line Interface (CLI) for various tasks.
"""
import click
import docker
import sys
import time
import requests
from subprocess import call
dclient = docker.from_env()
@click.group()
def cli():
"""Command line interface."""
pass
@cli.command()
@click.argument('yml', type=click.Path(exists=True))
def start(yml):
""" Run server with a given yml config file.
Utilizes docker-compose.
"""
cmd = ['docker-compose', '-f', 'docker-compose.yml',
'-f', yml, 'up', '-d',
'--build', '--force-recreate', '-t 1']
returncode = call(cmd)
returncode = call(['docker', 'ps'])
@cli.command()
@click.option('-f', '--force', is_flag=True)
def stop(force):
""" Stop all running docker containers. """
for container in dclient.containers.list():
if force:
container.kill()
else:
container.stop()
returncode = call(['docker', 'ps'])
@cli.command()
def test():
""" Run unit tests. """
returncode = call(['docker', 'exec', '-it',
'flowchat_web',
'python3', '/code/flowchat/manage.py',
'test'])
click.echo('Unit tests ran.')
@cli.command()
def makemigrations():
""" Make django migrations. """
returncode = call(['docker', 'exec', '-it',
'flowchat_web',
'python', '/code/flowchat/manage.py', 'makemigrations'])
@cli.command()
def migrate():
""" Run django migrations. """
returncode = call(['docker', 'exec', '-it',
'flowchat_web',
'python', '/code/flowchat/manage.py', 'migrate'])
@cli.command()
def createSuperUser():
""" Create a django super user """
returncode = call(['docker', 'exec', '-it',
'flowchat_web',
'python', '/code/flowchat/manage.py',
'createsuperuser'])
@cli.command()
def list():
""" List running docker containers. """
returncode = call(['docker', 'ps'])
@cli.command()
@click.argument('container')
def bash(container):
"""Connect to a docker container bash."""
containerobj = dclient.containers.get(container)
click.echo('Connected to ' + containerobj.name)
click.echo('Type "exit" to return.')
returncode = call(['docker', 'exec', '-it', container, '/bin/bash'])
@cli.command()
def clearCache():
"""Clears Memcache"""
returncode = call(['docker', 'exec', '-it',
'flowchat_web',
'python3', '/code/flowchat/manage.py',
'shell', '-c', "'from django.core.cache import cache; cache.clear()'"])
click.echo('Django memcached cleared.')
@cli.command()
def clearLockouts():
""" Clears login lockouts """
returncode = call(['docker', 'exec', '-it',
'flowchat_web',
'python', '/code/flowchat/manage.py',
'axes_reset'])
if __name__ == '__main__':
cli()