Skip to content

Commit be152c1

Browse files
author
Ware, Joseph (DLSLtd,RAL,LSCI)
committed
Publish debug container image and account-sync sidecar
1 parent 002a1c5 commit be152c1

File tree

8 files changed

+145
-0
lines changed

8 files changed

+145
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
on:
2+
workflow_call:
3+
4+
jobs:
5+
build:
6+
runs-on: ubuntu-latest
7+
8+
steps:
9+
- name: Checkout
10+
uses: actions/checkout@v4
11+
with:
12+
# Need this to get version number from last tag
13+
fetch-depth: 0
14+
15+
- name: Set up Docker Buildx
16+
id: buildx
17+
uses: docker/setup-buildx-action@v3
18+
19+
- name: Log in to GitHub Docker Registry
20+
if: github.event_name != 'pull_request'
21+
uses: docker/login-action@v3
22+
with:
23+
registry: ghcr.io
24+
username: ${{ github.actor }}
25+
password: ${{ secrets.GITHUB_TOKEN }}
26+
27+
- name: Create tags for publishing image
28+
id: meta
29+
uses: docker/metadata-action@v5
30+
with:
31+
images: ghcr.io/${{ github.repository }}/account-sync
32+
tags: |
33+
type=ref,event=tag
34+
type=raw,value=latest
35+
36+
- name: Build and publish debug image to container registry
37+
if: github.ref_type == 'tag'
38+
uses: docker/build-push-action@v6
39+
env:
40+
DOCKER_BUILD_RECORD_UPLOAD: false
41+
with:
42+
context: account-sync
43+
push: true
44+
tags: ${{ steps.debug-meta.outputs.tags }}

.github/workflows/_container.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,26 @@ jobs:
4646
type=ref,event=tag
4747
type=raw,value=latest
4848
49+
- name: Create tags for publishing debug image
50+
id: debug-meta
51+
uses: docker/metadata-action@v5
52+
with:
53+
images: ghcr.io/${{ github.repository }}
54+
tags: |
55+
type=ref,event=tag,suffix=-debug
56+
type=raw,value=latest-debug
57+
58+
- name: Build and publish debug image to container registry
59+
if: github.ref_type == 'tag'
60+
uses: docker/build-push-action@v6
61+
env:
62+
DOCKER_BUILD_RECORD_UPLOAD: false
63+
with:
64+
context: .
65+
push: true
66+
target: debug
67+
tags: ${{ steps.debug-meta.outputs.tags }}
68+
4969
- name: Push cached image to container registry
5070
if: github.ref_type == 'tag'
5171
uses: docker/build-push-action@v6

.github/workflows/ci.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,10 @@ jobs:
4545
uses: ./.github/workflows/_release.yml
4646
permissions:
4747
contents: write
48+
49+
release-account-sync:
50+
if: github.ref_type == 'tag'
51+
needs: release
52+
uses: ./.github/workflows/_account_sync.yml
53+
permissions:
54+
contents: write

account-sync/Dockerfile

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
ARG PYTHON_VERSION=3.11
2+
# Use same base image as debug to prevent incompatibilities
3+
FROM python:${PYTHON_VERSION}-slim
4+
5+
RUN apt update
6+
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
7+
COPY dls-nslcd.conf /etc/nslcd.conf
8+
9+
ENTRYPOINT [ "nslcd" ]
10+
CMD [ "--debug" ]

account-sync/dls-nslcd.conf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
URI ldap://ldap.diamond.ac.uk ldap://ldap2.diamond.ac.uk
2+
TIMELIMIT 30
3+
base dc=diamond,dc=ac,dc=uk
4+
tls_reqcert allow

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

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Debug a container within a cluster
2+
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.
4+
5+
With the Kubernetes plugin for vscode 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`.
6+
7+
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.
8+
9+
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.
10+
11+
```yaml
12+
- name: debug-account-sync
13+
image: ghcr.io/diamondlightsource/python-copier-template/account-sync:<version>
14+
volumeMounts:
15+
# This allows the nslcd socket to be shared between the main container and the sidecar
16+
- mountPath: /var/run/nslcd
17+
name: nslcd
18+
```
19+
20+
The following changes/additions to your `values.yaml` will be required to connect vscode when using the sidecar.
21+
22+
```yaml
23+
volumes:
24+
- name: home # Required for vscode to install plugins
25+
hostPath:
26+
path: /home/
27+
- name: nslcd # Shared volume between main and sidecar container
28+
emptyDir:
29+
sizeLimit: 500Mi
30+
31+
volumeMounts:
32+
- mountPath: /home/
33+
name: home
34+
- mountPath: /var/run/nslcd
35+
name: nslcd
36+
37+
# Disable any liveness probe, as will not start service automatically
38+
livenessProbe:
39+
40+
# Required to mount /home/, /dls/ etc.
41+
podSecurityContext:
42+
runAsUser: <uid>
43+
runAsGroup: <gid>
44+
45+
image:
46+
tag: "<version>-debug"
47+
```
53.8 KB
Loading

template/Dockerfile.jinja

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,19 @@ COPY . /context
1818
WORKDIR /context
1919
RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .
2020

21+
FROM build AS debug
22+
23+
RUN apt update
24+
# TODO: Is this required?
25+
RUN DEBIAN_FRONTEND=noninteractive apt install libnss-ldapd -y
26+
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
27+
28+
RUN pip install debugpy
29+
RUN pip install -e .
30+
31+
ENTRYPOINT [ "/bin/bash", "-c", "--" ]
32+
CMD [ "while true; do sleep 30; done;" ]
33+
2134
# The runtime stage copies the built venv into a slim runtime container
2235
FROM python:${PYTHON_VERSION}-slim AS runtime
2336
# Add apt-get system dependecies for runtime here if needed

0 commit comments

Comments
 (0)