Skip to content
This repository was archived by the owner on Dec 1, 2022. It is now read-only.

Commit cbcef1b

Browse files
committed
Fix up build script
1 parent 85e5e71 commit cbcef1b

File tree

2 files changed

+76
-12
lines changed

2 files changed

+76
-12
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,9 @@ jobs:
153153
# most likely be able leverage the functionality of upload-artifact v2(+)
154154
# to upload a single file as an artifact.
155155
- name: Unzip produced zip
156-
run: unzip skeleton-aws-lambda.zip -d lambda_zip_contents
156+
run: |
157+
unzip skeleton-aws-lambda_${{ matrix.python-version }}.zip \
158+
-d lambda_zip_contents
157159
- name: Upload artifacts
158160
uses: actions/upload-artifact@v2
159161
with:

build.sh

Lines changed: 73 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,95 @@ set -o nounset
44
set -o errexit
55
set -o pipefail
66

7-
if [ "$#" -ne 1 ]
8-
then
9-
exit 1
10-
else
11-
PY_VERSION="$1"
12-
fi
7+
PY_VERSION="3.8"
8+
FILE_BASE="skeleton-aws-lambda"
9+
10+
# Print usage information and exit with the provided exit code.
11+
function usage {
12+
echo "Usage:"
13+
echo " ${0##*/} [options]"
14+
echo
15+
echo "Options:"
16+
echo " -o, --output-file BASENAME Base output file name to use [default: $FILE_BASE]."
17+
echo " -p, --python-version VERSION Python version to use [default: $PY_VERSION]."
18+
echo " -h, --help Display this message."
19+
echo
20+
echo "Notes:"
21+
echo "- Outputs files in the format 'BASENAME_VERSION.zip'."
22+
echo "- Requires Docker and Docker Compose."
23+
exit "$1"
24+
}
25+
26+
# Check for required external programs. If any are missing output a list of all
27+
# requirements and then exit.
28+
function check_dependencies {
29+
required_tools="docker docker-compose"
30+
for tool in $required_tools
31+
do
32+
if [ -z "$(command -v "$tool")" ]
33+
then
34+
echo "This script requires the following tools to run:"
35+
for item in $required_tools
36+
do
37+
echo "- $item"
38+
done
39+
exit 1
40+
fi
41+
done
42+
}
43+
44+
while (( "$#" ))
45+
do
46+
case "$1" in
47+
-h|--help)
48+
usage 0
49+
;;
50+
-o|--output-name)
51+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]
52+
then
53+
FILE_BASE=$2
54+
shift 2
55+
else
56+
usage 1
57+
fi
58+
;;
59+
-p|--python-version)
60+
if [ -n "$2" ] && [ "${2:0:1}" != "-" ]
61+
then
62+
PY_VERSION=$2
63+
shift 2
64+
else
65+
usage 1
66+
fi
67+
;;
68+
-*)
69+
usage 1
70+
;;
71+
esac
72+
done
73+
74+
check_dependencies
1375

1476
###
1577
# Define the name of the Lambda zip file being produced.
1678
###
17-
ZIP_FILE=skeleton-aws-lambda.zip
79+
ZIP_FILE="${FILE_BASE}_${PY_VERSION}.zip"
1880

1981
###
2082
# Set up the Python virtual environment.
2183
# We use --system-site-packages so the venv has access to the packages already
2284
# installed in the container to avoid duplicating what will be available in the
2385
# lambda environment on AWS.
2486
###
25-
VENV_DIR=/venv
26-
python -m venv --system-site-packages $VENV_DIR
87+
VENV_DIR="/venv"
88+
python -m venv --system-site-packages "$VENV_DIR"
2789

2890
# Here shellcheck complains because it can't follow the dynamic path.
2991
# The path doesn't even exist until runtime, so we must disable that
3092
# check.
3193
#
3294
# shellcheck disable=1090
33-
source $VENV_DIR/bin/activate
95+
source "$VENV_DIR/bin/activate"
3496

3597
###
3698
# Upgrade pip.
@@ -70,7 +132,7 @@ cp lambda_handler.py "$BUILD_DIR"
70132
###
71133
# Zip it all up.
72134
###
73-
OUTPUT_DIR=/output
135+
OUTPUT_DIR="/output"
74136
if [ ! -d "$OUTPUT_DIR" ]
75137
then
76138
mkdir "$OUTPUT_DIR"

0 commit comments

Comments
 (0)