Skip to content

Commit 48a659d

Browse files
Lucas BeloLucas Belo
Lucas Belo
authored and
Lucas Belo
committed
Add deployment configuration
1 parent 0557248 commit 48a659d

File tree

8 files changed

+124
-3
lines changed

8 files changed

+124
-3
lines changed

.github/workflows/api.yml

+41-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@ on:
55
- 'services/tasks_api/**'
66
- '.github/workflows/api.yml'
77

8+
9+
env: # new
10+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
11+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
12+
AWS_DEFAULT_REGION: eu-west-1
13+
APP_ENVIRONMENT: development
14+
815
jobs:
916
test:
1017
strategy:
@@ -63,4 +70,37 @@ jobs:
6370
- name: Run flake8
6471
run: poetry run flake8 .
6572
- name: Run bandit
66-
run: poetry run bandit .
73+
run: poetry run bandit .
74+
deploy-development: # new
75+
needs: [ test, code-quality ]
76+
strategy:
77+
fail-fast: false
78+
matrix:
79+
python-version: [3.11]
80+
poetry-version: [1.3.2]
81+
node-version: [16]
82+
os: [ubuntu-latest]
83+
runs-on: ${{ matrix.os }}
84+
defaults:
85+
run:
86+
working-directory: services/tasks_api
87+
steps:
88+
- name: Checkout Code
89+
uses: actions/checkout@v3
90+
- name: Set up Python 3.9
91+
uses: actions/setup-python@v3
92+
with:
93+
python-version: ${{ matrix.python-version }}
94+
- name: Install poetry
95+
uses: abatilo/[email protected]
96+
with:
97+
poetry-version: ${{ matrix.poetry-version }}
98+
- uses: actions/setup-node@v3
99+
with:
100+
node-version: ${{ matrix.node-version }}
101+
- name: Install Serverless Framework
102+
run: npm install -g serverless
103+
- name: Install NPM dependencies
104+
run: npm install
105+
- name: Deploy
106+
run: sls deploy --stage development --verbose

README.md

+9-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
# was_tasks
1+
# was_tasks
2+
3+
## Infrastructure
4+
5+
The easiest way to manage servers, subnets, load balancers, managed databases, etc. is by using infrastructure-as-code (IaC). Inside the "infrastructure" folder we'll store configuration files for our tool(s) of choice. These are usually long YAML, JSON, or HCL files.
6+
7+
## Services
8+
9+
Anything that is long-running or talks to our end users is considered a service. It can be monolithic Django application, Vue UI, or a couple of microservice APIs -- all will reside in this folder.

services/tasks_api/.env.development

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ALLOWED_ORIGINS=*

services/tasks_api/main.py

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from fastapi import FastAPI
22
from fastapi.middleware.cors import CORSMiddleware
3+
from mangum import Mangum
34

45
app = FastAPI()
56
app.add_middleware(
@@ -14,3 +15,6 @@
1415
@app.get("/api/health-check/")
1516
def health_check():
1617
return {"message": "OK"}
18+
19+
20+
handle = Mangum(app)

services/tasks_api/package.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "tasks-api",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"dependencies": {},
7+
"devDependencies": {
8+
"serverless-python-requirements": "^5.1.1"
9+
},
10+
"scripts": {
11+
"test": "echo \"Error: no test specified\" && exit 1"
12+
},
13+
"author": "",
14+
"license": "ISC"
15+
}

services/tasks_api/poetry.lock

+15-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

services/tasks_api/pyproject.toml

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ python = "^3.11"
1010
fastapi = "^0.115.0"
1111
uvicorn = "^0.31.0"
1212
httpx = "^0.27.2"
13+
mangum = "^0.19.0"
1314

1415

1516
[tool.poetry.group.dev.dependencies]

services/tasks_api/serverless.yml

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
service: tasks-api
2+
3+
frameworkVersion: '3'
4+
useDotenv: true
5+
6+
7+
provider:
8+
name: aws
9+
runtime: python3.11
10+
region: ${opt:region, 'eu-west-1'}
11+
stage: ${opt:stage, 'development'}
12+
logRetentionInDays: 30
13+
environment:
14+
APP_ENVIRONMENT: ${self:provider.stage}
15+
16+
functions:
17+
API:
18+
handler: main.handle
19+
timeout: 10
20+
memorySize: 512
21+
events:
22+
- http:
23+
path: /{proxy+}
24+
method: any
25+
cors:
26+
origin: ${env:ALLOWED_ORIGINS}
27+
maxAge: 60
28+
29+
30+
custom:
31+
pythonRequirements:
32+
usePoetry: true
33+
noDeploy:
34+
- boto3 # already on Lambda
35+
- botocore # already on Lambda
36+
37+
plugins:
38+
- serverless-python-requirements

0 commit comments

Comments
 (0)