Skip to content

Commit 0e74700

Browse files
committed
deployment
1 parent 8a02b6e commit 0e74700

File tree

8 files changed

+173
-1
lines changed

8 files changed

+173
-1
lines changed

.ebextensions/logging.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
option_settings:
2+
aws:elasticbeanstalk:cloudwatch:logs:
3+
StreamLogs: true
4+
DeleteOnTerminate: true
5+
RetentionInDays: 7

.gitignore

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,8 @@ __pycache__
88
/.coverage
99
/.pytest_cache
1010
/.ruff_cache
11+
12+
# Elastic Beanstalk Files
13+
.elasticbeanstalk/*
14+
!.elasticbeanstalk/*.cfg.yml
15+
!.elasticbeanstalk/*.global.yml

Dockerrun.aws.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"AWSEBDockerrunVersion": "1",
3+
"Image": {
4+
"Name": "992382462803.dkr.ecr.eu-central-1.amazonaws.com/stapi-fastapi-planet:latest",
5+
"Update": "true"
6+
},
7+
"Ports": [
8+
{
9+
"ContainerPort": 8000
10+
}
11+
]
12+
}

Makefile

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Load environment variables from .env file
2+
include .env
3+
export $(shell sed 's/=.*//' .env)
4+
5+
.PHONY: help dev prod logs stop rebuild clean deploy terminate
6+
7+
help:
8+
@echo "🧪 LOCAL DEVELOPMENT COMMANDS:"
9+
@echo " make dev – Start in development mode with hot reload"
10+
@echo " make prod – Start in production mode (detached)"
11+
@echo " make logs – Follow logs from running container"
12+
@echo " make stop – Stop all containers"
13+
@echo " make rebuild – Rebuild image and start fresh"
14+
@echo " make clean – Remove all containers and images"
15+
@echo ""
16+
@echo "🚀 DEPLOYMENT TO AWS ELASTIC BEANSTALK:"
17+
@echo " make init – One-time EB app setup (eb init)"
18+
@echo " make create – Create EB environment (after terminate)"
19+
@echo " make deploy – Build, push to ECR, and deploy to EB (enables CloudWatch logs)"
20+
@echo " make status – Show EB environment status and health"
21+
@echo " make terminate – Shut down the EB environment"
22+
@echo ""
23+
@echo "🪵 EB LOGGING:"
24+
@echo " make logs-eb – Fetch recent logs from EB"
25+
@echo " make logs-eb-full – Fetch all available EB logs"
26+
@echo " make pull-logs – Download full EB logs to file"
27+
@echo " make logs-eb-watch – Simulate live logs (refresh every 10s)"
28+
@echo " make logs-cloudwatch – True tail logs via CloudWatch (real-time)"
29+
30+
# -- local workflow --
31+
32+
dev:
33+
docker compose -f $(DEV_COMPOSE) up
34+
35+
prod:
36+
docker compose up -d
37+
38+
logs:
39+
docker compose logs -f
40+
41+
stop:
42+
docker compose -f $(DEV_COMPOSE) down
43+
docker compose down
44+
45+
rebuild:
46+
docker compose -f $(DEV_COMPOSE) down
47+
docker compose down
48+
docker compose -f $(DEV_COMPOSE) up --build
49+
50+
clean:
51+
docker compose -f $(DEV_COMPOSE) down --volumes --remove-orphans
52+
docker compose down --volumes --remove-orphans
53+
docker image rm $(APP_NAME) || true
54+
55+
56+
# -- AWS workflow --
57+
init:
58+
eb init -p docker $(APP_NAME) --region $(AWS_REGION)
59+
60+
deploy: build push dockerrun zip upload
61+
62+
build:
63+
docker build -t $(ECR_REPO):$(IMAGE_TAG) .
64+
65+
push:
66+
aws ecr get-login-password --region $(AWS_REGION) | docker login --username AWS --password-stdin $(ECR_URI)
67+
docker tag $(ECR_REPO):$(IMAGE_TAG) $(ECR_URI):$(IMAGE_TAG)
68+
docker push $(ECR_URI):$(IMAGE_TAG)
69+
70+
dockerrun:
71+
@echo "Creating Dockerrun.aws.json..."
72+
@printf '%s\n' '{' \
73+
' "AWSEBDockerrunVersion": "1",' \
74+
' "Image": {' \
75+
' "Name": "$(ECR_URI):$(IMAGE_TAG)",' \
76+
' "Update": "true"' \
77+
' },' \
78+
' "Ports": [' \
79+
' {' \
80+
' "ContainerPort": 8000' \
81+
' }' \
82+
' ]' \
83+
'}' > Dockerrun.aws.json
84+
85+
zip:
86+
@echo "Zipping Dockerrun.aws.json and .ebextensions..."
87+
zip -r deploy.zip Dockerrun.aws.json .ebextensions/
88+
89+
upload:
90+
eb deploy $(ENV_NAME)
91+
92+
terminate:
93+
eb terminate $(ENV_NAME)
94+
95+
create:
96+
eb create $(ENV_NAME) --single --instance_type t3.micro
97+
98+
status:
99+
eb status $(ENV_NAME)
100+
101+
102+
logs-eb:
103+
@echo "Fetching recent logs from EB environment..."
104+
eb logs $(ENV_NAME)
105+
106+
logs-eb-full:
107+
@echo "Fetching all available logs from EB environment..."
108+
eb logs $(ENV_NAME) --all
109+
110+
pull-logs:
111+
@echo "Downloading full EB logs to file..."
112+
eb logs $(ENV_NAME) --all --output file
113+
114+
logs-eb-watch:
115+
@echo "Simulating live EB logs (refreshing every 10s)..."
116+
@while true; do \
117+
clear; \
118+
echo "🔄 Fetching logs from $(ENV_NAME) at $$(date)"; \
119+
eb logs $(ENV_NAME); \
120+
sleep 10; \
121+
done
122+
123+
logs-cloudwatch:
124+
@echo "Streaming real-time logs from CloudWatch (Ctrl+C to stop)..."
125+
aws logs tail "/aws/elasticbeanstalk/$(ENV_NAME)/var/log/web.stdout.log" --follow --region $(AWS_REGION)

deploy.zip

803 Bytes
Binary file not shown.

docker-compose.dev.yml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
version: '3.9'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
ports:
8+
- "8000:8000"
9+
volumes:
10+
- .:/app
11+
command: >
12+
uvicorn planet.application:app
13+
--host 0.0.0.0
14+
--port 8000
15+
--reload
16+
--reload-dir src

docker-compose.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
version: '3.9'
2+
3+
services:
4+
app:
5+
build:
6+
context: .
7+
ports:
8+
- "8000:8000"
9+
restart: unless-stopped

src/planet/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from pydantic_settings import BaseSettings
55

6-
ENV = "staging"
6+
ENV = "production"
77
API_DOMAINS = {
88
"production": "https://api.planet.com",
99
"staging": "https://api.staging.planet-labs.com",

0 commit comments

Comments
 (0)