Skip to content

Commit 6686848

Browse files
committed
refactor: Consolidate debug and main container
1 parent 8e8c71e commit 6686848

File tree

8 files changed

+141
-254
lines changed

8 files changed

+141
-254
lines changed

.github/workflows/_debug_container.yml

Lines changed: 0 additions & 49 deletions
This file was deleted.

.github/workflows/ci.yml

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,6 @@ jobs:
4545
contents: read
4646
packages: write
4747

48-
debug_container:
49-
needs: [container, test]
50-
uses: ./.github/workflows/_debug_container.yml
51-
with:
52-
publish: ${{ needs.test.result == 'success' }}
53-
permissions:
54-
contents: read
55-
packages: write
56-
5748
docs:
5849
uses: ./.github/workflows/_docs.yml
5950

Dockerfile

Lines changed: 9 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -27,51 +27,27 @@ RUN mkdir -p /.cache/pip; chmod o+wrX /.cache/pip
2727
# Requires buildkit 0.17.0
2828
COPY --chmod=o+wrX . /workspaces/blueapi
2929
WORKDIR /workspaces/blueapi
30-
RUN touch dev-requirements.txt && pip install --upgrade pip && pip install -c dev-requirements.txt .
31-
32-
33-
FROM build AS debug
34-
35-
36-
# Set origin to use ssh
37-
RUN git remote set-url origin [email protected]:DiamondLightSource/blueapi.git
38-
39-
40-
# For this pod to understand finding user information from LDAP
41-
RUN apt update
42-
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
43-
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
44-
45-
# Make editable and debuggable
46-
RUN pip install debugpy
47-
RUN pip install -e .
48-
49-
RUN groupadd -g 1000 blueapi && \
50-
useradd -m -u 1000 -g blueapi blueapi
51-
52-
# Switch to the custom user
53-
USER blueapi
54-
55-
# Alternate entrypoint to allow devcontainer to attach
56-
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
57-
CMD [ "while true; do sleep 30; done;" ]
58-
30+
RUN touch dev-requirements.txt && pip install --upgrade pip && pip install debugpy && pip install -c dev-requirements.txt .
5931

