-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfabfile.py
132 lines (93 loc) · 4.18 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
import os
import json
import socket
import datetime
import requests
import uuid
from fabric import task, Connection
from invoke import run
BASE_DIR = "/opt/src"
OPENAPI_GENERATOR_VERSION="5.0.0-beta2"
OPENAPI_GENERATOR_LIBRARY_NAME="web2pyrestful"
DEV_WEB_CLIENT_IP="192.168.205.21"
RELATIVE_PATH_TO_API_FILE = "api/swagger.json"
OPENAPI_STATIC_RELATIVE_DIR = "server/web2py/applications/api/private/openapi_static/"
print "WARNING: THESE ARE SUPPOSED TO BE RUN IN A VIRTUAL MACHINE"
@task
def generateAPISpec(ctx):
"""generates a new swagger.json on disk. equivalent to curl -o http://127.0.0.1:9999/api/autogenerated/swagger.json >> RELATIVE_PATH_TO_API_FILE"""
url = "http://127.0.0.1:9999/api/autogenerated/swagger.json"
result = requests.get(url).json()
with open(RELATIVE_PATH_TO_API_FILE,"w") as apifile:
json.dump(result,apifile)
@task
def generateAPISpecClient(ctx):
"""generates a new Typescript rest client api from swagger.json on disk"""
relative_path_to_api_file = RELATIVE_PATH_TO_API_FILE
relative_path_to_libs_dir = "src/client/ionic/src/lib/"
output_api_library_name = OPENAPI_GENERATOR_LIBRARY_NAME
relative_path_to_lib_output = relative_path_to_libs_dir + output_api_library_name
path = BASE_DIR + "/" + relative_path_to_api_file
contents = json.load(open(path,"r"))
api_url = contents["servers"][0]["url"]
print "[compileAPIClient]: %s" % api_url
image = "openapitools/openapi-generator-cli:v%s" % OPENAPI_GENERATOR_VERSION
docker_command = 'docker run --rm -v "%s:/local" %s' % (BASE_DIR,image)
shell_cmd = 'generate -i /local/%s -g typescript-axios -o /local/%s' % (
relative_path_to_api_file,relative_path_to_lib_output)
cmd = docker_command + " " + shell_cmd
result = run(cmd, hide=False, warn=True)
@task
def extractSchemasAndPathsFromEditorOutput(ctx):
""" parses editor-output.json into separate paths.json and schemas.json files for autogenerator to load
this was done so you can edit the schemas and merge them
"""
path_base = OPENAPI_STATIC_RELATIVE_DIR
path_editor_output = path_base + "editor-output.json"
path_schemas_input = path_base + "schemas.json"
path_paths_input = path_base + "paths.json"
contents = json.load(open(path_editor_output,"r"))
schemas = contents["components"]["schemas"]
paths = contents["paths"]
json.dump(paths,open(path_paths_input,"w"))
json.dump(schemas,open(path_schemas_input,"w"))
@task
def startAPISpecEditor(ctx):
"""starts swagger editor ui on 192.168.205.21:8080"""
cmd = "docker-compose -f env/development/swagger-editor.yml up -d"
print cmd
result = run(cmd, hide=False, warn=True)
@task
def startDevWebClientServer(ctx):
"""start ionic web server on port 8100 without opeoning browser"""
start_cmd = "ionic serve --host=%s --no-open" % DEV_WEB_CLIENT_IP
cmd = "cd client/ionic && %s" % start_cmd
result = run(cmd, hide=False, warn=True)
@task
def startDevAPIServer(ctx):
"""start web2py web server on port 9999 without gui (no admin)"""
print "NOTE: no access to admin because not hosted on 127.0.0.1"
start_cmd = "python web2py.py -a 'password' -i 0.0.0.0 -p 9999 --nogui"
cmd = "cd server/web2py && %s" % start_cmd
result = run(cmd, hide=False, warn=True)
@task
def startES(ctx):
"""start ephemeral elasticsearch on port 9200. modify settings in compose to add a volume and persist data"""
print "modify settings in compose to add a volume and persist data"
cmd = "docker-compose -f server/elasticsearch/docker-compose.yml up -d"
result = run(cmd, hide=False, warn=True)
@task
def testDockerCompose(ctx):
"""turns on and off a busybox image using docker-compose"""
cmd = "docker-compose -f tests/docker-compose.yml up -d"
result = run(cmd, hide=False, warn=True)
assert(result.ok)
cmd = "docker-compose -f tests/docker-compose.yml down"
result = run(cmd, hide=False, warn=True)
assert(result.ok)
@task
def typescriptDebug(ctx):
"""check typescript compile diagnostics"""
path = BASE_DIR + "/client/ionic"
cmd = "cd %s && tsc --noEmit --diagnostics " % path
result = run(cmd, hide=False, warn=True)