Skip to content
This repository has been archived by the owner on Sep 2, 2024. It is now read-only.

Commit

Permalink
Fix healtcheck
Browse files Browse the repository at this point in the history
Add editable dodal to image and helmcharts
Allow the appversion to be specified at deployment
Allow existing helmcharts to be upgraded
  • Loading branch information
rtuck99 committed Aug 15, 2024
1 parent baf4fa3 commit a00d840
Show file tree
Hide file tree
Showing 8 changed files with 90 additions and 42 deletions.
14 changes: 10 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
FROM python:3.11 AS build
ADD . /project/
WORKDIR "/project"
ADD . /app/hyperion
WORKDIR "/app/hyperion"
RUN pip install -e .[dev]
RUN python -m build

ENTRYPOINT /project/utility_scripts/docker/entrypoint.sh
# Check out and install dodal locally with no dependencies as this may be a different version to what
# is referred to in the setup.cfg, but we don't care as it will be overridden by bind mounts in the
# running container
RUN mkdir ../dodal && \
git clone https://github.com/DiamondLightSource/dodal.git ../dodal && \
pip install --no-deps -e ../dodal

ENTRYPOINT /app/hyperion/utility_scripts/docker/entrypoint.sh

EXPOSE 5005
24 changes: 13 additions & 11 deletions docs/deploying.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,26 +62,28 @@ Once the docker image is built, the image can be deployed to kubernetes using th
* From a development hyperion workspace
```commandline
python utility_scripts/deploy/deploy_hyperion.py --kubernetes <beamline>
cd <path to deployed hyperion folder in /dls_sw>
./utility_scripts/deploy/deploy_to_k8s.sh --beamline=<beamline> hyperion
```

* cd to the new folder and run
```commandline
git checkout vX.Y.Z
./utility_scripts/deploy/deploy_to_k8s.sh hyperion
```

This will create a helm release "hyperion".
This will create a helm release "hyperion". The source folders will be mounted as
bind mounts to allow the pod to pick up changes in production. For production these are expected to be in the normal
place defined in `values.yaml`.

### development deployment

From your development workspace, either with a release image or using a development image built with :

From a development `hyperion` workspace, either with a release image or using a development image built with the script
above, you install a dev deployment to the cluster you are currently logged into with `kubectl`:

```commandline
./utility_scripts/deploy/deploy_to_k8s.sh --dev --beamline=<beamline> --repository=<your image repo> hyperion-test
```

Please note, the deployment is intended to be run from a checked-out matching version of the git repository. For
production this is expected to be in the normal place defined in `values.yaml`. The source folders will be mounted as
bind mounts to allow the pod to pick up changes in production.
The dev deployment bind-mounts the current `hyperion` workspace and `../dodal` into the container so that you can
run against your own development code. **Clusters do not allow bind mounts from arbitrary directories so
your workspace will have to be in a permitted directory such as your home directory.**

Please note, the deployment script is intended to be run from a checked-out matching version of the git repository.

`helm list` should then show details of the installed release
16 changes: 11 additions & 5 deletions helmchart/templates/deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ spec:
hostPath:
path: "{{ .Values.hyperion.projectDir }}/utility_scripts"
type: Directory
- name: dodal
hostPath:
path: "{{ .Values.dodal.projectDir | clean }}"
type: Directory
{{- if .Values.hyperion.dev }}
- name: devlogs
hostPath:
Expand Down Expand Up @@ -78,7 +82,7 @@ spec:
{{- end }}
readinessProbe:
exec:
command: [ "/project/docker/healthcheck.sh" ]
command: [ "/app/hyperion/utility_scripts/docker/healthcheck.sh" ]
periodSeconds: 5
volumeMounts:
- mountPath: "/dls_sw/{{ .Values.hyperion.beamline }}"
Expand All @@ -93,13 +97,15 @@ spec:
name: dls-sw-dasc
readOnly: true
mountPropagation: HostToContainer
- mountPath: "/project/src"
- mountPath: "/app/hyperion/src"
name: src
- mountPath: "/project/tests"
- mountPath: "/app/hyperion/tests"
name: tests
- mountPath: "/project/utility_scripts"
- mountPath: "/app/hyperion/utility_scripts"
name: utility-scripts
- mountPath: "/app/dodal"
name: dodal
{{- if .Values.hyperion.dev }}
- mountPath: "/project/tmp"
- mountPath: "/app/hyperion/tmp"
name: devlogs
{{ end }}
6 changes: 4 additions & 2 deletions helmchart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@ hyperion:
beamline: i03
dev: false
logDir: "/dls_sw/i03/logs/bluesky"
projectDir: "/dls_sw/i03/software/bluesky/hyperion"
# This should be overridden at install time
# These should be overridden at install time
projectDir: SET_ON_INSTALL
appVersion: SET_ON_INSTALL
dodal:
projectDir: SET_ON_INSTALL
service:
type: NodePort
1 change: 1 addition & 0 deletions utility_scripts/build_docker_image.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/bin/bash
set -e
# builds the docker image
BUILD=1
PUSH=1
Expand Down
60 changes: 41 additions & 19 deletions utility_scripts/deploy/deploy_to_k8s.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ for option in "$@"; do
REPOSITORY="${option#*=}"
shift
;;
--appVersion=*)
APP_VERSION="${option#*=}"
shift
;;
--help|--info|--h)
CMD=`basename $0`
echo "$CMD [options] <release>"
Expand All @@ -22,6 +26,8 @@ for option in "$@"; do
echo " --dev Install to a development kubernetes cluster (assumes project checked out under /home)"
echo " -b, --beamline=BEAMLINE Overrides the BEAMLINE environment variable with the given beamline"
echo " --repository=REPOSITORY Override the repository to fetch the image from"
echo " --appVersion=version Version of the image to fetch from the repository otherwise it is deduced
from the setuptools_scm"
exit 0
;;
-*|--*)
Expand All @@ -46,10 +52,34 @@ fi
HELM_OPTIONS=""
PROJECTDIR=$(readlink -e $(dirname $0)/../..)

