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

Commit 60ad3f0

Browse files
Ajustes e melhorias nos scripts de boot
1 parent 6720ee6 commit 60ad3f0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+448
-121
lines changed

.gitignore

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ imagedefinitions.json
5050
config/integration.en
5151
/node_modules/
5252

53-
/examples/lambda_api/vendor/
54-
/examples/lambda_cron/vendor/
55-
/examples/lambda_s3/vendor/
56-
/examples/lambda_sns/vendor/
57-
/examples/lambda_sqs/vendor/
53+
/examples/lambda_api/vendor/*
54+
/examples/lambda_cron/vendor/*
55+
/examples/lambda_s3/vendor/*
56+
/examples/lambda_sns/vendor/*
57+
/examples/lambda_sqs/vendor/*
Lines changed: 50 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,61 @@
11
#!/bin/bash
2-
current_path=$(basename $(pwd))
3-
current_filename=$(basename -- "$0")
4-
current_filename_path=$0
5-
# echo $current_filename_path
6-
current_filename_path="${current_filename_path/$current_filename/''}"
7-
# echo $current_filename_path
8-
current_filename_path="${current_filename_path/scripts\//''}"
9-
# echo $current_filename_path
10-
current_filename_path_basename=$(basename -- "$current_filename_path")
11-
12-
echo "current_path: $current_path"
13-
echo "current_filename: $current_filename"
14-
echo "current_filename_path: $current_filename_path"
15-
echo "current_filename_path_basename: $current_filename_path_basename"
16-
17-
if test -f ${current_filename_path}/scripts/localstack/sqs/create-queue.sh; then
18-
19-
if test -f ${current_filename_path}.projectrc; then
20-
source ${current_filename_path}.projectrc
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/localstack/sqs/create-queue.sh; then
47+
48+
# echo "${current_parent_folder}.projectrc"
49+
if test -f ${current_parent_folder}.projectrc; then
50+
source ${current_parent_folder}.projectrc
2151
fi
2252

2353
if [ -z "$APP_QUEUE" ]; then
2454
echo 'APP_QUEUE not defined'
2555
exit 1
2656
else
2757
echo "Creating the queue: $APP_QUEUE"
28-
${current_filename_path}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
58+
${current_parent_folder}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
2959
fi
3060
fi
3161

examples/lambda_sqs/.projectrc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
PROJECT_NAME=template-serverless-lambda-python-lambda-sqs
22
NETWORK_NAME=service-python
3+
APP_QUEUE=test-queue
4+
APP_LAMBDA_NAME=lambda_sqs
5+
APP_LAMBDA_EVENT_SOURCE=true

examples/lambda_sqs/lambda_app/services/v1/carrier_notifier_service.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from lambda_app.helper import generate_hash
88
from lambda_app.logging import get_logger
99
from lambda_app.repositories.mysql.ocoren_repository import OcorenRepository
10+
from lambda_app.repositories.redis.product_repository import ProductRepository
1011
from lambda_app.vos.ocoren import OcorenVO
1112

1213

@@ -16,6 +17,7 @@ def __init__(self, logger=None, repository=None):
1617
self.logger = logger if logger is not None else get_logger()
1718

1819
self.repository = repository if repository is not None else OcorenRepository()
20+
self.redis_repository = ProductRepository()
1921
self.repository.debug = True
2022

2123
def process(self, sqs_event):
@@ -51,6 +53,10 @@ def process(self, sqs_event):
5153
event_vo = OcorenVO(event)
5254
self.logger.info('event_vo: {}'.format(event_vo.to_dict()))
5355
created = self.repository.create(event_vo)
56+
57+
self.redis_repository.create("event_{}".format(event_hash), str(event_vo.to_dict()))
58+
# self.redis_repository.list(where="*")
59+
5460
if not created:
5561
result = False
5662

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/migrations/mysql/migrate.py; then
47+
echo '----------------------------------------'
48+
echo 'Booting database...'
49+
echo '----------------------------------------'
50+
# TODO futuramente usar o Flask migrate ou outra alternativa
51+
echo 'Creating tables...'
52+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.ocorens.sql
53+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/structure/mysql/create.table.store.products.sql
54+
55+
read -p "Press enter to continue..."
56+
57+
echo 'Inserting data in the table...'
58+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.ocorens.sql
59+
python3 ${current_parent_folder}/scripts/migrations/mysql/migrate.py ${current_parent_folder}/tests/datasets/database/seeders/mysql/seeder.table.store.products.sql
60+
fi
61+
62+
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
echo '----------------------------------------'
47+
echo "$0 - Booting lambda"
48+
echo '----------------------------------------'
49+
echo 'Installing dependencies...'
50+
echo "Requirements file: ${current_parent_folder}requirements.txt"
51+
if test -f ${current_parent_folder}requirements.txt; then
52+
python3 -m pip install -r ${current_parent_folder}requirements.txt -t ${current_parent_folder}vendor
53+
# cat ${current_parent_folder}requirements.txt
54+
echo "requirements..."
55+
fi
56+
57+
echo "Requirements file: ${current_parent_folder}requirements-vendor.txt"
58+
if test -f ${current_parent_folder}requirement.s-vendor.txt; then
59+
python3 -m pip install -r ${current_parent_folder}requirements-vendor.txt -t ${current_parent_folder}vendor
60+
# cat ${current_parent_folder}requirements-vendor.txt
61+
echo "requirements vendor..."
62+
fi
63+
64+
read -p "Press enter to continue..."
65+
66+
#echo 'Creating resource dependencies...'
67+
#echo "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"
68+
69+
if test -f "${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"; then
70+
71+
if test -f ${current_parent_folder}.projectrc; then
72+
source ${current_parent_folder}.projectrc
73+
fi
74+
75+
if [ -z "$APP_LAMBDA_NAME" ]; then
76+
echo 'APP_LAMBDA_NAME not defined'
77+
exit 1
78+
else
79+
echo '----------------------------------------'
80+
echo "$0 - Creating the lambda: $APP_LAMBDA_NAME"
81+
echo '----------------------------------------'
82+
${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh $current_filename_path $APP_LAMBDA_NAME
83+
84+
read -p "Press enter to continue..."
85+
86+
if test $APP_LAMBDA_EVENT_SOURCE = true;then
87+
echo '----------------------------------------'
88+
echo "$0 - Creating the event source: $APP_LAMBDA_NAME"
89+
echo '----------------------------------------'
90+
${current_parent_folder}scripts/localstack/lambda/create-event-source-mapping.sh $APP_LAMBDA_NAME $APP_QUEUE
91+
else
92+
echo 'There is no event source for this lambda'
93+
fi
94+
fi
95+
else
96+
echo "File not found: ${current_parent_folder}scripts/localstack/lambda/create-function-from-s3.sh"
97+
fi
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# -----------------------------------------------------------------------------
3+
# Current file variables
4+
# -----------------------------------------------------------------------------
5+
debug=false
6+
parent_folder="../"
7+
current_path=$(pwd)/
8+
current_path_basename=$(basename $(pwd))
9+
current_file_full_path=$0
10+
# echo $current_filepath
11+
current_file_name=$(basename -- "$0")
12+
# echo $current_filename
13+
if [ $current_file_full_path = $current_file_name ] || [ $current_file_full_path = "./$current_file_name" ]; then
14+
current_file_full_path="./${current_file_full_path}"
15+
current_file_path="./"
16+
else
17+
current_file_path="${current_file_full_path/$current_file_name/''}"
18+
fi
19+
20+
current_file_path_basename=$(basename -- "$current_file_path")
21+
#echo "xxxxx current_file_path_basename $current_file_path_basename"
22+
23+
if [ -z "$current_file_path_basename" ] || [ $current_file_path = "./" ]; then
24+
# echo 'aq'
25+
current_parent_folder="../"
26+
else
27+
# echo 'naq'
28+
current_file_path_basename=$current_file_path_basename/
29+
current_parent_folder="${current_file_path/$current_file_path_basename/''}"
30+
fi
31+
32+
33+
if [ debug ]; then
34+
echo '----------------------------------------'
35+
echo "$0 - Script variables"
36+
echo '----------------------------------------'
37+
echo "current_path: $current_path"
38+
echo "current_path_basename: $current_path_basename"
39+
echo "current_file_full_path: $current_file_full_path"
40+
echo "current_file_name: $current_file_name"
41+
echo "current_file_path: $current_file_path"
42+
echo "current_parent_folder: $current_parent_folder"
43+
echo '----------------------------------------'
44+
fi
45+
46+
if test -f ${current_parent_folder}/scripts/localstack/sqs/create-queue.sh; then
47+
48+
# echo "${current_parent_folder}.projectrc"
49+
if test -f ${current_parent_folder}.projectrc; then
50+
source ${current_parent_folder}.projectrc
51+
fi
52+
53+
if [ -z "$APP_QUEUE" ]; then
54+
echo 'APP_QUEUE not defined'
55+
exit 1
56+
else
57+
echo "Creating the queue: $APP_QUEUE"
58+
${current_parent_folder}/scripts/localstack/sqs/create-queue.sh $APP_QUEUE
59+
fi
60+
fi
61+

examples/lambda_sqs/scriptsx/boot-validate-connection.sh renamed to examples/lambda_sqs/scripts/boot-validate-connection.sh

File renamed without changes.

0 commit comments

Comments
 (0)