|
#!/bin/bash -xe |
|
|
|
BASEDIR=$(cd "$(dirname "$0")/.."; pwd) |
|
echo "project directory $BASEDIR" |
|
|
|
: ${TARGET_DIR:=${BASEDIR}/tmp} |
|
|
|
rm -rf ${TARGET_DIR} |
|
mkdir -p ${TARGET_DIR} |
|
|
|
# arg 1 - space separated paths to check |
|
# arg 2 - friendly name for error messages |
|
function findFile() { |
|
for x in $1; do |
|
if [[ -f ${x} ]]; then |
|
echo ${x} |
|
return |
|
fi |
|
done |
|
>&2 echo "Could not find $2 to use" |
|
exit 1 |
|
} |
|
|
|
# modify this accordingly depending on the name and whether python3.6 (or python3.7 if that's your runtime) is on the path |
|
# here i pull in python 3.6 installed from centos-release-scl-rh |
|
PYTHON=$(findFile "$(which python3.6) /opt/rh/rh-python36/root/usr/bin/python $(which python3)" "python3.6") |
|
PIP=$(findFile "$(which pip3.6) /opt/rh/rh-python36/root/usr/bin/pip3.6 $(which pip3)" "pip3.6") |
|
# newer python doesn't use the virtualenv script, instead uses "python -m venv" |
|
VIRTUALENV="$PYTHON -m venv" |
|
|
|
# barfs if aws-sam-cli is installed in venv due to dependencies, so install at user level first |
|
${PIP} install --user aws-sam-cli |
|
export PATH=$(${PYTHON} -m site --user-base)/bin:$PATH |
|
|
|
echo "Activating virtualenv" |
|
${VIRTUALENV} venv |
|
|
|
if [[ -f venv/bin/activate ]]; then |
|
source venv/bin/activate |
|
else |
|
source venv/Scripts/activate |
|
fi |
|
|
|
# update pip and wheel |
|
pip install -U pip wheel |
|
|
|
#################################################### |
|
# TODO TESTS |
|
# create a setup.py with test dependencies then use: |
|
#################################################### |
|
#pip install .[tests] |
|
#py.test |
|
|
|
pwd |
|
mkdir -p .aws-sam/build |
|
|
|
sam build --debug |
|
|
|
if [[ -z "${BUCKET}" ]] || [[ -z "${PREFIX}" ]]; then |
|
>&2 echo "Skipping package and upload step as BUCKET or PREFIX is not set" |
|
exit 1 |
|
fi |
|
|
|
cd .aws-sam/build |
|
|
|
aws cloudformation package \ |
|
--template-file template.yaml \ |
|
--output-template-file ${TARGET_DIR}/serverless-output.yaml \ |
|
--s3-bucket ${BUCKET} \ |
|
--s3-prefix ${PREFIX} |
|
|
|
echo "to deploy run: (replacing YOUR_SLACK_TOKEN with your token)" |
|
echo "aws cloudformation deploy \ |
|
--template-file ${TARGET_DIR}/serverless-output.yaml \ |
|
--stack-name hipchat-proxy \ |
|
--parameter-overrides \ |
|
SlackToken=YOUR_SLACK_TOKEN \ |
|
EnvName=${ENV_NAME}" |
This comment has been minimized.
https://github.com/trustpilot/python-lambdarest
has been updated to support Application Load Balancer:
pip install lambdarest>=5.4.0