add docker compose

This commit is contained in:
2025-03-26 23:21:26 -03:00
parent b1e8f19d39
commit 7021833476
11 changed files with 71 additions and 15 deletions

4
http-api/.gitignore vendored
View File

@@ -1,2 +1,4 @@
.env
samlocal.json
env.json
dynamodb_volume/
elastic_volume/

View File

@@ -16,3 +16,9 @@ pytest:
htmlcov: pytest
uv run python -m http.server 80 -d htmlcov
up:
docker compose up -d
down:
docker compose down

34
http-api/compose.yaml Normal file
View File

@@ -0,0 +1,34 @@
services:
dynamodb:
image: amazon/dynamodb-local:latest
container_name: dynamodb
ports:
- 8000:8000
volumes:
- ./dynamodb_volume:/home/dynamodblocal/data
working_dir: /home/dynamodblocal
command: "-jar DynamoDBLocal.jar -sharedDb -dbPath ./data"
elastic:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.3
container_name: elastic
environment:
- discovery.type=single-node
- bootstrap.memory_lock=true
- xpack.security.enabled=false
- xpack.security.http.ssl.enabled=false
- xpack.security.transport.ssl.enabled=false
- "ES_JAVA_OPTS=-Xms512m -Xmx512m"
- http.cors.allow-origin="*"
- http.cors.enabled=true
- http.cors.allow-credentials=true
- http.cors.allow-methods=OPTIONS, HEAD, GET, POST, PUT, DELETE
- http.cors.allow-headers=X-Requested-With, X-Auth-Token, Content-Type, Content-Length, Authorization, Access-Control-Allow-Headers, Accept, x-elastic-client-meta
ulimits:
memlock:
soft: -1
hard: -1
volumes:
- ./elastic_volume:/usr/share/elasticsearch/data
ports:
- 9200:9200

View File

@@ -4,5 +4,6 @@
"USER_TABLE": "test-users",
"ORDER_TABLE": "test-orders",
"ENROLLMENT_TABLE": "test-enrollments"
"COURSE_TABLE": "test-courses"
}
}

View File

@@ -1,7 +1,6 @@
import json
from http import HTTPStatus
import boto3
from aws_lambda_powertools.event_handler import Response, content_types
from aws_lambda_powertools.event_handler.api_gateway import Router
from elasticsearch import Elasticsearch
@@ -9,19 +8,23 @@ from layercake.dynamodb import DynamoDBPersistenceLayer
from pydantic import BaseModel
import elastic
from boto3clients import dynamodb_client
from course import create_course
from models import Course, Org
from settings import COURSE_TABLE, ELASTIC_CONN
router = Router()
dynamodb_client = boto3.client('dynamodb')
elastic_client = Elasticsearch(**ELASTIC_CONN)
course_layer = DynamoDBPersistenceLayer(COURSE_TABLE, dynamodb_client)
@router.get('/', compress=True, tags=['Course'])
@router.get(
'/',
compress=True,
tags=['Course'],
summary='Get courses',
)
def get_courses():
"""Get a list of courses based on the query parameters."""
event = router.current_event
query = event.get_query_string_value('query', '{}')
page_size = event.get_query_string_value('page_size', '25')

View File

@@ -10,5 +10,5 @@ image_repositories = []
[default.local_start_api.parameters]
debug = true
env_vars = "samlocal.json"
env_vars = "env.json"
warm_containers = "EAGER"

2
http-api/uv.lock generated
View File

@@ -444,7 +444,7 @@ wheels = [
[[package]]
name = "layercake"
version = "0.1.3"
version = "0.1.4"
source = { directory = "../layercake" }
dependencies = [
{ name = "aws-lambda-powertools", extra = ["all"] },