8000 Fix scripts by andersoncontreira · Pull Request #1 · madeiramadeirabr/template-serverless-lambda-python · GitHub
[go: up one dir, main page]

Skip to content
This repository was archived by the owner on May 23, 2023. It is now read-only.

Fix scripts #1

Merged
merged 5 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ services:
SERVICES: sqs,lambda,cloudwatch,s3
DOCKER_HOST: unix:///var/run/docker.sock
PORT_WEB_UI: 9070
#LAMBDA_EXECUTOR: docker # está dando erro via docker
LAMBDA_EXECUTOR: local
LAMBDA_EXECUTOR: docker # está dando erro via docker
# LAMBDA_EXECUTOR: local
DEBUG: 1
HOSTNAME_EXTERNAL: localstack
networks:
Expand Down
1 change: 1 addition & 0 deletions examples/lambda_api/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ imagedefinitions.json
config/integration.en
/node_modules/

/lambda-full.zip
3 changes: 3 additions & 0 deletions examples/lambda_api/.projectrc
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
PROJECT_NAME=template-serverless-lambda-python-lambda-api
NETWORK_NAME=service-python
APP_QUEUE=test-queue
APP_LAMBDA_NAME=lambda_api
APP_LAMBDA_EVENT_SOURCE=false
2 changes: 1 addition & 1 deletion examples/lambda_api/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ def event_list(event_type):
data = {}

response.set_data(data)
response.set_total()
response.set_total(len(data))

# event_tracker.track(event_hash, data)
return response.get_response(status_code)
Expand Down
9 changes: 7 additions & 2 deletions examples/lambda_api/docker/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,19 @@ RUN apk add --no-cache build-base \
# upgrade pip
RUN pip install --upgrade pip

