Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@
"charliermarsh.ruff",
"ms-pyright.pyright",
"ms-azuretools.vscode-docker",
"ms-kubernetes-tools.vscode-kubernetes-tools"
"ms-kubernetes-tools.vscode-kubernetes-tools",
"rioj7.command-variable",
]
}
},
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/_container.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ jobs:
with:
context: .
# Need load and tags so we can test it below
target: runtime
load: true
tags: tag_for_testing

Expand Down Expand Up @@ -94,6 +95,7 @@ jobs:
with:
context: .
push: true
target: runtime
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}

Expand Down
47 changes: 47 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,33 @@
],
"console": "integratedTerminal",
},
{
"name": "Attach debugger",
"type": "debugpy",
"request": "attach",
"justMyCode": false,
"connect": {
"host": "0.0.0.0",
"port": 5678,
},
"preLaunchTask": "kubectl port-forward",
"postDebugTask": "pv-unmount",
"subProcess": true,
"pathMappings": [
{
"localRoot": "${input:Mount Point}",
"remoteRoot": "${input:PVC Name}"
},
{
"localRoot": "${workspaceFolder}/src/blueapi",
"remoteRoot": "/venv/lib/python3.11/site-packages/blueapi"
},
{
"localRoot": "${workspaceFolder}",
"remoteRoot": "/workspaces/blueapi"
}
]
},
{
"name": "Blueapi Server",
"type": "debugpy",
Expand Down Expand Up @@ -61,6 +88,26 @@
},
],
"inputs": [
{
"id": "PVC Name",
"type": "command",
"command": "extension.commandvariable.promptStringRemember",
"args": {
"key": "PVC Name",
"description": "Name of the PVC to mount locally",
"default": "scratch-1.0.0"
}
},
{
"id": "Mount Point",
"type": "command",
"command": "extension.commandvariable.promptStringRemember",
"args": {
"key": "Mount Point",
"description": "Location to mount PVC locally, must exist as an empty directory",
"default": "/scratch/mountPoint"
}
},
{
"id": "controller_args",
"type": "promptString",
Expand Down
73 changes: 73 additions & 0 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,79 @@
"cwd": "${workspaceRoot}"
},
"problemMatcher": [],
},
{
"type": "shell",
"label": "kubectl pv-mounter",
"command": "kubectl",
"args": [
"pv-mounter",
"mount",
"${input:namespace}",
"${input:PVC Name}",
"${input:Mount Point}",
"--cpu-limit",
"100m"
],
"problemMatcher": [],
},
{
"dependsOn": "kubectl pv-mounter",
"type": "shell",
"label": "kubectl port-forward",
"command": "kubectl",
"args": [
"port-forward",
"-n",
"${input:namespace}",
"${input:pod}",
"5678",
"&"
],
"problemMatcher": [],
},
{
"type": "shell",
"label": "pv-unmount",
"command": "kubectl",
"args": [
"pv-mounter",
"clean",
"${input:namespace}",
"${promptStringRemember:PVC Name}",
"${promptStringRemember:Mount Point}",
],
"problemMatcher": [],
}
],
"inputs": [
{
"id": "namespace",
"type": "promptString",
"description": "Beamline namespace in the cluster",
"default": "ixx-beamline"
},
{
"id": "pod",
"type": "promptString",
"description": "Blueapi pod name",
"default": "ixx-blueapi-0"
},
{
"id": "PVC Name",
"type": "command",
"command": "extension.commandvariable.remember",
"args": {
"key": "PVC Name"
}
},
{
"id": "Mount Point",
"type": "command",
"command": "extension.commandvariable.remember",
"args": {
"key": "Mount Point"
}
},
]
}
40 changes: 18 additions & 22 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -25,41 +25,25 @@ FROM developer AS build
RUN mkdir -p /.cache/pip; chmod o+wrX /.cache/pip
COPY --chmod=o+wrX . /workspaces/blueapi
WORKDIR /workspaces/blueapi
RUN touch dev-requirements.txt && pip install --upgrade pip && pip install -c dev-requirements.txt .

FROM build AS debug

# Set origin to use ssh
RUN git remote set-url origin [email protected]:diamondlightsource/DiamondLightSource/blueapi.git

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

# Make editable and debuggable
RUN pip install debugpy
RUN pip install -e .

# Alternate entrypoint to allow devcontainer to attach
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
CMD [ "while true; do sleep 30; done;" ]
RUN touch dev-requirements.txt && pip install --upgrade pip && pip install debugpy && pip install -c dev-requirements.txt .

# The runtime stage copies the built venv into a slim runtime container
FROM python:${PYTHON_VERSION}-slim AS runtime
# Add apt-get system dependecies for runtime here if needed
RUN apt-get update && apt-get install -y --no-install-recommends \
RUN DEBIAN_FRONTEND=noninteractive apt-get update && apt-get install -y --no-install-recommends \
# Git required for installing packages at runtime
git \
# gdb required for attaching debugger
gdb \
# required if attaching devcontainer
libnss-ldapd \
&& rm -rf /var/lib/apt/lists/*
COPY --from=build --chmod=o+wrX /venv/ /venv/
COPY --from=build --chmod=o+wrX /.cache/pip /.cache/pip
ENV PATH=/venv/bin:$PATH
ENV PYTHONPYCACHEPREFIX=/tmp/blueapi_pycache

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

# Set the MPLCONFIGDIR environment variable to a temporary directory to avoid
Expand All @@ -71,3 +55,15 @@ ENV MPLCONFIGDIR=/tmp/matplotlib

ENTRYPOINT ["blueapi"]
CMD ["serve"]

FROM runtime AS debug
COPY --from=build --chmod=o+wrX /workspaces/blueapi /blueapi
WORKDIR /blueapi
# Make editable
RUN pip install -e .
# Set origin to use ssh
RUN git remote set-url origin [email protected]:diamondlightsource/DiamondLightSource/blueapi.git

# Alternate entrypoint to allow devcontainer to attach
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
CMD [ "while true; do sleep 30; done;" ]
13 changes: 13 additions & 0 deletions helm/blueapi/templates/statefulset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ spec:
if [ $? -ne 0 ]; then echo 'Blueapi failed'; exit 1; fi;
echo "Exporting venv as artefact"
cp -r /venv/* /artefacts
{{if .Values.initContainer.persistentVolume.enabled }}chmod o+wrX -R {{ .Values.worker.scratch.root }}{{- end}}
volumeMounts:
- name: init-config
mountPath: "/config"
Expand Down Expand Up @@ -154,6 +155,18 @@ spec:
name: nslcd
{{- end }}
{{- if not .Values.debug.enabled }}
command: [
"python",
"-Xfrozen_modules=off",
"-m",
"debugpy",
"--listen",
"0.0.0.0:5678",
"--configure-subProcess",
"true",
"-m",
"blueapi"
]
args:
- "-c"
- "/config/config.yaml"
Expand Down