Skip to content

Commit 586ae06

Browse files
author
Ware, Joseph (DLSLtd,RAL,LSCI)
committed
Update with response to testing
1 parent bb20fd6 commit 586ae06

File tree

4 files changed

+33
-23
lines changed

4 files changed

+33
-23
lines changed

.github/workflows/_account_sync.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,4 @@ jobs:
4141
with:
4242
context: account-sync
4343
push: true
44-
tags: ${{ steps.debug-meta.outputs.tags }}
44+
tags: ${{ steps.meta.outputs.tags }}

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,4 @@ jobs:
5151
needs: release
5252
uses: ./.github/workflows/_account_sync.yml
5353
permissions:
54-
contents: write
54+
packages: write

docs/how-to/debug-in-cluster.md

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,58 @@
11
# Debug a container within a cluster
22

3-
The container build also publishes a debug container for each tagged release of the container with the tag suffixed with `-debug`. This container contains the workspace and has an alternative entrypoint which allows the devcontainer to attach: so if you have configured a `livenessProbe` that requires the service to have started it should be disabled. The container also installs debugpy and makes the service install editable. Any custom `command` or `args` defined for the container should be disabled.
3+
The container build also publishes a debug container for each tagged release of the container with the tag suffixed with `-debug`. This container contains the workspace and has an alternative entrypoint which allows the devcontainer to attach: if you have configured a `livenessProbe` that requires the service to have started it should be disabled. The container also installs debugpy and makes the service install editable. Any custom `command` or `args` defined for the container should be disabled.
44

