Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
settings.cfg
49 changes: 49 additions & 0 deletions .github/workflows/docker-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Docker Image CI

on:
push:
branches: [ "master" ]
env:
REGISTRY: ghcr.io
IMAGE_NAME: ${{ github.repository }}

jobs:
build-and-push-image:
permissions:
contents: read
packages: write
runs-on: ubuntu-latest
steps:

- uses: actions/checkout@v3

# for multiplatform image support
- name: Set up QEMU
uses: docker/setup-qemu-action@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Log in to the Container registry
uses: docker/login-action@65b78e6e13532edd9afa3aa52ac7964289d1a9c1
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
tags: |
type=sha
type=raw,value=latest,enable={{is_default_branch}}

- name: Build and push Docker image
uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
5 changes: 5 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"githubPullRequests.ignoredPullRequestBranches": [
"master"
]
}
17 changes: 17 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
FROM python:3-alpine

WORKDIR /app
COPY requirements.txt /app
RUN --mount=type=cache,target=/root/.cache/pip pip3 install -r requirements.txt

# install gunicorn production server
RUN --mount=type=cache,target=/root/.cache/pipu pip3 install gunicorn

COPY . /app

# put your settings.cfg in here
RUN mkdir /config
RUN ln -s /config/settings.cfg /app/settings.cfg

EXPOSE 8000
CMD ["gunicorn", "-c", "gunicorn.py", "app:app"]
10 changes: 10 additions & 0 deletions gunicorn.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@

import multiprocessing
import os

bind = f"0.0.0.0:{os.getenv('PORT', '8000')}"
accesslog = "-"
access_log_format = "%(h)s %(l)s %(u)s %(t)s '%(r)s' %(s)s %(b)s '%(f)s' '%(a)s' in %(D)sµs" # noqa: E501

workers = int(os.getenv("WEB_CONCURRENCY", multiprocessing.cpu_count() * 2))
threads = int(os.getenv("PYTHON_MAX_THREADS", 1))
51 changes: 51 additions & 0 deletions manifests/manifest.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: mtapi-config
data:
settings.cfg: |
MTA_KEY = 'i-dont-think-this-requires-a-key-but-whatever'
STATIONS_FILE = './data/stations.json'
CROSS_ORIGIN = '*'
MAX_TRAINS=10
MAX_MINUTES=30
CACHE_SECONDS=60
THREADED=True
DEBUG=False

---
apiVersion: apps/v1
kind: Deployment
metadata:
name: mtapi
spec:
selector:
matchLabels:
app: mtapi
template:
metadata:
labels:
app: mtapi
spec:
containers:
- name: mtapi
image: ghcr.io/asg0451/mtapi:latest
env:
- name: WEB_CONCURRENCY
value: "4"
resources:
requests:
memory: "512Mi"
cpu: "500m"
limits:
memory: "1Gi"
cpu: "2"
ports:
- containerPort: 8000
volumeMounts:
- name: mtapi-config
mountPath: /config
volumes:
- name: mtapi-config
configMap:
name: mtapi-config