ensure_version_py() {
# We require the _version.py to be created, this needs a minimal virtual environment
if [[ ! -d $PROJECTDIR/.venv ]]; then
echo "Creating _version.py"
echo "Virtual environment not found - creating"
module load python/3.11
python -m venv $PROJECTDIR/.venv
. $PROJECTDIR/.venv/bin/activate
pip install setuptools_scm
fi
}

app_version() {
ensure_version_py

. $PROJECTDIR/.venv/bin/activate
python -m setuptools_scm --force-write-version-files
}

if [[ -n $REPOSITORY ]]; then
HELM_OPTIONS+="--set hyperion.imageRepository=$REPOSITORY "
fi

ensure_version_py
if [[ -z $APP_VERSION ]]; then
APP_VERSION=$(app_version)
fi

if [[ -n $DEV ]]; then
GID=`id -g`
SUPPLEMENTAL_GIDS=37904
Expand All @@ -58,25 +88,17 @@ hyperion.dev=true,\
hyperion.runAsUser=$EUID,\
hyperion.runAsGroup=$GID,\
hyperion.supplementalGroups=[$SUPPLEMENTAL_GIDS],\
hyperion.logDir=/project/tmp,\
hyperion.projectDir=$PROJECTDIR \
--replace "
hyperion.logDir=/app/hyperion/tmp "
mkdir -p $PROJECTDIR/tmp
elif [[ ! -e $PROJECTDIR/src/hyperion/_version.py ]]; then
# Production install requires the _version.py to be created, this needs a minimal virtual environment
echo "Creating _version.py"
if [[ -d $PROJECTDIR/.venv/bin/activate ]]; then
echo "Virtual environment not found - creating"
module load python/3.11
python -m venv $PROJECTDIR/.venv
. $PROJECTDIR/.venv/bin/activate
pip install setuptools_scm
else
. $PROJECTDIR/.venv/bin/activate
fi
python -m setuptools_scm --force-write-version-files
DEPLOYMENT_DIR=$PROJECTDIR
else
DEPLOYMENT_DIR=/dls_sw/i03/software/bluesky/hyperion_v${APP_VERSION}/hyperion
fi
APP_VERSION=`python -m setuptools_scm | sed -e 's/[^a-zA-Z0-9._-]/_/g'`
HELM_OPTIONS+="--set hyperion.appVersion=$APP_VERSION "

HELM_OPTIONS+="--set hyperion.appVersion=$APP_VERSION,\
hyperion.projectDir=$DEPLOYMENT_DIR,\
dodal.projectDir=$DEPLOYMENT_DIR/../dodal "

helm package $PROJECTDIR/helmchart --app-version $APP_VERSION
helm install $HELM_OPTIONS $RELEASE hyperion-0.0.1.tgz
# Helm package generates a file suffixed with the chart version
helm upgrade --install $HELM_OPTIONS $RELEASE hyperion-0.0.1.tgz
11 changes: 10 additions & 1 deletion utility_scripts/docker/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/bash -x
#!/bin/bash
# Entry point for the production docker image that launches the external callbacks
# as well as the main server

Expand Down Expand Up @@ -29,6 +29,13 @@ for option in "$@"; do
esac
done

kill_active_apps () {
echo "Killing active instances of hyperion and hyperion-callbacks..."
pkill -e -f "python.*hyperion"
pkill -e -f "SCREEN.*hyperion"
echo "done."
}

RELATIVE_SCRIPT_DIR=$( dirname -- "$0"; )
cd ${RELATIVE_SCRIPT_DIR}

Expand Down Expand Up @@ -64,6 +71,8 @@ do
fi;
done

trap kill_active_apps TERM

if [ "$EXTERNAL_CALLBACK_SERVICE" = true ]; then
hyperion-callbacks `echo $cb_commands;`>$callback_start_log_path 2>&1 &
fi
Expand Down
Empty file modified utility_scripts/docker/healthcheck.sh
100644 → 100755
Empty file.

0 comments on commit a00d840

Please sign in to comment.