-
Notifications
You must be signed in to change notification settings - Fork 0
/
release_prod.py
54 lines (37 loc) · 1.36 KB
/
release_prod.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
#!/usr/bin/env python3
import subprocess
import os
import shutil
current_directory = os.path.abspath(os.getcwd())
def _execute_cmd(command):
"""Executes the command in current shell and waits for 0 exit code."""
print('About to run command: %s' % command)
subprocess.check_call(command, shell=True)
def prepare_css():
"""Prepares css for prod deployment."""
minify_css_command = 'npm run minify-css'
_execute_cmd(minify_css_command)
# after that we need to copy
shutil.copy(os.path.join(current_directory, 'css-dist/main.min.css'),
os.path.join(current_directory, 'app/static/styles/main.min.css'))
# remove css folder after that
shutil.rmtree(os.path.join(current_directory, 'css-dist'))
def prepare_js():
"""prepare js for prod deployment."""
# first remove all content of js folder
js_folder_path = os.path.join(current_directory, 'app\static\js')
shutil.rmtree(js_folder_path, ignore_errors=True)
os.mkdir(js_folder_path)
# generate new files
generate_js_cmd = 'npm run build-prod'
_execute_cmd(generate_js_cmd)
def deploy_app_on_gcp():
deploy_app_on_gcp_cmd = 'gcloud app deploy app.yaml --no-cache'
_execute_cmd(deploy_app_on_gcp_cmd)
def main():
"""Runs release prod"""
prepare_css()
prepare_js()
deploy_app_on_gcp()
if __name__ == '__main__':
main()