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

Commit 67d62c7

Browse files
Inclusão de build.yml para sonar;
Atualização de README.md e docs; Atualização de gitignore para permitir relatórios de cobertura; Inclusão de versão do projeto no projectrc
1 parent bedd159 commit 67d62c7

34 files changed

+665
-224
lines changed

.github/workflows/build.yml

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- production
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
sonarcloud:
10+
name: SonarCloud
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- name: SonarCloud Scan
17+
uses: SonarSource/sonarcloud-github-action@master
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
20+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

.gitignore

+22-8
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,22 @@ venv
1717
/docker/elk/logs/elasticsearch.log
1818
/.infrastructure/.terraform/
1919
/.chalice/deployments/
20-
/target/
21-
/target/dynamodb-local/
2220
*_us-east-2.db
2321
*_sa-east-1.db
2422
/docker/aws/credentials
2523
/deployment.zip
2624
/sam.json
2725
/.coverage
2826

27+
# mantem a vendor
28+
!vendor
29+
# ignora os demais arquivos
30+
vendor/*
31+
# mantem essa pasta
32+
!/vendor/public
33+
# mantem essa pasta
34+
!/vendor/datasources
35+
2936
# Coverage results and execution report
3037
!/target/integration/report.xml
3138
!/target/component/report.xml
@@ -50,9 +57,16 @@ imagedefinitions.json
5057
config/integration.en
5158
/node_modules/
5259

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/*
58-
/vendor/
60+
/lambda-full.zip
61+
62+
#output lambda
63+
output/response.json
64+
/output/
65+
/include/
66+
/life-cycle-service-manager-recovery.zip
67+
/env/integration.env
68+
/env/production.env
69+
/env/staging.env
70+
/env/_staging.env
71+
/env/_integration.env
72+
/env/_production.env

README.md

+137-17
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,64 @@
11
# template-serverless-lambda-python
22
This project contains isolated examples of AWS Lambda Services as well this provide
33
a stack example.
4+
[![linting: pylint](https://img.shields.io/badge/linting-pylint-yellowgreen)](https://github.com/PyCQA/pylint)
5+
[![PEP8](https://img.shields.io/badge/code%20style-pep8-orange.svg)](https://www.python.org/dev/peps/pep-0008/)
6+
[![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=madeiramadeirabr_template-serverless-lambda-python&metric=alert_status)](https://sonarcloud.io/summary/new_code?id=madeiramadeirabr_template-serverless-lambda-python)
7+
[![Coverage](https://sonarcloud.io/api/project_badges/measure?project=madeiramadeirabr_template-serverless-lambda-python&metric=coverage)](https://sonarcloud.io/summary/new_code?id=madeiramadeirabr_template-serverless-lambda-python)
8+
[![Reliability Rating](https://sonarcloud.io/api/project_badges/measure?project=madeiramadeirabr_template-serverless-lambda-python&metric=reliability_rating)](https://sonarcloud.io/summary/new_code?id=madeiramadeirabr_template-serverless-lambda-python)
49

510
## Service Architecture
6-
Example of architecture of this project stack.
11+
Diagrams with application usage of this architecture.
12+
13+
More details [here](https://drive.google.com/file/d/112om-id0zfd8qGd0Q4kTaoIwIgwx6DGJ/view?usp=sharing).
14+
15+
### Cloud Architecture
16+
Example of the architecture running on AWS Cloud.
17+
718
![Service-Arch](docs/service-arch.png)
819

9-
## Service Stack
10-
Example of components of the architecture of this project.
11-
![Service-Stack](docs/service-stack.png)
20+
### Docker Architecture
21+
Example of the architecture running with docker.
22+
![Docker-Service-Arch](docs/service-stack.png)
23+
24+
## General Service Routes Architecture
25+
Example of OpenApi documentation.
26+
![Swagger](docs/swagger.png)
27+
28+
Route list:
29+
```
30+
GET / - Root
31+
GET /docs - Swagger docs
32+
GET /alive - Health Check
33+
GET /v1/event/<event_type> - Event List
34+
POST /v1/event/<event_type> - Create Event
35+
```
36+
37+
# Prerequisites
38+
- Python >=3.6
39+
- docker
40+
- docker-compose
41+
- python-dotenv
42+
- jsonformatter
43+
- requests
44+
- pytz
45+
- redis
46+
- pyyaml
47+
- apispec
48+
- marshmallow
49+
- Flask
50+
51+
## Features
52+
- Docker-compose
53+
- Localstack
54+
- SQS Integration
55+
- Flask
56+
- MySQL
57+
- Redis
1258

1359
## Build environment script workflow
1460
Example of the workflow to create the environment.
15-
![Service-Stack](docs/runenv-workflow.drawio.png)
61+
![Runenv-Workflow](docs/runenv-workflow.drawio.png)
1662

1763
## Single project examples
1864

@@ -31,20 +77,42 @@ You can find complex examples:
3177
* [Lambda SNS](./examples/lambda_sns)
3278
* [Lambda S3](./examples/lambda_s3)
3379

80+
## Details about requirements files
81+
### requirements.txt
82+
Collection of common application modules, light modules.
83+
84+
### requirements-vendor.txt
85+
Collection of specific application modules, heavy modules that can be converted to layers if necessary.
3486

35-
## Stack
36-
* AWS Lambda
37-
* Flask for APIs
38-
* Custom code based in AWS Chalice for SQS, SNS, S3 and CRON
87+
### requirements-tests.txt
88+
Collection of specific test application modules.
3989

40-
## Prerequisites
41-
* Docker
42-
* Docker-compose
43-
* Python 3.x
4490

4591
## Installation
46-
### Creating the virtual env
47-
To create the venv and install the modules execute:
92+
### Installing AWS CLI
93+
Documentation:
94+
https://docs.aws.amazon.com/pt_br/cli/latest/userguide/install-cliv2.html
95+
96+
Execute the follow command:
97+
```bash
98+
apt install python38-env
99+
apt install awscli
100+
apt install zip
101+
app install pip
102+
```
103+
Execute the follow command:
104+
```bash
105+
aws configure
106+
```
107+
108+
### Installing python venv support
109+
Execute the follow command:
110+
```bash
111+
apt install python38-env
112+
```
113+
114+
### Running Locally
115+
To create the `venv` and install the modules execute:
48116
```bash
49117
./scripts/venv.sh
50118
```
@@ -54,12 +122,64 @@ To execute the build:
54122
```bash
55123
./scripts/runenv.sh --build
56124
```
125+
57126
Execute the follow command:
58127
```bash
59128
./scripts/runenv.sh
60129
```
61-
### Boot the resources
130+
131+
### Recovering the environment in error cases
62132
Execute the follow command:
63133
```bash
64-
./scripts/boot.sh
134+
./scripts/fixenv.sh
65135
```
136+
137+
## Automation scripts information
138+
Bellow we describe the usage of the automation scripts.
139+
These kebab case scripts helps the developer in general tasks.
140+
141+
### General scripts
142+
Kebab case script to help the developer in general tasks.
143+
144+
| Script | Description | Context |
145+
|-----------------------------|-----------------------------------------------------------------------------------|-------------------|
146+
| autopep8.sh | Execute the code-lint for pep8 | Codelint |
147+
| boot.sh | Boot the application during de container execution | Local boot |
148+
| boot-db.sh | Boot the data for the database | Local boot |
149+
| boot-queues.sh | Boot the queues of the application in the localstack | Local boot |
150+
| boot-validate-connection.sh | Check if localstack is ready to connect | Local boot |
151+
| clean-env.sh | Clean the ./vendor folder | Local install |
152+
| fixenv.sh | In some cases where the network are deleted, you can fix the container references | Local install |
153+
| install.sh | Script to install the dependencies | Local install |
154+
| install-local.sh | Script to install the dependencies in the ./vendor folder | Local install |
155+
| openapi.sh | Script to generate the openapi.yaml | CI/CD pipeline |
156+
| preenv.sh | Script to execute the pre build commands | Local boot |
157+
| pylint.sh | Script to execute the pylint analysis | Local development |
158+
| runenv.sh | Script to start the project locally | Local development |
159+
| testenv.sh | Script to run the environment with focus in the component tests | Local development |
160+
| venv.sh | Script to install the dependencies in the venv folder | Local install |
161+
| venv-exec.sh | Script to execute scripts to install content inside the venv | Local install |
162+
| zip.sh | Generate a zip file with the application content | Other |
163+
164+
### Docker scripts
165+
Helper scripts to do tasks for docker context;
166+
### Flask scripts
167+
Helper scripts to run flask locally, not inside a docker container;
168+
### Localstack scripts
169+
Helper scripts to run commands over Localstack resources like S3, SQS, Lambda, etc;
170+
### Migrations scripts
171+
Helper scripts to execute migrations;
172+
### OpenApi scripts
173+
Helper scripts to generate openapi schemas and specifications;
174+
### Tests scripts
175+
Helper scripts to execute tests and generate reports;
176+
177+
## Samples
178+
See the project samples in this folder [here](samples).
179+
180+
181+
## License
182+
See the license: [LICENSE.md](LICENSE.md).
183+
184+
## Contributions
185+
* Anderson de Oliveira Contreira [andersoncontreira](https://github.com/andersoncontreira)

docker-compose.yml

+3-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
version: "3.2"
22
services:
3-
template-serverless-lambda-python-lambda-api-resful:
4-
# container_name: template-serverless-lambda-python-lambda-api
3+
template-serverless-lambda-python-lambda-api:
54
build:
6-
context: ./examples/lambda_api_restful/
5+
context: ./examples/lambda_api/
76
dockerfile: ./docker/python/Dockerfile
87
privileged: true
98
entrypoint: ["sh", "./docker/python/entrypoint.sh"]
@@ -21,7 +20,7 @@ services:
2120
networks:
2221
- service-python
2322
volumes:
24-
- ./examples/lambda_api_restful/:/app
23+
- ./examples/lambda_api/:/app
2524
template-serverless-lambda-python-lambda-sqs:
2625
# container_name: template-serverless-lambda-python-lambda-sqs
2726
build:

docs/swagger.png

373 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
name: Build
2+
on:
3+
push:
4+
branches:
5+
- production
6+
pull_request:
7+
types: [opened, synchronize, reopened]
8+
jobs:
9+
sonarcloud:
10+
name: SonarCloud
11+
runs-on: ubuntu-latest
12+
steps:
13+
- uses: actions/checkout@v2
14+
with:
15+
fetch-depth: 0 # Shallow clones should be disabled for a better relevancy of analysis
16+
- name: SonarCloud Scan
17+
uses: SonarSource/sonarcloud-github-action@master
18+
env:
19+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
20+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}

examples/lambda_api/.gitignore

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ venv
1717
/docker/elk/logs/elasticsearch.log
1818
/.infrastructure/.terraform/
1919
/.chalice/deployments/
20-
/target/
21-
/target/dynamodb-local/
2220
*_us-east-2.db
2321
*_sa-east-1.db
2422
/docker/aws/credentials
@@ -71,5 +69,4 @@ output/response.json
7169
/env/staging.env
7270
/env/_staging.env
7371
/env/_integration.env
74-
/env/_production.env
75-
72+
/env/_production.env

examples/lambda_api/.projectrc

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
APP_NAME=template-serverless-lambda-python-lambda-api
2+
APP_VERSION=1.0.0
23
NETWORK_NAME=service-python
34
APP_QUEUE=test-queue
45
APP_LAMBDA_NAME=lambda_api
56
APP_LAMBDA_EVENT_SOURCE=false
6-
APP_PORT=5001
7+
APP_PORT=5000

0 commit comments

Comments
 (0)