Skip to content

Commit

Permalink
Switch to UWSGI service
Browse files Browse the repository at this point in the history
Closes #27
  • Loading branch information
edwardtheharris committed Aug 15, 2024
1 parent bd46ed9 commit 8756ead
Show file tree
Hide file tree
Showing 10 changed files with 53 additions and 34 deletions.
4 changes: 2 additions & 2 deletions Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,6 @@ type: application
#
# ```{literalinclude} /Chart.yaml
# :language: yaml
# :start-at: "version: 0.0.2\n"
# :start-at: "version: 0.0.3\n"
# ```
version: 0.0.2
version: 0.0.3
2 changes: 2 additions & 0 deletions config/nautobot.init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ sudo -u nautobot /opt/nautobot/bin/pip install --no-cache-dir -U pip
sudo -u nautobot /opt/nautobot/bin/pip install --no-cache-dir -r /opt/.nautobot/reqs

cat /opt/.nautobot/.bashrc > /opt/nautobot/.bashrc
cat /opt/.nautobot/uwsgi.ini > /opt/nautobot/uwsgi.ini

chown -v nautobot:nautobot /opt/nautobot/.bashrc
chown -v nautobot:nautobot /opt/nautobot/uwsgi.ini

NAUTOBOT_ROOT=/opt/nautobot

Expand Down
18 changes: 8 additions & 10 deletions config/uwsgi.ini
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
[uwsgi]
; The IP address (typically localhost) and port that the WSGI process should listen on
socket = 127.0.0.1:8001
http = 0.0.0.0:8000

; Fail to start if any parameter in the configuration file isn’t explicitly understood by uWSGI
strict = true
strict = false

; Enable master process to gracefully re-spawn and pre-fork workers
master = true
Expand All @@ -24,30 +24,28 @@ die-on-term = true
need-app = true

; By default, uWSGI has rather verbose logging that can be noisy
disable-logging = true
disable-logging = false

; Assert that critical 4xx and 5xx errors are still logged
log-4xx = true
log-5xx = true

; Enable HTTP 1.1 keepalive support
http-keepalive = 1

;
; Advanced settings (disabled by default)
; Customize these for your environment if and only if you need them.
; Ref: https://uwsgi-docs.readthedocs.io/en/latest/Options.html
;

; Number of uWSGI workers to spawn. This should typically be 2n+1, where n is the number of CPU cores present.
; processes = 5
processes = 5

; If using subdirectory hosting e.g. example.com/nautobot, you must uncomment this line. Otherwise you'll get double paths e.g. example.com/nautobot/nautobot/.
; Ref: https://uwsgi-docs.readthedocs.io/en/latest/Changelog-2.0.11.html#fixpathinfo-routing-action
; route-run = fixpathinfo:

