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

Commit 410b997

Browse files
Merge pull request #3 from madeiramadeirabr/add_entrypoints
Melhorias gerais para a execução dos projetos localmente (docker via entrypoints)
2 parents cf32279 + aee8a91 commit 410b997

39 files changed

+376
-120
lines changed

docker-compose.yml

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
version: "3.2"
22
services:
33
template-serverless-lambda-python-lambda-api:
4+
# container_name: template-serverless-lambda-python-lambda-api
45
build:
56
context: ./examples/lambda_api/
67
dockerfile: ./docker/python/Dockerfile
@@ -9,13 +10,18 @@ services:
910
# Fake credentials for Localstack
1011
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
1112
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
13+
depends_on:
14+
- "localstack"
15+
- "redis"
16+
- "mysql"
1217
ports:
1318
- 5000:5000
1419
networks:
1520
- service-python
1621
volumes:
17-
- ./:/app
22+
- ./examples/lambda_api/:/app
1823
template-serverless-lambda-python-lambda-sqs:
24+
# container_name: template-serverless-lambda-python-lambda-sqs
1925
build:
2026
context: ./examples/lambda_sqs/
2127
dockerfile: ./docker/python/Dockerfile
@@ -24,12 +30,16 @@ services:
2430
# Fake credentials for Localstack
2531
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
2632
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
27-
ports:
28-
- 5001:5000
33+
depends_on:
34+
- "localstack"
35+
- "redis"
36+
- "mysql"
37+
# ports:
38+
# - 5001:5000
2939
networks:
3040
- service-python
3141
volumes:
32-
- ./:/app
42+
- ./examples/lambda_sqs/:/app
3343
redis:
3444
image: "redis:alpine"
3545
ports:
@@ -59,8 +69,8 @@ services:
5969
SERVICES: sqs,lambda,cloudwatch,s3
6070
DOCKER_HOST: unix:///var/run/docker.sock
6171
PORT_WEB_UI: 9070
62-
LAMBDA_EXECUTOR: docker # está dando erro via docker
63-
# LAMBDA_EXECUTOR: local
72+
# LAMBDA_EXECUTOR: docker # está dando erro via docker
73+
LAMBDA_EXECUTOR: local
6474
DEBUG: 1
6575
HOSTNAME_EXTERNAL: localstack
6676
networks:

examples/lambda_api/docker-compose.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
version: "3.2"
22
services:
33
template-serverless-lambda-python-lambda-api:
4-
container_name: template-serverless-lambda-python-lambda-api
4+
# container_name: lambda-api
55
build:
66
context: .
77
dockerfile: ./docker/python/Dockerfile
@@ -10,6 +10,10 @@ services:
1010
# Fake credentials for Localstack
1111
AWS_ACCESS_KEY_ID: AKIAIOSFODNN7EXAMPLE
1212
AWS_SECRET_ACCESS_KEY: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
13+
depends_on:
14+
- "localstack"
15+
- "redis"
16+
- "mysql"
1317
ports:
1418
- 5000:5000
1519
networks:

examples/lambda_api/docker/python/Dockerfile

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ ENV FLASK_ENV=$ENVIRONMENT_NAME \
99

1010
EXPOSE ${FLASK_PORT}
1111

12-
WORKDIR /${PROJECT_NAME}
12+
WORKDIR /app
1313