RUN rm -Rf ./vendor/*

# Install requirements
COPY requirements.txt requirements-vendor.txt ./
RUN pip install --no-cache-dir -r requirements.txt \
&& pip install --no-cache-dir -r requirements-vendor.txt

# Flask compatibility with Python 3.8
RUN pip uninstall dataclasses -y
RUN rm -Rf ./vendor/dataclasses-0.8.dist-info/ ./vendor/dataclasses.py

# Copy project files
COPY . .

#CMD [ "flask", "run", "--host", "0.0.0.0" ]
CMD [ "python3", "server.py" ]
CMD [ "flask", "run", "--host", "0.0.0.0" ]

3 changes: 1 addition & 2 deletions examples/lambda_api/requirements-vendor.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
boto3
pymysql
boto3
1 change: 1 addition & 0 deletions examples/lambda_api/requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ Flask
pyyaml
apispec
marshmallow
pymysql
97 changes: 97 additions & 0 deletions examples/lambda_api/scripts/boot-lambda.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
#!/bin/bash
# -----------------------------------------------------------------------------
# Current file variables
# -----------------------------------------------------------------------------
debug=false
parent_folder="../"
current_path=$(pwd)/
current_path_basename=$(basename $(pwd))
current_file_full_path=$0
# echo $current_filepath
current_file_name=$(basename -- "$0")
# echo $current_filename
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
current_file_full_path="./${current_file_full_path}"
current_file_path="./"
else
current_file_path="${current_file_full_path/$current_file_name/''}"
fi

current_file_path_basename=$(basename -- "$current_file_path")
#echo "xxxxx current_file_path_basename $current_file_path_basename"

if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
# echo 'aq'
current_parent_folder="../"
else
# echo 'naq'
current_file_path_basename=$current_file_path_basename/
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
fi


if [ debug ]; then
echo '----------------------------------------'
echo "$0 - Script variables"
echo '----------------------------------------'
echo "current_path: $current_path"
echo "current_path_basename: $current_path_basename"
echo "current_file_full_path: $current_file_full_path"
echo "current_file_name: $current_file_name"
echo "current_file_path: $current_file_path"
echo "current_parent_folder: $current_parent_folder"
echo '----------------------------------------'
fi

echo '----------------------------------------'
echo "$0 - Booting lambda"
echo '----------------------------------------'
echo 'Installing dependencies...'
echo "Requirements file: ${current_parent_folder}requirements.txt"
if test -f ${current_parent_folder}requirements.txt; then
python3 -m pip install -r ${current_parent_folder}requirements.txt -t ${current_parent_folder}vendor
# cat ${current_parent_folder}requirements.txt
echo "requirements..."
fi

echo "Requirements file: ${current_parent_folder}requirements-vendor.txt"
if test -f ${current_parent_folder}requirement.s-vendor.txt; then
python3 -m pip install -r ${current_parent_folder}requirements-vendor.txt -t ${current_parent_folder}vendor
# cat ${current_parent_folder}requirements-vendor.txt
echo "requirements vendor..."
fi

read -p "Press enter to continue..."

#echo 'Creating resource dependencies...'
#echo "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"

if test -f "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"; then

if test -f ${current_parent_folder}.projectrc; then
source ${current_parent_folder}.projectrc
fi

if [ -z "$APP_LAMBDA_NAME" ]; then
echo 'APP_LAMBDA_NAME not defined'
exit 1
else
echo '----------------------------------------'
echo "$0 - Creating the lambda: $APP_LAMBDA_NAME"
echo '----------------------------------------'
${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh $current_filename_path $APP_LAMBDA_NAME

read -p "Press enter to continue..."

if test $APP_LAMBDA_EVENT_SOURCE = true;then
echo '----------------------------------------'
echo "$0 - Creating the event source: $APP_LAMBDA_NAME"
echo '----------------------------------------'
${current_parent_folder}scripts/localstack/lambda/create-event-source-mapping.sh $APP_LAMBDA_NAME $APP_QUEUE
else
echo 'There is no event source for this lambda'
fi
fi
else
echo "File not found: ${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"
fi
10 changes: 0 additions & 10 deletions examples/lambda_api/scripts/boot-lambdas.sh

This file was deleted.

32 changes: 31 additions & 1 deletion examples/lambda_api/scripts/boot-queues.sh
Original file line number Diff line number Diff line change
@@ -1 +1,31 @@
./scripts/localstack/sqs/create-queue.sh test-queue
#!/bin/bash
current_path=$(basename $(pwd))
current_filename=$(basename -- "$0")
current_filename_path=$0
# echo $current_filename_path
current_filename_path="${current_filename_path/$current_filename/''}"
# echo $current_filename_path
current_filename_path="${current_filename_path/scripts\//''}"
# echo $current_filename_path
current_filename_path_basename=$(basename -- "$current_filename_path")

echo "current_path: $current_path"
echo "current_filename: $current_filename"
echo "current_filename_path: $current_filename_path"
echo "current_filename_path_basename: $current_filename_path_basename"

if test -f ${current_filename_path}/scripts/localstack/sqs/create-queue.sh; then

if test -f ${current_filename_path}.projectrc; then
source ${current_filename_path}.projectrc
fi

if [ -z "$APP_QUEUE" ]; then
echo 'APP_QUEUE not defined'
exit 1
else
echo "Creating the queue: $APP_QUEUE"
${current_filename_path}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
fi
fi

100 changes: 79 additions & 21 deletions examples/lambda_api/scripts/boot.sh
Original file line number Diff line number Diff line change
@@ -1,22 +1,80 @@
#!/bin/bash
echo 'Validating jd installation..'
/usr/bin/jq --help > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo 'Installing'
# download directly into ~/bin_compciv
sudo curl http://stedolan.github.io/jq/download/linux64/jq -o /usr/bin/jq
# give it executable permissions
sudo chmod a+x /usr/bin/jq
fi

echo 'Validate connection'
./scripts/boot-validate-connection.sh

echo 'Booting db...'
./scripts/boot-db.sh

echo 'Create the queues...'
./scripts/boot-queues.sh

echo 'Create the lambdas...'
./scripts/boot-lambdas.sh
# -----------------------------------------------------------------------------
# Current file variables
# -----------------------------------------------------------------------------
debug=false
parent_folder="../"
current_path=$(pwd)/
current_path_basename=$(basename $(pwd))
current_file_full_path=$0
# echo $current_filepath
current_file_name=$(basename -- "$0")
# echo $current_filename
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
current_file_full_path="./${current_file_full_path}"
current_file_path="./"
else
current_file_path="${current_file_full_path/$current_file_name/''}"
fi
if [ debug ]; then
echo '----------------------------------------'
echo "$0 - Script variables"
echo '----------------------------------------'
echo "current_path: $current_path"
echo "current_path_basename: $current_path_basename"
echo "current_file_full_path: $current_file_full_path"
echo "current_file_name: $current_file_name"
echo "current_file_path: $current_file_path"
echo '----------------------------------------'
fi


echo '----------------------------------------'
echo "$0 - jq check"
echo '----------------------------------------'
echo 'Validating jq installation...'
/usr/bin/jq --version > /dev/null 2>&1
if [ $? -ne 0 ]; then
echo 'Installing jq...'
# download directly into ~/bin_compciv
sudo curl http://stedolan.github.io/jq/download/linux64/jq -o /usr/bin/jq
# give it executable permissions
sudo chmod a+x /usr/bin/jq
else
echo 'jq installed...'
fi

read -p "Press enter to continue..."

echo '----------------------------------------'
echo "$0 - Localstack connection check"
echo '----------------------------------------'
# valida se o Localstack está rodando
if test -f ${current_file_path}boot-validate-connection.sh; then
echo 'Validate connection...'
${current_file_path}boot-validate-connection.sh
else
echo 'There is no connection check file'
fi

read -p "Press enter to continue..."

echo '----------------------------------------'
echo "$0 - Queues boot"
echo '----------------------------------------'
if test -f ${current_file_path}boot-queues.sh; then
${current_file_path}boot-queues.sh
else
echo 'There is no queues to be booted'
fi

read -p "Press enter to continue..."

echo '----------------------------------------'
echo "$0 - Lambda boot"
echo '----------------------------------------'
if test -f ${current_file_path}boot-lambda.sh; then
${current_file_path}boot-lambda.sh
else
echo 'There is no lambda to be booted'
fi
4 changes: 2 additions & 2 deletions examples/lambda_api/scripts/docker/create-network.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
if test -f .projectrc; then
source .projectrc
elif test -f ./bin/.projectrc; then
source ./bin/.projectrc
elif test -f ./scripts/.projectrc; then
source ./scripts/.projectrc
fi

if [ -z "$NETWORK_NAME" ]; then
Expand Down
Loading
0