6032
# The runtime stage copies the built venv into a slim runtime container
6133
FROM python:${PYTHON_VERSION}-slim AS runtime
6234
# Add apt-get system dependecies for runtime here if needed
63-
RUN apt-get update && apt-get install -y --no-install-recommends \
35+
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \
6436
# Git required for installing packages at runtime
6537
git \
38+
# gdb required for attaching debugger
39+
gdb \
40+
# May be required if attaching devcontainer
41+
libnss-ldapd \
6642
&& rm -rf /var/lib/apt/lists/*
43+
6744
COPY --from=build --chmod=o+wrX /venv/ /venv/
6845
COPY --from=build --chmod=o+wrX /.cache/pip /.cache/pip
46+
6947
ENV PATH=/venv/bin:$PATH
7048
ENV PYTHONPYCACHEPREFIX=/tmp/blueapi_pycache
7149

7250
# For this pod to understand finding user information from LDAP
73-
RUN apt update
74-
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
7551
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
7652

7753
# Set the MPLCONFIGDIR environment variable to a temporary directory to avoid
@@ -83,7 +59,7 @@ ENV MPLCONFIGDIR=/tmp/matplotlib
8359

8460
RUN groupadd -g 1000 blueapi && \
8561
useradd -m -u 1000 -g blueapi blueapi
86-
62+
8763
# Switch to the custom user
8864
USER blueapi
8965

helm/blueapi/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@ A Helm chart deploying a worker pod that runs Bluesky plans
99
| Key | Type | Default | Description |
1010
|-----|------|---------|-------------|
1111
| affinity | object | `{}` | May be required to run on specific nodes (e.g. the control machine) |
12-
| debug.enabled | bool | `false` | If enabled, disables liveness and readiness probes, and does not start the service on startup This allows connecting to the pod and starting the service manually to allow debugging on the cluster |
12+
| debug.enabled | bool | `false` | If enabled, runs debugpy, allowing port-forwarding to expose port 5678 or attached vscode instance |
13+
| debug.log-to-stderr | bool | `false` | If enabled configures debugpy to use the option `--log-to-stderr` |
14+
| debug.suspend | bool | `false` | If enabled does not start the service on startup This allows connecting to the pod and starting the service manually to allow debugging on the cluster |
1315
| extraEnvVars | list | `[]` | Additional envVars to mount to the pod |
1416
| fullnameOverride | string | `""` | |
1517
| global | object | `{}` | Not used, but must be present for validation when using as a dependency of another chart |

helm/blueapi/templates/statefulset.yaml

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ spec:
7272
type: Directory
7373
{{- end }}
7474
{{- end }}
75-
{{- if or .Values.debug.enabled (and .Values.initContainer.enabled .Values.initContainer.persistentVolume.enabled)}}
75+
{{- if ne 1000.0 .Values.securityContext.runAsUser }}
7676
- name: home # Required for vscode to install plugins
7777
emptyDir:
7878
sizeLimit: 500Mi
@@ -83,7 +83,7 @@ spec:
8383
{{- if .Values.initContainer.enabled }}
8484
initContainers:
8585
- name: setup-scratch
86-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}{{ ternary "-debug" "" .Values.debug.enabled }}"
86+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
8787
imagePullPolicy: {{ .Values.image.pullPolicy }}
8888
resources:
8989
{{- .Values.initResources | default .Values.resources | toYaml | nindent 12 }}
@@ -116,7 +116,7 @@ spec:
116116
securityContext:
117117
{{- toYaml . | nindent 12 }}
118118
{{- end }}
119-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}{{ ternary "-debug" "" .Values.debug.enabled }}"
119+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
120120
imagePullPolicy: {{ .Values.image.pullPolicy }}
121121
ports:
122122
- name: http
@@ -151,17 +151,34 @@ spec:
151151
- name: venv
152152
mountPath: /venv
153153
{{- end }}
154-
{{- if or .Values.debug.enabled (and .Values.initContainer.enabled .Values.initContainer.persistentVolume.enabled) }}
154+
{{- if ne 1000.0 .Values.securityContext.runAsUser }}
155155
- mountPath: /home
156156
name: home
157157
- mountPath: /var/run/nslcd
158158
name: nslcd
159159
{{- end }}
160-
{{- if not .Values.debug.enabled }}
161160
args:
162161
- "-c"
163162
- "/config/config.yaml"
164163
- "serve"
164+
{{- if .Values.debug.enabled }}
165+
command:
166+
- "python"
167+
- "-Xfrozen_modules=off"
168+
- "-m"
169+
- "debugpy"
170+
- "--listen"
171+
- "5678"
172+
{{- if .Values.debug.log-to-stderr }}
173+
- "--log-to-stderr"
174+
{{ end }}
175+
{{- if .Values.debug.suspend }}
176+
- "--wait-for-client"
177+
{{- end }}
178+
- "--configure-subProcess"
179+
- "true"
180+
- "-m"
181+
- "blueapi"
165182
{{- with .Values.livenessProbe }}
166183
livenessProbe:
167184
{{- toYaml . | nindent 12 }}
@@ -180,7 +197,7 @@ spec:
180197
name: {{ include "blueapi.fullname" . }}-otel-config
181198
env:
182199
{{- toYaml .Values.extraEnvVars | nindent 12 }}
183-
{{- if or .Values.debug.enabled (and .Values.initContainer.persistentVolume.enabled .Values.initContainer.enabled )}}
200+
{{- if ne 1000.0 .Values.securityContext.runAsUser }}
184201
- name: debug-account-sync
185202
image: ghcr.io/diamondlightsource/account-sync-sidecar:3.0.0
186203
volumeMounts:

helm/blueapi/values.schema.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,15 @@
1212
"type": "object",
1313
"properties": {
1414
"enabled": {
15-
"description": "If enabled, disables liveness and readiness probes, and does not start the service on startup This allows connecting to the pod and starting the service manually to allow debugging on the cluster",
15+
"description": "If enabled, runs debugpy, allowing port-forwarding to expose port 5678 or attached vscode instance",
16+
"type": "boolean"
17+
},
18+
"log-to-stderr": {
19+
"description": "If enabled configures debugpy to use the option `--log-to-stderr`",
20+
"type": "boolean"
21+
},
22+
"suspend": {
23+
"description": "If enabled does not start the service on startup This allows connecting to the pod and starting the service manually to allow debugging on the cluster",
1624
"type": "boolean"
1725
}
1826
}

helm/blueapi/values.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -223,9 +223,13 @@ initContainer:
223223
existingClaimName: ""
224224

225225
debug:
226-
# -- If enabled, disables liveness and readiness probes, and does not start the service on startup
227-
# This allows connecting to the pod and starting the service manually to allow debugging on the cluster
226+
# -- If enabled, runs debugpy, allowing port-forwarding to expose port 5678 or attached vscode instance
228227
enabled: false
228+
# -- If enabled does not start the service on startup
229+
# This allows connecting to the pod and starting the service manually to allow debugging on the cluster
230+
suspend: false
231+
# -- If enabled configures debugpy to use the option `--log-to-stderr`
232+
log-to-stderr: false
229233

230234
# -- Not used, but must be present for validation when using as a dependency of another chart
231235
global: {}

0 commit comments

Comments
 (0)