Skip to content

Commit

Permalink
Merge pull request #38 from DiamondLightSource/container
Browse files Browse the repository at this point in the history
Make deployable in container environment
  • Loading branch information
GDYendell authored Jul 23, 2024
2 parents d2df2aa + 21fa5b3 commit c7b6ff1
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 16 deletions.
13 changes: 9 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# The devcontainer should use the developer target and run as root with podman
# or docker with user namespaces.
ARG PYTHON_VERSION=3.11
FROM python:${PYTHON_VERSION} as developer
FROM python:${PYTHON_VERSION} AS developer

# Add any system dependencies for the developer/build environment here
RUN apt-get update && apt-get install -y --no-install-recommends \
Expand All @@ -13,17 +13,22 @@ RUN python -m venv /venv
ENV PATH=/venv/bin:$PATH

# The build stage installs the context into the venv
FROM developer as build
FROM developer AS build
COPY . /context
WORKDIR /context
RUN pip install .
RUN pip install --upgrade pip && pip install .

# The runtime stage copies the built venv into a slim runtime container
FROM python:${PYTHON_VERSION}-slim as runtime
FROM python:${PYTHON_VERSION}-slim AS runtime
# Add apt-get system dependecies for runtime here if needed
COPY --from=build /venv/ /venv/
ENV PATH=/venv/bin:$PATH

# Make directory to run inside and generate bob files
RUN mkdir -p /epics/opi

WORKDIR /epics/opi

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["eiger-fastcs"]
CMD ["--version"]
20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@
[![PyPI](https://img.shields.io/pypi/v/eiger-fastcs.svg)](https://pypi.org/project/eiger-fastcs)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)

# eiger_fastcs
# Eiger FastCS

Eiger control system integration with FastCS
Control system integration for Dectris Eiger detectors using FastCS.

## Quickstart

1. Run eiger-detector development environment with data writers and simulated detector

i. `podman run --rm -it -v /dev/shm:/dev/shm -v /tmp:/tmp --net=host ghcr.io/dls-controls/eiger-detector-runtime:latest`

2. Run the IOC against the simulated detector, either from a local checkout

i. `eiger-fastcs ioc EIGER` (or run `Eiger IOC` vscode launch config)

3. or the container

i. Make a local directory for UIs `mkdir /tmp/opi`

ii. `podman run --rm -it -v /tmp/opi:/epics/opi --net=host ghcr.io/DiamondLightSource/eiger-fastcs:latest`

Source | <https://github.com/DiamondLightSource/eiger-fastcs>
:---: | :---:
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ classifiers = [
description = "Eiger control system integration with FastCS"
dependencies = [
"aiohttp",
"fastcs>=0.3.0",
"fastcs~=0.4.0",
"numpy",
"pillow",
"typer",
Expand Down Expand Up @@ -44,7 +44,7 @@ dev = [
]

[project.scripts]
eiger-fastcs = "eiger_fastcs.__main__:main"
eiger-fastcs = "eiger_fastcs.__main__:app"

[project.urls]
GitHub = "https://github.com/DiamondLightSource/eiger-fastcs"
Expand Down
31 changes: 23 additions & 8 deletions src/eiger_fastcs/__main__.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from pathlib import Path
from typing import Optional

import typer
from fastcs.backends.asyncio_backend import AsyncioBackend
from fastcs.backends.epics.backend import EpicsBackend
from fastcs.backends.epics.gui import EpicsGUIOptions
from fastcs.mapping import Mapping

from eiger_fastcs import __version__
Expand Down Expand Up @@ -35,26 +37,39 @@ def main(
pass


EigerIp = typer.Option("127.0.0.1", help="IP address of Eiger detector")
EigerPort = typer.Option(8081, help="Port of Eiger HTTP server")

OPI_PATH = Path("/epics/opi")


@app.command()
def ioc(pv_prefix: str = typer.Argument()):
mapping = get_controller_mapping()
def ioc(
pv_prefix: str = typer.Argument(),
ip: str = EigerIp,
port: int = EigerPort,
):
ui_path = OPI_PATH if OPI_PATH.is_dir() else Path.cwd()

mapping = get_controller_mapping(ip, port)

backend = EpicsBackend(mapping, pv_prefix)
backend.create_gui()
backend.create_gui(
EpicsGUIOptions(output_path=ui_path / "eiger.bob", title=f"Eiger - {pv_prefix}")
)
backend.get_ioc().run()


@app.command()
def asyncio():
mapping = get_controller_mapping()
def asyncio(ip: str = EigerIp, port: int = EigerPort):
mapping = get_controller_mapping(ip, port)

backend = AsyncioBackend(mapping)
backend.run_interactive_session()


def get_controller_mapping() -> Mapping:
controller = EigerController("127.0.0.1", 8081)
# controller = EigerController("i03-eiger01", 80)
def get_controller_mapping(ip: str, port: int) -> Mapping:
controller = EigerController(ip, port)

return Mapping(controller)

Expand Down

0 comments on commit c7b6ff1

Please sign in to comment.