Skip to content

Commit 40de4f0

Browse files
authored
Merge pull request #5 from DiamondLightSource/dev-in-cluster
Dev in cluster
2 parents 660f717 + 2e8def5 commit 40de4f0

File tree

8 files changed

+178
-8
lines changed

8 files changed

+178
-8
lines changed

.copier-answers.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Changes here will be overwritten by Copier
2-
_commit: 4.1.0
2+
_commit: 4.2.0
33
_src_path: https://github.com/diamondlightsource/python-copier-template
44
author_email: [email protected]
55
author_name: Giles Knap
@@ -9,7 +9,7 @@ component_type: service
99
description: An example simulation IOC for testing fastCS
1010
distribution_name: fastcs-example
1111
docker: true
12-
docker_debug: false
12+
docker_debug: true
1313
docs_type: README
1414
git_platform: github.com
1515
github_org: DiamondLightSource

.github/CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,4 @@ It is recommended that developers use a [vscode devcontainer](https://code.visua
2424

2525
This project was created using the [Diamond Light Source Copier Template](https://github.com/DiamondLightSource/python-copier-template) for Python projects.
2626

27-
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.1.0/how-to.html).
27+
For more information on common tasks like setting up a developer environment, running the tests, and setting a pre-commit hook, see the template's [How-to guides](https://diamondlightsource.github.io/python-copier-template/4.2.0/how-to.html).
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
on:
2+
workflow_call:
3+
inputs:
4+
publish:
5+
type: boolean
6+
description: If true, pushes image to container registry
7+
8+
jobs:
9+
build:
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- name: Checkout
14+
uses: actions/checkout@v4
15+
with:
16+
# Need this to get version number from last tag
17+
fetch-depth: 0
18+
19+
- name: Set up Docker Buildx
20+
id: buildx
21+
uses: docker/setup-buildx-action@v3
22+
23+
- name: Log in to GitHub Docker Registry
24+
if: github.event_name != 'pull_request'
25+
uses: docker/login-action@v3
26+
with:
27+
registry: ghcr.io
28+
username: ${{ github.actor }}
29+
password: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Create tags for publishing debug image
32+
id: debug-meta
33+
uses: docker/metadata-action@v5
34+
with:
35+
images: ghcr.io/${{ github.repository }}-debug
36+
tags: |
37+
type=ref,event=tag
38+
type=raw,value=latest
39+
40+
- name: Build and publish debug image to container registry
41+
if: github.ref_type == 'tag'
42+
uses: docker/build-push-action@v6
43+
env:
44+
DOCKER_BUILD_RECORD_UPLOAD: false
45+
with:
46+
context: .
47+
push: true
48+
target: debug
49+
tags: ${{ steps.debug-meta.outputs.tags }}

.github/workflows/ci.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ jobs:
4242
contents: read
4343
packages: write
4444

45+
debug_container:
46+
needs: [container, test]
47+
uses: ./.github/workflows/_debug_container.yml
48+
with:
49+
publish: ${{ needs.test.result == 'success' }}
50+
permissions:
51+
contents: read
52+
packages: write
53+
4554
dist:
4655
uses: ./.github/workflows/_dist.yml
4756

.vscode/launch.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@
44
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
55
"version": "0.2.0",
66
"configurations": [
7+
{
8+
"name": "Python Debugger: Remote Attach",
9+
"type": "debugpy",
10+
"request": "attach",
11+
"connect": {
12+
"host": "localhost",
13+
"port": 5678
14+
},
15+
"pathMappings": [
16+
{
17+
"localRoot": "${workspaceFolder}",
18+
"remoteRoot": "."
19+
}
20+
],
21+
"justMyCode": false
22+
},
723
{
824
"name": "Debug Unit Test",
925
"type": "debugpy",

DEBUGGING.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Developing in Cluster
2+
3+
e.g. fastcs-example
4+
5+
# Deploy the develop mode chart
6+
7+
First deploy the developer mode helm chart:
8+
- checkout a branch 'develop'
9+
- Switch the container to develop mode with developMode: true
10+
- push the change
11+
- ec deploy bl47p-ea-fastcs-01 develop
12+
13+
This will deploy the container running sleep and with a new PVC called bl47p-ea-fastcs-01-develop, containing:
14+
- /workspaces mounted at /workspaces in the container
15+
- /venv mounted at /venv in the container
16+
- both mounts above will have the original container contents copied in by an init-container
17+
18+
19+
# Get the process started with debugpy
20+
21+
Exec this in the container
22+
23+
```bash
24+
python -Xfrozen_modules=off -m debugpy --listen 0.0.0.0:5678 --wait-for-client --configure-subProcess true -m fastcs_example run /epics/ioc/config/controller.yaml
25+
```
26+
27+
Port forward the debug port on your workstation
28+
29+
```bash
30+
k port-forward -n p47-beamline bl47p-ea-fastcs-01-0 5678
31+
```
32+
33+
# Get VSCode connected
34+
35+
mount the ...-develop PVC on your workstation and open it with vscode
36+
37+
```bash
38+
pv-mounter mount p47-beamline bl47p-ea-fastcs-01-develop ./debugger
39+
code debugger/workspaces/fastcs-example
40+
```
41+
42+
Launch remote debugging with a launcher configuration like this:
43+
```json
44+
{
45+
"name": "Python Debugger: Remote Attach",
46+
"type": "debugpy",
47+
"request": "attach",
48+
"connect": {
49+
"host": "localhost",
50+
"port": 5678
51+
},
52+
"pathMappings": [
53+
{
54+
"localRoot": "${workspaceFolder}",
55+
"remoteRoot": "."
56+
}
57+
],
58+
"justMyCode": false
59+
},
60+
```

Dockerfile

Lines changed: 40 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,63 @@
11
# The devcontainer should use the developer target and run as root with podman
22
# or docker with user namespaces.
33
ARG PYTHON_VERSION=3.11
4+
5+
# The developer is used by devcontainers ###############################################
46
FROM python:${PYTHON_VERSION} AS developer
57

68
# Add any system dependencies for the developer/build environment here
79
RUN apt-get update && apt-get install -y --no-install-recommends \
10+
gdb \
11+
busybox \
812
graphviz \
9-
&& rm -rf /var/lib/apt/lists/*
13+
&& rm -rf /var/lib/apt/lists/* \
14+
&& busybox --install -s
1015

1116
# Set up a virtual environment and put it in PATH
1217
RUN python -m venv /venv
1318
ENV PATH=/venv/bin:$PATH
1419

15-
# The build stage installs the context into the venv
20+
# The build stage installs the context into the venv ###################################
1621
FROM developer AS build
22+
1723
# Requires buildkit 0.17.0
1824
COPY --chmod=o+wrX . /workspaces/fastcs-example
1925
WORKDIR /workspaces/fastcs-example
20-
RUN touch dev-requirements.txt && pip install -c dev-requirements.txt .[demo]
26+
RUN touch dev-requirements.txt && pip install stdio-socket>=1.3.1 debugpy \
27+
-c dev-requirements.txt .[demo]
28+
29+
# The debug stage allows for debugging and development #################################
30+
FROM build AS debug
31+
32+
# Set origin to use ssh
33+
RUN git remote set-url origin [email protected]:DiamondLightSource/fastcs-example.git
34+
35+
# Make editable and debuggable
36+
RUN pip install debugpy -e '.[dev]'
37+
RUN chmod o+wrX /venv /workspaces
2138

39+
RUN apt-get update && \
40+
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends \
41+
busybox \
42+
gdb \
43+
libnss-ldapd \
44+
&& rm -rf /var/lib/apt/lists/* \
45+
&& busybox --install -s
2246

23-
# The runtime stage copies the built venv into a slim runtime container
47+
# For this pod to understand finding user information from LDAP
48+
RUN sed -i 's/files/ldap files/g' /etc/nsswitch.conf
49+
50+
# Alternate entrypoint to allow restarting the IOC
51+
ENTRYPOINT [ "/bin/bash", "-c", "sleep infinity" ]
52+
53+
# The runtime stage has built venv only ################################################
2454
FROM python:${PYTHON_VERSION}-slim AS runtime
25-
# Add apt-get system dependecies for runtime here if needed
55+
56+
# Add apt-get system dependecies for runtime
57+
RUN apt-get update && apt-get install -y --no-install-recommends \
58+
gdb \
59+
&& rm -rf /var/lib/apt/lists/*
60+
2661
COPY --from=build /venv/ /venv/
2762
ENV PATH=/venv/bin:$PATH
2863

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ lint.select = [
100100
"C4", # flake8-comprehensions - https://docs.astral.sh/ruff/rules/#flake8-comprehensions-c4
101101
"E", # pycodestyle errors - https://docs.astral.sh/ruff/rules/#error-e
102102
"F", # pyflakes rules - https://docs.astral.sh/ruff/rules/#pyflakes-f
103+
"N", # pep8-naming - https://docs.astral.sh/ruff/rules/#pep8-naming-n
103104
"W", # pycodestyle warnings - https://docs.astral.sh/ruff/rules/#warning-w
104105
"I", # isort - https://docs.astral.sh/ruff/rules/#isort-i
105106
"UP", # pyupgrade - https://docs.astral.sh/ruff/rules/#pyupgrade-up

0 commit comments

Comments
 (0)