Skip to content

Commit

Permalink
Merge pull request #26 from DiamondLightSource/container
Browse files Browse the repository at this point in the history
Container runtime and developer environment
  • Loading branch information
GDYendell authored Oct 21, 2024
2 parents 29672ac + 75c772b commit 86382d1
Show file tree
Hide file tree
Showing 36 changed files with 1,220 additions and 61 deletions.
51 changes: 30 additions & 21 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
// For format details, see https://containers.dev/implementors/json_reference/
{
"name": "Python 3 Developer Container",
"name": "eiger-detector devcontainer",
"build": {
"dockerfile": "../Dockerfile",
"context": "..",
"target": "developer"
},
"remoteEnv": {
// Allow X11 apps to run inside the container
"DISPLAY": "${localEnv:DISPLAY}"
"features": {
// add quality of life features for developers including git config integration
// note this is slow for the odin-data container - leaving out for now
"ghcr.io/devcontainers/features/common-utils:2": {
// don't upgrade to make this similar to the runtime container
"upgradePackages": false
}
},
// IMPORTANT for this devcontainer to work with docker VSCODE_REMOTE_USER must be
// set to vscode. You will run as vscode with full sudo rights.
// For podman it should be left blank. You will run as root but host mounts
// will be owned by your user.
"remoteUser": "${localEnv:VSCODE_REMOTE_USER}",
"customizations": {
"vscode": {
// Set *default* container specific settings.json values on container create.
"settings": {
"python.defaultInterpreterPath": "/venv/bin/python"
},
// Add the IDs of extensions you want installed when the container is created.
"extensions": [
"ms-python.python",
"github.vscode-github-actions",
"ms-python.vscode-pylance",
"tamasfe.even-better-toml",
"redhat.vscode-yaml",
"ryanluker.vscode-coverage-gutters",
"epicsdeb.vscode-epics",
"charliermarsh.ruff",
"ms-azuretools.vscode-docker"
"ms-vscode.cmake-tools",
"ms-vscode.cpptools"
]
}
},
"features": {
// Some default things like git config
"ghcr.io/devcontainers/features/common-utils:2": {
"upgradePackages": false
}
},
// You can place any outside of the container before-launch commands here
"initializeCommand": "bash .devcontainer/initializeCommand ${devcontainerId}",
// One time global setup commands inside the container
"postCreateCommand": "bash .devcontainer/postCreateCommand ${devcontainerId}",
"runArgs": [
// Allow the container to access the host X11 display and EPICS CA
"--net=host",
// Make sure SELinux does not disable with access to host filesystems like tmp
// Make sure SELinux does not disable write access to host filesystems like tmp
"--security-opt=label=disable"
],
// Mount the parent as /workspaces so we can pip install peers as editable
// Mount the parent of the project folder so we can access peer projects
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
// After the container is created, install the python project in editable form
"postCreateCommand": "pip install $([ -f dev-requirements.txt ] && echo '-c dev-requirements.txt') -e './python[dev]' && pre-commit install"
// mount in other useful files from the host
"mounts": [
// add extra mounts below
// "source=${localWorkspaceFolder},target=/odin-data,type=bind"
"source=/dev/shm,target=/dev/shm,type=bind"
]
}
6 changes: 6 additions & 0 deletions .devcontainer/initializeCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/bash

# custom initialization goes here - runs outside of the dev container
# just before the container is launched but after the container is created

echo "devcontainerID ${1}"
28 changes: 28 additions & 0 deletions .devcontainer/postCreateCommand
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/bash

# Custom initialization goes here if needed.
# Runs inside the dev container after the container is created

################################################################################
# When using docker we will not be root inside the container
# You may wish to change ownership of files you want the user to modify
################################################################################

# if [[ $USER != "root" ]] ; then
# # make sure the non-root user can build iocs and (mounted in) support modules
# # sudo chown -R ${USER}:${USER} add_folders_here_if needed
# fi

################################################################################
# Shell customizations for Generic IOC devcontainers
################################################################################

# pick a zsh theme that does not cause completion corruption in zsh vscode terminals
sed -i $HOME/.zshrc -e 's/ZSH_THEME="devcontainers"/ZSH_THEME="dst"/'

# allow personalization of all devcontainers in this subdirectory
# by placing a .devcontainer_rc file in the workspace root
if [[ -f /workspaces/.devcontainer_rc ]] ; then
source /workspaces/.devcontainer_rc
fi

10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.dockerignore

external
*build*
*prefix*
*.pyc
venv*
*.egg-info

docs/build/
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
# Contribute to the project

Contributions and issues are most welcome! All issues and pull requests are
handled through [GitHub](https://github.com/DiamondLightSource/odin-fastcs/issues). Also, please check for any existing issues before
handled through [GitHub](https://github.com/DiamondLightSource/eiger-detector/issues). Also, please check for any existing issues before
filing a new one. If you have a great idea but it involves big changes, please
file a ticket before making a pull request! We want to make sure you don't spend
your time coding something that might not fit the scope of the project.

## Issue or Discussion?

Github also offers [discussions](https://github.com/DiamondLightSource/odin-fastcs/discussions) as a place to ask questions and share ideas. If
Github also offers [discussions](https://github.com/DiamondLightSource/eiger-detector/discussions) as a place to ask questions and share ideas. If
your issue is open ended and it is not obvious when it can be "closed", please
raise it as a discussion instead.

Expand Down
92 changes: 92 additions & 0 deletions .github/workflows/container.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
name: Container CI

on:
push:
pull_request:

jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write

steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0 # All history

- name: Cache Docker layers
uses: actions/cache@v2
with:
path: /tmp/.buildx-cache
key: ${{ runner.os }}-buildx-${{ github.sha }}
restore-keys: |
${{ runner.os }}-buildx-
- name: Log in to GitHub Docker Registry
if: github.event_name != 'pull_request'
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@v1

- name: Build image
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: runtime
push: false
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Create tags for developer image
id: meta-developer
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-developer
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Push developer image
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: developer
tags: ${{ steps.meta-developer.outputs.tags }}
labels: ${{ steps.meta-developer.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache

- name: Create tags for runtime image
id: meta-runtime
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}-runtime
tags: |
type=ref,event=tag
type=raw,value=latest
- name: Push runtime image
if: ${{ github.event_name == 'push' && github.ref_type == 'tag' }}
uses: docker/build-push-action@v4
with:
context: .
file: Dockerfile
target: runtime
tags: ${{ steps.meta-runtime.outputs.tags }}
labels: ${{ steps.meta-runtime.outputs.labels }}
push: ${{ github.event_name != 'pull_request' }}
cache-from: type=local,src=/tmp/.buildx-cache
cache-to: type=local,dest=/tmp/.buildx-cache
9 changes: 9 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"recommendations": [
"ms-vscode-remote.remote-containers",
"ms-vscode.cmake-tools",
"ms-vscode.cpptools",
"ms-python.python",
"ms-python.vscode-pylance",
]
}
93 changes: 93 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Odin Control",
"type": "debugpy",
"request": "launch",
"module": "odin.main",
"justMyCode": false,
"console": "integratedTerminal",
"args": ["--config", "${workspaceFolder}/deploy/odin_server.cfg", "--logging", "info"]
},
{
"name": "Meta Writer",
"type": "debugpy",
"request": "launch",
"module": "odin_data.meta_writer.meta_writer_app",
"justMyCode": false,
"console": "integratedTerminal",
"args": [
"--writer", "eiger_detector.EigerMetaWriter",
"--sensor-shape", "4362", "4148",
"--data-endpoints", "tcp://127.0.0.1:10008,tcp://127.0.0.1:10018,tcp://127.0.0.1:10028,tcp://127.0.0.1:10038"
]
},
{
"name": "Debug Unit Test",
"type": "debugpy",
"request": "launch",
"justMyCode": false,
"program": "${file}",
"purpose": [
"debug-test"
],
"console": "integratedTerminal",
"env": {
// Enable break on exception when debugging tests (see: tests/conftest.py)
"PYTEST_RAISE": "1",
},
},
{
"name": "Eiger Fan",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/vscode_build/bin/eigerfan",
"args": ["--addr", "127.0.0.1", "--consumers", "4", "--sockets", "4", "--blocksize", "1000", "--threads", "2"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
{
"name": "FrameProcessor",
"type": "cppdbg",
"request": "launch",
"program": "/odin/bin/frameProcessor",
"args": ["--ctrl", "tcp://0.0.0.0:10004", "--config", "${workspaceFolder}/deploy/fp1.json"],
"stopAtEntry": false,
"cwd": "${fileDirname}",
"environment": [{"name": "HDF5_PLUGIN_PATH", "value": "/odin/h5plugin"}],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true
}
]
},
],
}
21 changes: 21 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"cmake.generator": "Unix Makefiles",
"cmake.sourceDirectory": "${workspaceFolder}/cpp",
"cmake.buildDirectory": "${workspaceFolder}/vscode_build",
"cmake.installPrefix": "/odin",
"cmake.configureArgs": [
"-DODINDATA_ROOT_DIR=/odin"
],
"cmake.buildArgs": ["VERBOSE=1"],
"C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools",
"editor.formatOnSave": true,
"[python]": {
"editor.codeActionsOnSave": {
"source.organizeImports": "explicit"
},
"editor.defaultFormatter": "charliermarsh.ruff",
"editor.rulers": [
88
]
},
}
Loading

0 comments on commit 86382d1

Please sign in to comment.