-
Notifications
You must be signed in to change notification settings - Fork 4
/
amp_build.py
executable file
·82 lines (65 loc) · 2.93 KB
/
amp_build.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
#!/bin/env python3
#
# Build the amp rest tarball for distribution
#
import argparse
import logging
import tempfile
from pathlib import Path
import shutil
import sys
import os
import subprocess
import xml.etree.ElementTree as ET
from amp.package import *
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--debug', default=False, action='store_true', help="Turn on debugging")
parser.add_argument('--package', default=False, action='store_true', help="build a package instead of installing")
parser.add_argument('--clean', default=False, action='store_true', help="Clean previous build & dependencies")
parser.add_argument('destdir', help="Output directory for package or webserver path root", nargs='?')
args = parser.parse_args()
logging.basicConfig(format="%(asctime)s [%(levelname)-8s] (%(filename)s:%(lineno)d) %(message)s",
level=logging.DEBUG if args.debug else logging.INFO)
if args.package and not args.destdir:
logging.error("You must supply a destdir when building a package")
exit(1)
if args.destdir and not Path(args.destdir).is_dir():
logging.error("Destination directory not actually a directory.")
exit(1)
if 'JAVA_HOME' not in os.environ:
logging.error("Please set the JAVA_HOME to a JDK11 Path (this won't build on JDK17)")
exit(1)
logging.info("Building REST WAR")
os.chdir(sys.path[0])
try:
if args.clean:
subprocess.run(['mvn', 'clean'], check=True)
subprocess.run(['mvn', 'install', '-DskipTests'], check=True)
except Exception as e:
logging.error(f"Maven build failed: {e}")
exit(1)
warfile = list(Path("target").glob("*.war"))[0]
if not args.package:
logging.info(f"The war file is in: {warfile}")
if args.destdir:
shutil.copy(warfile, args.destdir + "/rest.war")
logging.info(f"Copied warfile to {args.destdir}/rest.war")
exit(0)
# OK so the .war file is in the target directory.
# find the version:
root = ET.parse("pom.xml").getroot()
version = root.find('{http://maven.apache.org/POM/4.0.0}version').text
with tempfile.TemporaryDirectory() as tmpdir:
shutil.copy(warfile, tmpdir + "/rest.war")
pfile = create_package("amp_rest", version, "tomcat/webapps",
Path(args.destdir), Path(tmpdir),
hooks={'post': 'amp_hook_post.py',
'config': 'amp_hook_config.py',
'start': 'amp_hook_start.py'},
user_defaults='amp_config.user_defaults',
system_defaults='amp_config.system_defaults',
depends_on=['tomcat', 'galaxy', 'mediaprobe'])
logging.info(f"New package is in {pfile}")
if __name__ == "__main__":
main()