Skip to content

Commit 8949076

Browse files
keithralphsWare, Joseph (DLSLtd,RAL,LSCI)
andauthored
feat: Add debugging container target to Helm (#960)
Co-authored-by: Ware, Joseph (DLSLtd,RAL,LSCI) <[email protected]>
1 parent 4d5079d commit 8949076

4 files changed

Lines changed: 72 additions & 7 deletions

File tree

.github/workflows/_container.yml

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,27 @@ jobs:
5959
tags: |
6060
type=ref,event=tag
6161
type=raw,value=latest
62-
62+
63+
- name: Create tags for publishing debug image
64+
id: debug-meta
65+
uses: docker/metadata-action@v5
66+
with:
67+
images: ghcr.io/${{ github.repository }}
68+
tags: |
69+
type=ref,event=tag,suffix=-debug
70+
type=raw,value=latest-debug
71+
72+
- name: Build and publish debug image to container registry
73+
if: github.ref_type == 'tag'
74+
uses: docker/build-push-action@v6
75+
env:
76+
DOCKER_BUILD_RECORD_UPLOAD: false
77+
with:
78+
context: .
79+
push: true
80+
target: debug
81+
tags: ${{ steps.debug-meta.outputs.tags }}
82+
6383
- name: Push cached image to container registry
6484
if: github.ref_type == 'tag'
6585
uses: docker/build-push-action@263435318d21b8e681c14492fe198d362a7d2c83 # v6

Dockerfile

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,38 @@ ENV PATH=/venv/bin:$PATH
2121

2222
# The build stage installs the context into the venv
2323
FROM developer AS build
24-
COPY . /context
25-
WORKDIR /context
24+
RUN mkdir -p /.cache/pip; chmod o+wrX /.cache/pip
25+
COPY --chmod=o+wrX . /workspaces/blueapi
26+
WORKDIR /workspaces/blueapi
2627
RUN touch dev-requirements.txt && pip install --upgrade pip && pip install -c dev-requirements.txt .
2728

29+
FROM build AS debug
30+
31+
# Set origin to use ssh
32+
RUN git remote set-url origin [email protected]:diamondlightsource/DiamondLightSource/blueapi.git
33+
34+
# For this pod to understand finding user information from LDAP
35+
RUN apt update
36+
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
37+
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
38+
39+
# Make editable and debuggable
40+
RUN pip install debugpy
41+
RUN pip install -e .
42+
43+
# Alternate entrypoint to allow devcontainer to attach
44+
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
45+
CMD [ "while true; do sleep 30; done;" ]
46+
2847
# The runtime stage copies the built venv into a slim runtime container
2948
FROM python:${PYTHON_VERSION%@*}-slim AS runtime
3049
# Add apt-get system dependecies for runtime here if needed
3150
RUN apt-get update && apt-get install -y --no-install-recommends \
3251
# Git required for installing packages at runtime
3352
git \
3453
&& rm -rf /var/lib/apt/lists/*
35-
COPY --from=build /venv/ /venv/
54+
COPY --from=build --chmod=o+wrX /venv/ /venv/
55+
COPY --from=build --chmod=o+wrX /.cache/pip /.cache/pip
3656
ENV PATH=/venv/bin:$PATH
3757
ENV PYTHONPYCACHEPREFIX=/tmp/blueapi_pycache
3858

@@ -43,7 +63,5 @@ ENV PYTHONPYCACHEPREFIX=/tmp/blueapi_pycache
4363

4464
ENV MPLCONFIGDIR=/tmp/matplotlib
4565

46-
RUN mkdir -p /.cache/pip; chmod -R 777 /venv /.cache/pip
47-
4866
ENTRYPOINT ["blueapi"]
4967
CMD ["serve"]

helm/blueapi/templates/statefulset.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ spec:
5252
emptyDir:
5353
sizeLimit: 5Gi
5454
{{- end }}
55+
{{- if .Values.debug.enabled }}
56+
- name: home # Required for vscode to install plugins
57+
emptyDir:
58+
sizeLimit: 500Mi
59+
- name: nslcd # Shared volume between main and sidecar container
60+
emptyDir:
61+
sizeLimit: 5Mi
62+
{{- end }}
5563
{{- if .Values.initContainer.enabled }}
5664
initContainers:
5765
- name: setup-scratch
@@ -81,7 +89,7 @@ spec:
8189
- name: {{ .Chart.Name }}
8290
securityContext:
8391
{{- toYaml .Values.securityContext | nindent 12 }}
84-
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}"
92+
image: "{{ .Values.image.repository }}:{{ .Values.image.tag | default .Chart.AppVersion }}{{ ternary "-debug" "" .Values.debug.enabled }}"
8593
imagePullPolicy: {{ .Values.image.pullPolicy }}
8694
resources:
8795
{{- toYaml .Values.resources | nindent 12 }}
@@ -96,15 +104,31 @@ spec:
96104
- name: venv
97105
mountPath: /venv
98106
{{- end }}
107+
{{- if .Values.debug.enabled }}
108+
- mountPath: /home
109+
name: home
110+
- mountPath: /var/run/nslcd
111+
name: nslcd
112+
{{- end }}
113+
{{- if not .Values.debug.enabled }}
99114
args:
100115
- "-c"
101116
- "/config/config.yaml"
102117
- "serve"
118+
{{ end }}
103119
envFrom:
104120
- configMapRef:
105121
name: {{ include "blueapi.fullname" . }}-otel-config
106122
env:
107123
{{- toYaml .Values.extraEnvVars | nindent 12 }}
124+
{{- if .Values.debug.enabled }}
125+
- name: debug-account-sync
126+
image: ghcr.io/diamondlightsource/account-sync-sidecar:3.0.0
127+
volumeMounts:
128+
# This allows the nslcd socket to be shared between the main container and the sidecar
129+
- mountPath: /var/run/nslcd
130+
name: nslcd
131+
{{- end }}
108132
{{- with .Values.nodeSelector }}
109133
nodeSelector:
110134
{{- toYaml . | nindent 8 }}

helm/blueapi/values.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,3 +126,6 @@ worker:
126126
port: 12232
127127
initContainer:
128128
enabled: false
129+
130+
debug:
131+
enabled: false

0 commit comments

Comments
 (0)