Skip to content

Commit

Permalink
Add deployment configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Belo authored and Lucas Belo committed Oct 7, 2024
1 parent 0557248 commit 48a659d
Show file tree
Hide file tree
Showing 8 changed files with 124 additions and 3 deletions.
42 changes: 41 additions & 1 deletion .github/workflows/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,13 @@ on:
- 'services/tasks_api/**'
- '.github/workflows/api.yml'


env: # new
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_DEFAULT_REGION: eu-west-1
APP_ENVIRONMENT: development

jobs:
test:
strategy:
Expand Down Expand Up @@ -63,4 +70,37 @@ jobs:
- name: Run flake8
run: poetry run flake8 .
- name: Run bandit
run: poetry run bandit .
run: poetry run bandit .
deploy-development: # new
needs: [ test, code-quality ]
strategy:
fail-fast: false
matrix:
python-version: [3.11]
poetry-version: [1.3.2]
node-version: [16]
os: [ubuntu-latest]
runs-on: ${{ matrix.os }}
defaults:
run:
working-directory: services/tasks_api
steps:
- name: Checkout Code
uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install poetry
uses: abatilo/[email protected]
with:
poetry-version: ${{ matrix.poetry-version }}
- uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install Serverless Framework
run: npm install -g serverless
- name: Install NPM dependencies
run: npm install
- name: Deploy
run: sls deploy --stage development --verbose
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
# was_tasks
# was_tasks

## Infrastructure

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.

## Services

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.
1 change: 1 addition & 0 deletions services/tasks_api/.env.development
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ALLOWED_ORIGINS=*
4 changes: 4 additions & 0 deletions services/tasks_api/main.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from mangum import Mangum

app = FastAPI()
app.add_middleware(
Expand All @@ -14,3 +15,6 @@
@app.get("/api/health-check/")
def health_check():
return {"message": "OK"}


handle = Mangum(app)
15 changes: 15 additions & 0 deletions services/tasks_api/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"name": "tasks-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"dependencies": {},
"devDependencies": {
"serverless-python-requirements": "^5.1.1"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC"
}
16 changes: 15 additions & 1 deletion services/tasks_api/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions services/tasks_api/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ python = "^3.11"
fastapi = "^0.115.0"
uvicorn = "^0.31.0"
httpx = "^0.27.2"
mangum = "^0.19.0"


[tool.poetry.group.dev.dependencies]
Expand Down
38 changes: 38 additions & 0 deletions services/tasks_api/serverless.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
service: tasks-api

frameworkVersion: '3'
useDotenv: true


provider:
name: aws
runtime: python3.11
region: ${opt:region, 'eu-west-1'}
stage: ${opt:stage, 'development'}
logRetentionInDays: 30
environment:
APP_ENVIRONMENT: ${self:provider.stage}

functions:
API:
handler: main.handle
timeout: 10
memorySize: 512
events:
- http:
path: /{proxy+}
method: any
cors:
origin: ${env:ALLOWED_ORIGINS}
maxAge: 60


custom:
pythonRequirements:
usePoetry: true
noDeploy:
- boto3 # already on Lambda
- botocore # already on Lambda

plugins:
- serverless-python-requirements

0 comments on commit 48a659d

Please sign in to comment.