diff --git a/.github/renovate.json5 b/.github/renovate.json5 index 7066419..72bb23f 100644 --- a/.github/renovate.json5 +++ b/.github/renovate.json5 @@ -24,7 +24,8 @@ "kubernetes": { "fileMatch": [ "^jira-summarizer\\.yaml$", - "^jira-estimator\\.yaml$" + "^jira-estimator\\.yaml$", + "^summarize-api\\.yaml$" ] }, "packageRules": [ diff --git a/Pipfile b/Pipfile index 2929b9f..9f514d3 100644 --- a/Pipfile +++ b/Pipfile @@ -10,6 +10,7 @@ ibm-generative-ai = "*" backoff-utils = "*" flask = "*" flask-jwt-extended = "*" +gunicorn = "*" [dev-packages] ipykernel = "*" diff --git a/Pipfile.lock b/Pipfile.lock index 6b6e76e..16cd4ed 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "988783d8275cdfc784dbfda689ba79960cf0a4d9a13aacc1053c1f0e13ef761a" + "sha256": "2f4b80be08ec25ea0dc1f7fceb82a13267ebec69bb6782a68b7e002b94279fd1" }, "pipfile-spec": 6, "requires": { @@ -455,6 +455,15 @@ "markers": "platform_machine == 'aarch64' or (platform_machine == 'ppc64le' or (platform_machine == 'x86_64' or (platform_machine == 'amd64' or (platform_machine == 'AMD64' or (platform_machine == 'win32' or platform_machine == 'WIN32')))))", "version": "==3.0.3" }, + "gunicorn": { + "hashes": [ + "sha256:350679f91b24062c86e386e198a15438d53a7a8207235a78ba1b53df4c4378d9", + "sha256:4a0b436239ff76fb33f11c07a16482c521a7e09c1ce3cc293c2330afe01bec63" + ], + "index": "pypi", + "markers": "python_version >= '3.7'", + "version": "==22.0.0" + }, "h11": { "hashes": [ "sha256:8f19fbbe99e72420ff35c00b27a34cb9937e902a8b810e2c88300c6f0a3b699d", diff --git a/summarize-api.yaml b/summarize-api.yaml new file mode 100644 index 0000000..8b0b4ab --- /dev/null +++ b/summarize-api.yaml @@ -0,0 +1,83 @@ +--- +kind: Route +apiVersion: route.openshift.io/v1 +metadata: + name: summarize-api + labels: + app: summarize-api +spec: + host: jira-summarizer.apps.platform-sts.pcbk.p1.openshiftapps.com + to: + kind: Service + name: summarize-api + weight: 100 + port: + targetPort: 8000 + tls: + termination: edge + insecureEdgeTerminationPolicy: Redirect + wildcardPolicy: None + +--- +apiVersion: v1 +kind: Service +metadata: + name: summarize-api +spec: + selector: + app: summarize-api + ports: + - protocol: TCP + port: 8000 + targetPort: 8000 + +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: summarize-api + labels: + app: summarize-api +spec: + replicas: 1 + selector: + matchLabels: + app: summarize-api + strategy: + type: Recreate + template: + metadata: + labels: + app: summarize-api + spec: + containers: + - name: estimator + image: ghcr.io/johnstrunk/jira-summarizer:1.2.1@sha256:505b205a45f0eb24d82fa5c02dc105af6d075362cb2694d82dc5face1d0a54ed + command: + - "/app/.venv/bin/gunicorn" + args: + - "--bind=0.0.0.0:8000" + - "--access-logfile=-" + - "summarize_api:create_app()" + envFrom: + - secretRef: + name: jira-summarizer-secret + optional: false + ports: + - containerPort: 8000 + resources: + requests: + memory: "64Mi" + cpu: "10m" + limits: + memory: "512Mi" + cpu: "1000m" + securityContext: + allowPrivilegeEscalation: false + capabilities: + drop: + - ALL + readOnlyRootFilesystem: true + securityContext: + runAsNonRoot: true + terminationGracePeriodSeconds: 10 diff --git a/summarize_api.py b/summarize_api.py index bfb9db5..f1222db 100755 --- a/summarize_api.py +++ b/summarize_api.py @@ -2,8 +2,10 @@ """Summarize a JIRA issue""" +import datetime import os import sys +from datetime import UTC from sys import argv from atlassian import Jira # type: ignore @@ -41,6 +43,9 @@ def summarize_issue(): if key is None: return {"error": 'Missing required parameter "key"'}, 400 + when = datetime.datetime.now(UTC) - datetime.timedelta(hours=1) + issue_cache.remove_older_than(when) + issue = issue_cache.get_issue(client, key) return { "key": key,