; If hosted behind a load balancer uncomment these lines, the harakiri timeout should be greater than your load balancer timeout.
; Ref: https://uwsgi-docs.readthedocs.io/en/latest/HTTP.html?highlight=keepalive#http-keep-alive
; harakiri = 65
; add-header = Connection: Keep-Alive
; http-keepalive = 1
harakiri = 65
add-header = Connection: Keep-Alive
; Enable HTTP 1.1 keepalive support
http-keepalive = 1
2 changes: 2 additions & 0 deletions container/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ ARG USER=nautobot
LABEL io.ghcr.edwardtheharris.helm-nautobot.editor="Xander Harris"
LABEL io.ghcr.edwardtheharris.helm-nautobot.name="${USER}"
LABEL org.opencontainers.image.source="https://github.com/edwardtheharris/helm-nautobot"
LABEL org.opencontainers.image.description="Runs ${USER} for nautobot on Kubernetes."
LABEL io.ghcr.edwardtheharris.helm-nautobot.version="${VERSION}"
RUN apk add --no-cache \
alpine-sdk \
Expand All @@ -13,6 +14,7 @@ RUN apk add --no-cache \
iputils-ping \
libxml2-dev \
jpeg-dev \
mailcap \
nmap \
pkgconfig \
python3-dev \
Expand Down
4 changes: 2 additions & 2 deletions container/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ To build the nautobot container you run the build command below.
```{code-block} shell
:caption: build nautobot
VERSION=0.0.1
VERSION=0.0.2
export VERSION
Expand All @@ -31,7 +31,7 @@ argument as shown below.
```{code-block} shell
:caption: build celery
VERSION=0.0.1
VERSION=0.0.2
export VERSION
Expand Down
10 changes: 5 additions & 5 deletions templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -93,10 +93,11 @@ spec:
mountPath: /opt/.nautobot
containers:
- name: {{ .Values.nameOverride }}
args:
- 'apk add --no-cache sudo && sudo -E -u nautobot /opt/nautobot/bin/nautobot-server start --ini /opt/nautobot/uwsgi.ini'
command:
- tail
- '-f'
- /dev/null
- /bin/bash
- '-c'
env:
- name: NAUTOBOT_ALLOWED_HOSTS
value: {{ .Values.config.allowed_hosts | quote }}
Expand Down Expand Up @@ -180,9 +181,8 @@ spec:
- mountPath: /opt
name: nautobot-pvc
subPath: nautobot
- mountPath: /opt
- mountPath: /opt/.nautobot
name: {{ .Values.config.name }}
subPath: .nautobot
imagePullSecrets:
- name: secret.github.ghcr
volumes:
Expand Down
2 changes: 1 addition & 1 deletion tests/connection_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ tests:
- equal:
path: metadata.labels
value:
helm.sh/chart: nautobot-0.0.2
helm.sh/chart: nautobot-0.0.3
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: "2.3.0"
app.kubernetes.io/part-of: nautobot
Expand Down
20 changes: 10 additions & 10 deletions tests/deployment_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ tests:
value: nautobot-init
- equal:
path: spec.template.spec.initContainers[0].image
value: ghcr.io/edwardtheharris/helm-nautobot/nautobot:0.0.1.rc30
value: ghcr.io/edwardtheharris/helm-nautobot/nautobot:0.0.2
- equal:
path: spec.template.spec.initContainers[0].command[0]
value: /bin/bash
Expand All @@ -61,16 +61,16 @@ tests:
value: nautobot
- equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/edwardtheharris/helm-nautobot/nautobot:0.0.1.rc30
value: ghcr.io/edwardtheharris/helm-nautobot/nautobot:0.0.2
- equal:
path: spec.template.spec.containers[0].command[0]
value: tail
value: /bin/bash
- equal:
path: spec.template.spec.containers[0].command[1]
value: '-f'
value: '-c'
- equal:
path: spec.template.spec.containers[0].command[2]
value: /dev/null
path: spec.template.spec.containers[0].args[0]
value: 'apk add --no-cache sudo && sudo -E -u nautobot /opt/nautobot/bin/nautobot-server start --ini /opt/nautobot/uwsgi.ini'
- equal:
path: spec.template.spec.containers[0].env[0].name
value: NAUTOBOT_ALLOWED_HOSTS
Expand Down Expand Up @@ -113,7 +113,7 @@ tests:
value: celery-worker-init
- equal:
path: spec.template.spec.initContainers[0].image
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.1.rc30
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.2
- equal:
path: spec.template.spec.initContainers[0].command[0]
value: /bin/bash
Expand All @@ -135,7 +135,7 @@ tests:
value: celery-worker
- equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.1.rc30
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.2
- equal:
path: spec.template.spec.containers[0].command[0]
value: /bin/bash
Expand Down Expand Up @@ -181,7 +181,7 @@ tests:
value: celery-beat-init
- equal:
path: spec.template.spec.initContainers[0].image
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.1.rc30
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.2
- equal:
path: spec.template.spec.initContainers[0].command[0]
value: /bin/bash
Expand All @@ -203,7 +203,7 @@ tests:
value: celery-beat
- equal:
path: spec.template.spec.containers[0].image
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.1.rc30
value: ghcr.io/edwardtheharris/helm-nautobot/celery:0.0.2
- equal:
path: spec.template.spec.containers[0].command[0]
value: /bin/bash
Expand Down
2 changes: 1 addition & 1 deletion tests/ingress_test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ tests:
- equal:
path: metadata.labels
value:
helm.sh/chart: nautobot-0.0.2
helm.sh/chart: nautobot-0.0.3
app.kubernetes.io/managed-by: Helm
app.kubernetes.io/version: 2.3.0
app.kubernetes.io/part-of: nautobot
Expand Down
23 changes: 20 additions & 3 deletions values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,27 @@ config:
allowed_hosts: "*"
caches_backend: django_redis.cache.RedisCache
celery:
broker: 'redis://redis.redis.svc.cluster.local:6379/0'
livenessProbe:
exec:
command:
- /opt/nautobot/bin/nautobot-server
- celery
- status
# When to give up` and restart the container
failureThreshold: 3
# Delay before the first probe is initiated
initialDelaySeconds: 30
# How often to perform the probe
periodSeconds: 10
# Minimum consecutive successes for the probe to
# be considered successful after having failed
successThreshold: 1
# When the probe times out
timeoutSeconds: 5
img:
repository: ghcr.io/edwardtheharris/helm-nautobot/celery
tag: '0.0.1.rc30'
broker: 'redis://redis.redis.svc.cluster.local:6379/0'
tag: '0.0.2'
name: celery-config
results: 'redis://redis.redis.svc.cluster.local:6379/0'
root: '/opt/celery'
Expand Down Expand Up @@ -125,7 +142,7 @@ image:
pullPolicy: Always
repository: ghcr.io/edwardtheharris/helm-nautobot/nautobot
# Overrides the image tag whose default is the chart appVersion.
tag: '0.0.1.rc30'
tag: '0.0.2'
secret:
name: ghcr
data: ''
Expand Down

0 comments on commit 8756ead

Please sign in to comment.