5-
With the [Kubernetes plugin for vscode](https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools) it is then possible to attach to the container inside the cluster. This may require that the kubeconfig is at `~/.kube/config`, rather than referenced from the environment variable `KUBECONFIG`. It may also be necessary to [add additional contextual information](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_config/kubectl_config_set-context/), such as the namespace in use.
5+
With the [Kubernetes plugin for vscode](https://marketplace.visualstudio.com/items?itemName=ms-kubernetes-tools.vscode-kubernetes-tools) it is then possible to attach to the container inside the cluster. This may require that your targeted kubeconfig is at `~/.kube/config`, rather than referenced from the environment variable `KUBECONFIG`. It may also be necessary to [add additional contextual information](https://kubernetes.io/docs/reference/kubectl/generated/kubectl_config/kubectl_config_set-context/), such as the namespace.
66

7-
![Location of the Kubernetes plugin in the plugin bar (screen left), with the Clusters>cluster>Workloads>Pods views expanded out to show a pod named "my-service", overlaid with a dropdown box, with the "Attach Visual Studio Code" highlighted](../images/debugging-kubernetes.jpg)
8-
The Kubernetes plugin can be found in the plugin bar. Expanding the Clusters>`cluster`>Workloads>Pods views, your service should be visible. Right Click>Attach Visual Studio Code will initiate connecting to the workspace in the cluster. Select your service container from the top menu.
7+
![Location of the Kubernetes plugin in the plugin bar (screen left), with the Clusters>cluster>Workloads>Pods views expanded out to show a pod named "my-service", overlaid with a dropdown box, with "Attach Visual Studio Code" highlighted](../images/debugging-kubernetes.jpg)
8+
The Kubernetes plugin can be found in the plugin bar. Expanding the Clusters>`cluster`>Workloads>Pods views, your service should be visible. Right Click>Attach Visual Studio Code will initiate connecting to the workspace in the cluster. Select your service container from the top menu when prompted.
99

10-
After the connection to the cluster has been established, it may be necessary to open the workspace folder by clicking the Explorer option in the plugin bar, it should be mounted at `/workspaces/<service name>`, equivalent to a local devcontainer.
10+
After the connection to the cluster has been established, it may be necessary to open the workspace folder by clicking the Explorer option in the plugin bar, the repository will be mounted at `/workspaces/<service name>`, equivalent to when working with a local devcontainer.
1111

12-
Starting your service with the command usually executed by the container definition starts it on the node, with access to kubernetes resources as usual, however it's also now possible to attach a debugger, configured to autoReload code, or to start and stop the service rapidly to implement prospective changes.
12+
Starting your service with the command in the container definition starts it on the node, with access to Kubernetes resources, however it is also now possible to run with or attach a debugger, potentially configured to autoReload code, or to start and stop the service rapidly to implement prospective changes.
1313

14-
After you are happy with the changes, commit them and release a new version of your container. Changes will otherwise not be persisted across container restarts! Your git configuration should be mounted inside the container.
14+
After you are happy with the changes, commit them and release a new version of your container. Changes will otherwise not be persisted across container restarts. Your git and ssh config will be mounted inside the devcontainer while connected and for containers on github, the remote `origin` will be configured to use ssh.
1515

1616
## Debugging containers that run as non-root
17-
For containers running in the Diamond Kubernetes infrastructure that run as a specific uid (e.g. if mounting the filesystem), it is required to use a sidecar container to provide name resolution with Diamond's LDAP infrastructure and to mount a home directory to download vscode plugins.
17+
For containers running in the Diamond Kubernetes infrastructure that run as a specific uid (e.g. if mounting the filesystem), it is required to use a sidecar container to provide name resolution from Diamond's LDAP infrastructure and to mount a home directory to house vscode plugins.
1818

1919
A sidecar for the Debian-based Python image this template uses is published as a container from this repository, the version should match the version of the python-copier-template you are using, to ensure compatibility with the underlying container infrastructure.
2020

2121
```yaml
2222
- name: debug-account-sync
23-
image: ghcr.io/diamondlightsource/python-copier-template/account-sync:<version>
24-
volumeMounts:
25-
# This allows the nslcd socket to be shared between the main container and the sidecar
26-
- mountPath: /var/run/nslcd
23+
image: ghcr.io/diamondlightsource/python-copier-template/account-sync:<version>
24+
volumeMounts:
25+
# The nslcd socket will be shared between the service and the sidecar
26+
- mountPath: /var/run/nslcd
2727
name: nslcd
2828
```
2929
30-
The following changes/additions to your `values.yaml` will be required to connect vscode when using the sidecar.
30+
The following changes/additions to your `values.yaml` may be required to connect vscode when using the sidecar.
31+
It is recommended to set the `HOME` environment variable on your container to be debugged to the same value used in the volume below.
3132

3233
```yaml
3334
volumes:
34-
- name: home # Required for vscode to install plugins
35+
- name: home # Required for vscode to start and install plugins
3536
hostPath:
36-
path: /home/
37+
path: /home/<fedid>
3738
- name: nslcd # Shared volume between main and sidecar container
3839
emptyDir:
3940
sizeLimit: 500Mi
4041
4142
volumeMounts:
42-
- mountPath: /home/
43+
- mountPath: /home/<fedid>
4344
name: home
4445
- mountPath: /var/run/nslcd
4546
name: nslcd
4647
4748
# Disable any liveness probe, as will not start service automatically
48-
livenessProbe:
49+
livenessProbe: null
50+
readinessProbe: null
4951
5052
# Required to mount /home/, /dls/ etc.
5153
podSecurityContext:
52-
runAsUser: <uid>
53-
runAsGroup: <gid>
54+
runAsUser: <uid of fedid>
55+
runAsGroup: <gid of fedid>
5456
5557
image:
5658
tag: "<version>-debug"

template/Dockerfile.jinja

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,28 @@ ENV PATH=/venv/bin:$PATH{% if docker %}
1414

1515
# The build stage installs the context into the venv
1616
FROM developer AS build
17-
COPY --chmod=777 . /workspaces/{{ repo_name }}
17+
# Requires buildkit 0.17.0
18+
COPY --chmod=o+wrX . /workspaces/{{ repo_name }}
1819
WORKDIR /workspaces/{{ repo_name }}
1920
RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .
2021

2122
FROM build AS debug
2223

24+
{% if git_platform=="github.com" %}
25+
# Set origin to use ssh
26+
RUN git remote set-url origin [email protected]:{{github_org}}/{{repo_name}}.git
27+
{% endif %}
28+
29+
# For this pod to understand finding user information from LDAP
2330
RUN apt update
24-
# TODO: Is this required?
2531
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
2632
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
2733

34+
# Make editable and debuggable
2835
RUN pip install debugpy
2936
RUN pip install -e .
3037

38+
# Alternate entrypoint to allow devcontainer to attach
3139
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
3240
CMD [ "while true; do sleep 30; done;" ]
3341

0 commit comments

Comments
 (0)