-
Notifications
You must be signed in to change notification settings - Fork 0
/
package-glue-job.sh
executable file
·107 lines (75 loc) · 2.16 KB
/
package-glue-job.sh
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
#!/bin/bash
FULL_JOB_PATH=$1
if [[ "$FULL_JOB_PATH" != *.py ]]
then
echo "Expected job-path to end with .py"
exit 1
fi
JOB_DIR=$(dirname "$FULL_JOB_PATH")
JOB_NAME=$(basename "$JOB_DIR")
JOB_SCRIPT=$(basename "$FULL_JOB_PATH")
DIST_PATH="./glue-dist/$JOB_NAME"
echo
echo "Job located at: $JOB_DIR"
echo "Job name: $JOB_NAME"
echo "Entry point: $JOB_SCRIPT"
echo "Output path: $DIST_PATH"
echo
# Prep
rm -rf "$DIST_PATH"
mkdir -p "$DIST_PATH/.workspace"
# Copy src to workspace and move to workspace
echo "* Copying source files from $JOB_DIR to $DIST_PATH/.workspace"
cp -LR "$JOB_DIR/." "$DIST_PATH/.workspace/"
pushd "$DIST_PATH" > /dev/null
pushd ".workspace" > /dev/null
# Move main job file
echo "* Copying $JOB_SCRIPT as-is"
mv -v "$JOB_SCRIPT" ..
# Move .jar files
echo "* Copying .jar files (if any)"
find . -name '*.jar' -exec mv -v {} .. \;
# Download external dependencies
if [[ -f Pipfile ]]
then
echo "* Downloading external dependencies"
echo "Creating requirements.txt"
pipenv requirements > requirements.txt
echo "Installing dependencies..."
python -m pip install -q -r requirements.txt --no-deps -t .
else
echo "No Pipfile found, assuming no external dependencies are being used."
fi
# Create Wheel Package
echo "* Creating Wheel package"
read -r -d '' CMD <<EOF
from setuptools import setup, find_namespace_packages
from glob import glob
from os.path import basename, splitext
# Returns the filename of all .py files in the current directory without their extensions.
def find_py_modules():
file_paths = glob("*.py")
file_names = [basename(file_path) for file_path in file_paths]
py_modules = [splitext(file_name)[0] for file_name in file_names]
return py_modules
setup(
name="deps",
version="1.0",
packages=find_namespace_packages(),
py_modules=find_py_modules(),
setup_requires=['wheel'],
)
EOF
python -c "$CMD" -q bdist_wheel --dist-dir .. || exit 2
# Cleanup
popd > /dev/null # out of workspace
rm -rf .workspace
# Done
popd > /dev/null # out of $DIST_PATH
echo
echo "Packaging completed:"
echo
ls -1 "$DIST_PATH"/*
echo
echo "You should now upload all files in $DIST_PATH to S3"
echo