Skip to content

Commit

Permalink
Merge pull request #31 from JohnStrunk/kube
Browse files Browse the repository at this point in the history
Add manifest for deploying to Kubernetes
  • Loading branch information
mergify[bot] authored Apr 26, 2024
2 parents a17261a + 87b5a85 commit 66b8834
Show file tree
Hide file tree
Showing 3 changed files with 106 additions and 4 deletions.
12 changes: 10 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,16 @@ RUN pipenv --no-site-packages install -v --deploy
############################################################
FROM python:3.12-slim@sha256:2be8daddbb82756f7d1f2c7ece706aadcb284bf6ab6d769ea695cc3ed6016743 as final

RUN adduser --uid 19876 summarizer-bot && \
mkdir /app && \
chown summarizer-bot:summarizer-bot /app
USER 19876

# Make sure stdout gets flushed so we see it in the pod logs
ENV PYTHONUNBUFFERED=true

WORKDIR /app
COPY --from=builder /app/.venv /app/.venv
COPY *.py /app/
COPY --from=builder --chown=summarizer-bot:summarizer-bot /app/.venv /app/.venv
COPY --chown=summarizer-bot:summarizer-bot *.py /app/

ENTRYPOINT ["/app/.venv/bin/python", "bot.py"]
51 changes: 49 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Jira issue description
## Required environment variables

It is recommended that you provide the variables via a `.env` file since they
will contain sensitive information. There is already a `.gitignore` file that
will ignore the `.env` file.
will contain sensitive information. *There is already a `.gitignore` file that
will ignore the `.env` file.*

The following variables are required:

Expand Down Expand Up @@ -41,3 +41,50 @@ options:
-n, --no-update Do not update the Jira issues with the summaries
-r, --regenerate Force regeneration of summaries
```

Summarizer bot: `bot.py`:

```console
$ pipenv run ./bot.py --help
Loading .env environment variables...
usage: bot.py [-h] [-d MAX_DEPTH] [--log-level
{DEBUG,INFO,WARNING,ERROR,CRITICAL}] [-m MODIFIED_SINCE] [-n] [-s SECONDS]

Summarizer bot

options:
-h, --help show this help message and exit
-d MAX_DEPTH, --max-depth MAX_DEPTH
Maximum depth to recursively examine issues while summarizing
--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Set the logging level
-m MODIFIED_SINCE, --modified-since MODIFIED_SINCE
Summarize issues that have been modified since this date/time
-n, --no-update Do not update the Jira issues with the summaries
-s SECONDS, --seconds SECONDS
Seconds to wait between iterations
```

## Methods to run the summarizer bot

Note: All these methods assume that the required environment variables are
configured via a `.env` file, as described above.

- **Run locally via pipenv**:
- Install pipenv: `pip install pipenv`
- Install the dependencies: `pipenv install`
- Run the bot: `pipenv run ./bot.py <bot-args>`
- **Run locally via Docker**:
- Build the Docker image: `docker build -t jira-summarizer .`
- Run the Docker container: `docker run --env-file .env jira-summarizer
<bot-args>`
- **Run in Kubernetes**:
- Create a Namespace for the project: `kubectl create namespace
jira-summarizer`
- Create a Kubernetes secret with the environment variables: `kubectl -n
jira-summarizer create secret generic jira-summarizer-secret
--from-env-file=.env`
- Apply the Kubernetes manifest: `kubectl -n jira-summarizer apply -f
jira-summarizer.yaml`
*You may need to adjust the image specification in the manifest to point to
your Docker image repository*
47 changes: 47 additions & 0 deletions jira-summarizer.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
apiVersion: apps/v1
kind: Deployment
metadata:
name: jira-summarizer
labels:
app: jira-summarizer
spec:
replicas: 1
selector:
matchLabels:
app: jira-summarizer
strategy:
type: Recreate
template:
metadata:
labels:
app: jira-summarizer
spec:
containers:
- name: summarizer
image: ghcr.io/johnstrunk/jira-summarizer:latest
args:
- "--log-level"
- "INFO"
- "--seconds"
- "300"
envFrom:
- secretRef:
name: jira-summarizer-secret
optional: false
resources:
requests:
memory: "64Mi"
cpu: "10m"
limits:
memory: "512Mi"
cpu: "1000m"
securityContext:
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
readOnlyRootFilesystem: true
securityContext:
runAsNonRoot: true
terminationGracePeriodSeconds: 5

0 comments on commit 66b8834

Please sign in to comment.