From 2f42e62c8e73ed44b2e8c59067f29b86aa5a95c0 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Thu, 28 Mar 2024 22:52:00 -0400 Subject: [PATCH 01/12] Create docker-image.yml --- .github/workflows/docker-image.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 .github/workflows/docker-image.yml diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml new file mode 100644 index 0000000..32c77f3 --- /dev/null +++ b/.github/workflows/docker-image.yml @@ -0,0 +1,12 @@ +name: Docker Image CI + +on: + push: + branches: [ "master" ] +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag mtapi:$(date +%s) --tag mtapi:latest From ed695ec228f631dcd4a93d63ae6fd8473c0165c7 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Thu, 28 Mar 2024 23:34:57 -0400 Subject: [PATCH 02/12] docker + kube manifest --- .dockerignore | 1 + Dockerfile | 17 +++++++++++++++++ gunicorn.py | 10 ++++++++++ manifest.yaml | 45 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 gunicorn.py create mode 100644 manifest.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..a67fa26 --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +settings.cfg diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..be2349c --- /dev/null +++ b/Dockerfile @@ -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"] diff --git a/gunicorn.py b/gunicorn.py new file mode 100644 index 0000000..39d7aa5 --- /dev/null +++ b/gunicorn.py @@ -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)) diff --git a/manifest.yaml b/manifest.yaml new file mode 100644 index 0000000..ebaa784 --- /dev/null +++ b/manifest.yaml @@ -0,0 +1,45 @@ +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 + resources: + limits: + memory: "128Mi" + cpu: "500m" + ports: + - containerPort: 8000 + volumeMounts: + - name: mtapi-config + mountPath: /config + volumes: + - name: mtapi-config + configMap: + name: mtapi-config From 92f66031c4ea7566f74bb837f67c2a7bf7b078c6 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Thu, 28 Mar 2024 23:43:21 -0400 Subject: [PATCH 03/12] push docker image --- .github/workflows/docker-image.yml | 35 +++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 32c77f3..c8cc5a6 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -3,10 +3,39 @@ name: Docker Image CI on: push: branches: [ "master" ] +env: + REGISTRY: ghcr.io + IMAGE_NAME: ${{ github.repository }} + jobs: - build: + build-and-push-image: + permissions: + contents: read + packages: write runs-on: ubuntu-latest steps: + - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag mtapi:$(date +%s) --tag mtapi:latest + - 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 }} From d8ed354b69afb51fc00d8f280e73bfb5803b3a11 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Thu, 28 Mar 2024 23:47:15 -0400 Subject: [PATCH 04/12] move manifests --- manifest.yaml => manifests/manifest.yaml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename manifest.yaml => manifests/manifest.yaml (100%) diff --git a/manifest.yaml b/manifests/manifest.yaml similarity index 100% rename from manifest.yaml rename to manifests/manifest.yaml From 20e07289eaf20ec970c6d265589cf424f42df3dc Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Fri, 29 Mar 2024 00:03:00 -0400 Subject: [PATCH 05/12] add arm --- .github/workflows/docker-image.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index c8cc5a6..025d5bc 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -39,3 +39,4 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 From 4285410967739f5c901b3cef221f9f9014f762d9 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Fri, 29 Mar 2024 00:03:43 -0400 Subject: [PATCH 06/12] no arm i guess --- .github/workflows/docker-image.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index 025d5bc..c8cc5a6 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -39,4 +39,3 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} - platforms: linux/amd64,linux/arm64 From d9601c386bc63245517b9c83e820a0b1d6f79651 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Fri, 29 Mar 2024 00:05:13 -0400 Subject: [PATCH 07/12] add arch to manifest --- manifests/manifest.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/manifests/manifest.yaml b/manifests/manifest.yaml index ebaa784..c36bdc9 100644 --- a/manifests/manifest.yaml +++ b/manifests/manifest.yaml @@ -27,6 +27,8 @@ spec: labels: app: mtapi spec: + nodeSelector: + kubernetes.io/arch: amd64 containers: - name: mtapi image: ghcr.io/asg0451/mtapi:latest From c4d98c307c766a87c45e011a3ff498100001bd8d Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Fri, 29 Mar 2024 00:07:12 -0400 Subject: [PATCH 08/12] alter limits --- manifests/manifest.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/manifests/manifest.yaml b/manifests/manifest.yaml index c36bdc9..130f1ca 100644 --- a/manifests/manifest.yaml +++ b/manifests/manifest.yaml @@ -34,8 +34,8 @@ spec: image: ghcr.io/asg0451/mtapi:latest resources: limits: - memory: "128Mi" - cpu: "500m" + memory: "1Gi" + cpu: "1" ports: - containerPort: 8000 volumeMounts: From 5bf81e7184dc58e6f1207d6ef8780aaa6ebd5b37 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Fri, 29 Mar 2024 00:09:14 -0400 Subject: [PATCH 09/12] conc --- manifests/manifest.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/manifests/manifest.yaml b/manifests/manifest.yaml index 130f1ca..e2a0ce6 100644 --- a/manifests/manifest.yaml +++ b/manifests/manifest.yaml @@ -32,6 +32,9 @@ spec: containers: - name: mtapi image: ghcr.io/asg0451/mtapi:latest + env: + - name: WEB_CONCURRENCY + value: "4" resources: limits: memory: "1Gi" From 8d15a8212b97b014ff1db5ec57b7e5a008bc33e8 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Sat, 30 Mar 2024 15:39:26 -0400 Subject: [PATCH 10/12] multiplat --- .github/workflows/docker-image.yml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/.github/workflows/docker-image.yml b/.github/workflows/docker-image.yml index c8cc5a6..cf9919e 100644 --- a/.github/workflows/docker-image.yml +++ b/.github/workflows/docker-image.yml @@ -16,6 +16,13 @@ jobs: 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: @@ -39,3 +46,4 @@ jobs: push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} + platforms: linux/amd64,linux/arm64 From a51ef683b32e5b0b1803d25b229a24d294808ad5 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Sat, 30 Mar 2024 15:41:14 -0400 Subject: [PATCH 11/12] rm node selector --- .vscode/settings.json | 5 +++++ manifests/manifest.yaml | 2 -- 2 files changed, 5 insertions(+), 2 deletions(-) create mode 100644 .vscode/settings.json diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..ab42e63 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,5 @@ +{ + "githubPullRequests.ignoredPullRequestBranches": [ + "master" + ] +} diff --git a/manifests/manifest.yaml b/manifests/manifest.yaml index e2a0ce6..28ed825 100644 --- a/manifests/manifest.yaml +++ b/manifests/manifest.yaml @@ -27,8 +27,6 @@ spec: labels: app: mtapi spec: - nodeSelector: - kubernetes.io/arch: amd64 containers: - name: mtapi image: ghcr.io/asg0451/mtapi:latest From 5b8bb3b8c440d8d9c48ad4c6f95e74ea4b454686 Mon Sep 17 00:00:00 2001 From: Miles Frankel Date: Fri, 5 Apr 2024 22:21:19 -0400 Subject: [PATCH 12/12] burstman --- manifests/manifest.yaml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/manifests/manifest.yaml b/manifests/manifest.yaml index 28ed825..c6407f5 100644 --- a/manifests/manifest.yaml +++ b/manifests/manifest.yaml @@ -34,9 +34,12 @@ spec: - name: WEB_CONCURRENCY value: "4" resources: + requests: + memory: "512Mi" + cpu: "500m" limits: memory: "1Gi" - cpu: "1" + cpu: "2" ports: - containerPort: 8000 volumeMounts: