Skip to content

Commit b416b04

Browse files
authored
24 kubernetes setup (#35)
* added dockerfile * added docker-compose file * setting up pipeline to push to ghcr * Adding Auth Module (#18) * token creation init * fixed JSON issues * fixed lint issues * token is generating * added method to get claims * added api-server * Adding project APIs and Auth APIs (#23) * token creation init * fixed JSON issues * fixed lint issues * token is generating * added method to get claims * added api-server * added more apis * fixed authentication * fixing linting issues * added dockerfile * added docker-compose file * setting up pipeline to push to ghcr * cleaned tagging * testing docker file changes * fallback versioning * added kubernetes files
1 parent 8953d39 commit b416b04

7 files changed

Lines changed: 156 additions & 2 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Publish API server image to GHCR and deploys to Kubernetes Cluster
2+
3+
on:
4+
push:
5+
branches: [main]
6+
paths:
7+
- 'api-server/**'
8+
release:
9+
types: [published]
10+
workflow_dispatch:
11+
12+
env:
13+
REGISTRY: ghcr.io
14+
IMAGE_NAME: ${{ github.repository_owner }}/exosphere-api-server
15+
16+
jobs:
17+
publish-image:
18+
runs-on: ubuntu-latest
19+
20+
permissions:
21+
contents: read
22+
packages: write
23+
24+
steps:
25+
- uses: actions/checkout@v4
26+
27+
- uses: docker/setup-buildx-action@v3
28+
29+
- name: Log in to GHCR
30+
uses: docker/login-action@v3
31+
with:
32+
registry: ${{ env.REGISTRY }}
33+
username: ${{ github.actor }}
34+
password: ${{ secrets.GITHUB_TOKEN }}
35+
36+
- name: Generate tags & labels
37+
id: meta
38+
uses: docker/metadata-action@v5
39+
with:
40+
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
41+
tags: |
42+
type=raw,value=latest
43+
type=sha,format=short
44+
type=ref,event=tag # v1.2.3 → v1.2.3
45+
46+
- name: Build and push
47+
uses: docker/build-push-action@v5
48+
with:
49+
context: ./api-server
50+
push: true
51+
tags: ${{ steps.meta.outputs.tags }}
52+
labels: ${{ steps.meta.outputs.labels }}

api-server/.dockerignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*.pyo
5+
*.pyd
6+
*.so
7+
8+
# C extensions
9+
*.egg
10+
*.egg-info
11+
.eggs
12+
13+
# Virtual environments
14+
.venv/
15+
16+
# Git, CI and editor config
17+
.git/
18+
.github/
19+
.vscode/
20+
21+
# Logs and temp files
22+
*.log
23+
24+
# Other
25+
.env
26+
Dockerfile

api-server/Dockerfile

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
FROM python:3.12-slim-bookworm
2+
COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/
3+
4+
WORKDIR /api-server
5+
6+
COPY pyproject.toml uv.lock ./
7+
8+
RUN uv sync --locked
9+
10+
COPY . .
11+
12+
EXPOSE 8000
13+
14+
CMD ["uv", "run", "run.py", "--mode", "production", "--workers", "4"]

api-server/app/main.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ async def lifespan(app: FastAPI):
5959
app.add_middleware(UnhandledExceptionsMiddleware)
6060

6161

62-
63-
@app.get("/health-check")
62+
@app.get("/health")
6463
def health() -> dict:
6564
return {"message": "OK"}
6665

api-server/docker-compose.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: '3.8'
2+
3+
services:
4+
api-server:
5+
build:
6+
context: .
7+
dockerfile: Dockerfile
8+
ports:
9+
- "8000:8000"
10+
env_file:
11+
- .env
12+
command: ["uv", "run", "run.py", "--mode", "production", "--workers", "2"]

k8s/deployment.yml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
apiVersion: apps/v1
2+
kind: Deployment
3+
metadata:
4+
name: exosphere-api-server
5+
spec:
6+
replicas: 2
7+
selector:
8+
matchLabels:
9+
app: exosphere-api-server
10+
template:
11+
metadata:
12+
labels:
13+
app: exosphere-api-server
14+
spec:
15+
containers:
16+
- name: exosphere-api-server
17+
image: ghcr.io/exospherehost/exosphere-api-server:latest
18+
ports:
19+
- containerPort: 8000
20+
envFrom:
21+
- secretRef:
22+
name: exosphere-api-server-secrets
23+
resources:
24+
requests:
25+
memory: "256Mi"
26+
cpu: "250m"
27+
limits:
28+
memory: "512Mi"
29+
cpu: "500m"
30+
readinessProbe:
31+
httpGet:
32+
path: /health
33+
port: 8000
34+
initialDelaySeconds: 5
35+
periodSeconds: 10
36+
livenessProbe:
37+
httpGet:
38+
path: /health
39+
port: 8000
40+
initialDelaySeconds: 5
41+
periodSeconds: 10

k8s/service.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
apiVersion: v1
2+
kind: Service
3+
metadata:
4+
name: exosphere-api-server
5+
spec:
6+
selector:
7+
app: exosphere-api-server
8+
ports:
9+
- port: 8000
10+
targetPort: 8000

0 commit comments

Comments
 (0)