Skip to content

Commit

Permalink
Move scratch management to bash script (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
callumforrester authored Oct 25, 2023
1 parent d80eca0 commit 1f9dadf
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 290 deletions.
3 changes: 2 additions & 1 deletion .devcontainer/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ FROM python:3.11 as runtime

# copy the virtual environment from the build stage and put it in PATH
COPY --from=build /venv/ /venv/
COPY ./container-startup.sh /container-startup.sh
ENV PATH=/venv/bin:$PATH


RUN mkdir -p /.cache/pip; chmod -R 777 /venv /.cache/pip

# change this entrypoint if it is not the same as the repo
ENTRYPOINT ["blueapi"]
ENTRYPOINT ["/container-startup.sh"]
CMD ["serve"]
16 changes: 16 additions & 0 deletions .devcontainer/container-startup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env bash

SCRATCH_AREA="/blueapi-plugins/scratch"

mkdir -p ${SCRATCH_AREA}

DIRS=`ls -1 ${SCRATCH_AREA}`

echo "Loading Python packages from from ${DIRS}"

for DIR in ${DIRS}
do
python -m pip install --no-deps -e "${SCRATCH_AREA}/${DIR}"
done

blueapi $@
3 changes: 1 addition & 2 deletions helm/blueapi/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ spec:
readOnly: true
{{- if .Values.scratch.hostPath }}
- name: scratch-host
mountPath: {{ .Values.worker.env.scratch.path }}
mountPath: {{ .Values.scratch.containerPath }}
mountPropagation: HostToContainer
{{- end }}
command: ["blueapi"]
args:
- "-c"
- "/config/config.yaml"
Expand Down
15 changes: 8 additions & 7 deletions helm/blueapi/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ affinity: {}
#existingSecret: see templates/secret.yaml

scratch:
{}
# hostPath: /usr/local/blueapi-software-scratch
hostPath: "" # example: /usr/local/blueapi-software-scratch
containerPath: /blueapi-plugins/scratch

worker:
api:
Expand All @@ -79,12 +79,13 @@ worker:
env:
sources:
- kind: deviceFunctions
module: blueapi.startup.example
module: blueapi.startup.example_devices
- kind: planFunctions
module: blueapi.startup.example_plans
- kind: planFunctions
module: dls_bluesky_core.plans
- kind: planFunctions
module: blueapi.plans
scratch:
path: /blueapi-plugins/scratch
auto_make_directory: true
module: dls_bluesky_core.stubs
stomp:
auth:
username: guest
Expand Down
10 changes: 0 additions & 10 deletions src/blueapi/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,6 @@ class StompConfig(BaseModel):
auth: Optional[BasicAuthentication] = None


class ScratchConfig(BlueapiBaseModel):
"""
Config for the scratch space where editable Python packages can be installed
"""

path: Path = Field(default=Path("/tmp/blueapi/scratch"))
auto_make_directory: bool = Field(default=False)


class DataWritingConfig(BlueapiBaseModel):
visit_service_url: Optional[str] = None # e.g. "http://localhost:8088/api"
visit_directory: Path = Path("/tmp/0-0")
Expand All @@ -68,7 +59,6 @@ class EnvironmentConfig(BlueapiBaseModel):
Source(kind=SourceKind.PLAN_FUNCTIONS, module="dls_bluesky_core.plans"),
Source(kind=SourceKind.PLAN_FUNCTIONS, module="dls_bluesky_core.stubs"),
]
scratch: Optional[ScratchConfig] = Field(default=None)
data_writing: DataWritingConfig = Field(default_factory=DataWritingConfig)


Expand Down
5 changes: 0 additions & 5 deletions src/blueapi/service/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from super_state_machine.errors import TransitionError

from blueapi.config import ApplicationConfig
from blueapi.service.scratch import ScratchManager
from blueapi.worker import RunPlan, TrackableTask, WorkerState

from .handler import Handler, get_handler, setup_handler, teardown_handler
Expand Down Expand Up @@ -236,10 +235,6 @@ def set_state(
def start(config: ApplicationConfig):
import uvicorn

if config.env.scratch is not None:
scratch = ScratchManager.from_config(config.env.scratch)
scratch.sync_packages()

app.state.config = config
uvicorn.run(app, host=config.api.host, port=config.api.port)

Expand Down
116 changes: 0 additions & 116 deletions src/blueapi/service/scratch.py

This file was deleted.

149 changes: 0 additions & 149 deletions tests/service/test_scratch.py

This file was deleted.

0 comments on commit 1f9dadf

Please sign in to comment.