1414
# SQLite support
1515
RUN apk update \
@@ -27,11 +27,17 @@ RUN apk add --no-cache build-base \
2727
libcurl \
2828
gpgme-dev \
2929
libc-dev \
30+
bash \
31+
curl \
32+
zip \
3033
&& rm -rf /var/cache/apk/*
3134

3235
# upgrade pip
3336
RUN pip install --upgrade pip
3437

38+
# install aws cli
39+
RUN pip --no-cache-dir install --upgrade awscli
40+
3541
RUN rm -Rf ./vendor/*
3642

3743
# Install requirements
@@ -46,5 +52,10 @@ RUN rm -Rf ./vendor/dataclasses-0.8.dist-info/ ./vendor/dataclasses.py
4652
# Copy project files
4753
COPY . .
4854

55+
# entrypoint permission
56+
RUN ["chmod", "+x", "./docker/python/entrypoint.sh"]
57+
# entrypoint
58+
ENTRYPOINT ["sh", "./docker/python/entrypoint.sh"]
59+
4960
CMD [ "flask", "run", "--host", "0.0.0.0" ]
5061

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
#!/bin/bash
2+
# aws configure for localstack
3+
aws configure set region us-east-1 --profile default
4+
5+
# define the environment variable indicating thar are running inside a container
6+
#!/bin/bash
7+
if [ -f /.dockerenv ]; then
8+
echo "I'm inside matrix ;(";
9+
export RUNNING_IN_CONTAINER=1
10+
else
11+
echo "I'm living in real world!";
12+
export RUNNING_IN_CONTAINER=0
13+
fi
14+
15+
#echo $RUNNING_IN_CONTAINER
16+
17+
# execute the boot.sh
18+
bash ./scripts/boot.sh
19+
# bash ./scripts/boot-queues.sh
20+
21+
# execute the flask
22+
flask run --host 0.0.0.0

examples/lambda_api/scripts/boot.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,19 @@ echo 'Validating jq installation...'
3636
/usr/bin/jq --version > /dev/null 2>&1
3737
if [ $? -ne 0 ]; then
3838
echo 'Installing jq...'
39-
# download directly into ~/bin_compciv
40-
sudo curl http://stedolan.github.io/jq/download/linux64/jq -o /usr/bin/jq
41-
# give it executable permissions
42-
sudo chmod a+x /usr/bin/jq
39+
sudo --help > /dev/null 2>&1
40+
if [ $? -ne 0 ]; then
41+
# download directly into ~/bin_compciv
42+
curl http://stedolan.github.io/jq/download/linux64/jq -o /usr/bin/jq
43+
# give it executable permissions
44+
chmod a+x /usr/bin/jq
45+
else
46+
# download directly into ~/bin_compciv
47+
sudo curl http://stedolan.github.io/jq/download/linux64/jq -o /usr/bin/jq
48+
# give it executable permissions
49+
sudo chmod a+x /usr/bin/jq
50+
fi
51+
4352
else
4453
echo 'jq installed...'
4554
fi
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
if test -f .projectrc; then
2+
source .projectrc
3+
elif test -f ./scripts/.projectrc; then
4+
source ./scripts/.projectrc
5+
fi
6+
7+
if [ -z "$PROJECT_NAME" ]; then
8+
echo 'PROJECT_NAME not defined'
9+
exit 1
10+
else
11+
docker-compose exec $PROJECT_NAME /bin/sh
12+
fi

examples/lambda_api/scripts/localstack/lambda/create-event-source-mapping.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,11 @@ else
66
echo 'Queue name must be informed'
77
exit 1
88
else
9-
HOST=0.0.0.0
9+
if [ $RUNNING_IN_CONTAINER ]; then
10+
HOST=localstack
11+
else
12+
HOST=0.0.0.0
13+
fi
1014
REGION=us-east-1
1115
echo "aws --endpoint-url=http://$HOST:4566 lambda create-event-source-mapping \
1216
--function-name arn:aws:lambda:$REGION:000000000000:function:$1 \

examples/lambda_api/scripts/localstack/lambda/create-function-from-s3.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,11 @@ if [ -z "$1" ]; then
4646
exit 1
4747
else
4848

49-
HOST=0.0.0.0
49+
if [ $RUNNING_IN_CONTAINER ]; then
50+
HOST=localstack
51+
else
52+
HOST=0.0.0.0
53+
fi
5054
FUNCTION_PATH=$1
5155
FUNCTION_NAME=$1
5256
HANDLER=$2

examples/lambda_api/scripts/localstack/lambda/create-layer-from-vendor.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ if [ -z "$1" ]; then
33
echo 'Function path must be informed'
44
exit 1
55
else
6-
HOST=0.0.0.0
6+
if [ $RUNNING_IN_CONTAINER ]; then
7+
HOST=localstack
8+
else
9+
HOST=0.0.0.0
10+
fi
711
FUNCTION_PATH=$1
812
FUNCTION_NAME=$1
913
LAYER_NAME=$2

examples/lambda_api/scripts/localstack/lambda/create-layer.sh

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@ if [ -z "$1" ]; then
33
echo 'Function path must be informed'
44
exit 1
55
else
6-
HOST=0.0.0.0
6+
if [ $RUNNING_IN_CONTAINER ]; then
7+
HOST=localstack
8+
else
9+
HOST=0.0.0.0
10+
fi
711
FUNCTION_PATH=$1
812
FUNCTION_NAME=$1
913
LAYER_NAME=$2

0 commit comments

Comments
 (0)