diff --git a/.github/workflows/imswitch-docker-multiarch-noqt.yaml b/.github/workflows/imswitch-docker-multiarch-noqt.yaml index 85bb66bd..8ad0a647 100644 --- a/.github/workflows/imswitch-docker-multiarch-noqt.yaml +++ b/.github/workflows/imswitch-docker-multiarch-noqt.yaml @@ -49,7 +49,7 @@ jobs: - name: Build and push container image to registry uses: docker/build-push-action@v2 with: - context: docker + context: docker/HIK file: docker/HIK/dockerfile push: true platforms: linux/amd64,linux/arm64 diff --git a/docker/HIK/dockerfile b/docker/HIK/dockerfile index 38b78dd4..2a6287ba 100644 --- a/docker/HIK/dockerfile +++ b/docker/HIK/dockerfile @@ -182,85 +182,6 @@ RUN cd /tmp/UC2-REST && \ # Expose FTP, SSH port and HTTP port EXPOSE 21 22 8001 -CMD ["/bin/bash", "-c", "\ - if [ \"$MODE\" = \"terminal\" ]; then \ - /bin/bash; \ - else \ - echo 'Starting the container' && \ - echo 'LSUSB' && lsusb && \ - echo 'Listing external USB storage devices' && \ - ls /media && \ - /usr/sbin/sshd -D & \ - /usr/sbin/vsftpd /etc/vsftpd.conf & \ - ls /root/ImSwitchConfig/imcontrol_setups && \ - PATCH_DIR=/tmp/ImSwitch-changes && \ - PATCH_FILE=$PATCH_DIR/diff.patch && \ - mkdir -p $PATCH_DIR && \ - if [ -f \"$PATCH_FILE\" ]; then \ - echo 'Applying stored patch from: $PATCH_FILE' && \ - cd /tmp/ImSwitch && \ - git apply $PATCH_FILE; \ - else \ - echo 'No patch file found, proceeding without applying changes'; \ - fi && \ - if [ \"$UPDATE_CONFIG\" = \"true\" ]; then \ - echo 'Pulling the ImSwitchConfig repository' && \ - cd /root/ImSwitchConfig && \ - git pull; \ - fi && \ - if [ -z \"$CONFIG_PATH\" ]; then \ - CONFIG_FILE=${CONFIG_FILE:-/root/ImSwitchConfig/imcontrol_setups/example_virtual_microscope.json}; \ - else \ - CONFIG_FILE=None; \ - fi && \ - PERSISTENT_PIP_DIR=${PERSISTENT_PIP_DIR:-/persistent_pip_packages} && \ - mkdir -p $PERSISTENT_PIP_DIR && \ - export PYTHONUSERBASE=$PERSISTENT_PIP_DIR && \ - export PATH=$PERSISTENT_PIP_DIR/bin:$PATH && \ - if [ ! -z \"$PIP_PACKAGES\" ]; then \ - echo 'Installing additional pip packages: $PIP_PACKAGES' && \ - for package in $PIP_PACKAGES; do \ - /opt/conda/bin/conda run -n imswitch pip install --user $package; \ - done; \ - fi && \ - if [ \"$UPDATE_GIT\" = \"true\" ] || [ \"$UPDATE_GIT\" = \"1\" ]; then \ - PATCH_DIR=/tmp/ImSwitch-changes && \ - PATCH_FILE=$PATCH_DIR/diff.patch && \ - mkdir -p $PATCH_DIR && \ - cd /tmp/ImSwitch && \ - if [ -f \"$PATCH_FILE\" ]; then \ - echo 'Applying stored patch to ImSwitch from: $PATCH_FILE' && \ - git apply $PATCH_FILE || { echo 'Failed to apply patch, aborting fetch'; exit 1; }; \ - fi && \ - echo 'Fetching the latest changes from ImSwitch repository' && \ - git fetch origin && \ - echo 'Checking for differences between local and remote branch' && \ - git diff HEAD origin/master > $PATCH_FILE && \ - if [ -s $PATCH_FILE ]; then \ - echo 'New changes detected, patch saved at: $PATCH_FILE'; \ - else \ - echo 'No new changes detected in ImSwitch repository, patch not updated'; \ - rm -f $PATCH_FILE; \ - fi && \ - echo 'Merging fetched changes from origin/master' && \ - git merge origin/master; \ - fi && \ - if [ \"$UPDATE_INSTALL_GIT\" = \"true\" ] || [ \"$UPDATE_INSTALL_GIT\" = \"1\" ]; then \ - echo 'Pulling the ImSwitch repository and installing' && \ - cd /tmp/ImSwitch && \ - git pull && \ - /bin/bash -c 'source /opt/conda/bin/activate imswitch && pip install --target /persistent_pip_packages /tmp/ImSwitch'; \ - fi && \ - source /opt/conda/bin/activate imswitch && \ - HEADLESS=${HEADLESS:-1} && \ - HTTP_PORT=${HTTP_PORT:-8001} && \ - USB_DEVICE_PATH=${USB_DEVICE_PATH:-/dev/bus/usb} && \ - CONFIG_PATH=${CONFIG_PATH:-None} && \ - DATA_PATH=${DATA_PATH:-None} && \ - echo \"python3 /tmp/ImSwitch/main.py --headless $HEADLESS --config-file $CONFIG_FILE --http-port $HTTP_PORT --config-folder $CONFIG_PATH --ext-data-folder $DATA_PATH \" && \ - python3 /tmp/ImSwitch/main.py --headless $HEADLESS --config-file $CONFIG_FILE --http-port $HTTP_PORT --config-folder $CONFIG_PATH --ext-data-folder $DATA_PATH; \ - fi"] - - -# source /opt/conda/bin/activate imswitch -# python3 /tmp/ImSwitch/main.py --headless 1 --config-file example_virtual_microscope.json --config-folder /config +ADD entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh +ENTRYPOINT ["/entrypoint.sh"] \ No newline at end of file diff --git a/docker/HIK/entrypoint.sh b/docker/HIK/entrypoint.sh new file mode 100644 index 00000000..bc8c0df3 --- /dev/null +++ b/docker/HIK/entrypoint.sh @@ -0,0 +1,110 @@ +#!/usr/bin/env bash + +if [[ ! ("$MODE" == "terminal") ]]; +then + echo 'Starting the container' + echo 'Listing USB Bus' + lsusb + echo 'Listing external storage devices' + ls /media + echo 'Starting SSH Server' + /usr/sbin/sshd -D + echo 'Starting SFTP Server' + /usr/sbin/vsftpd /etc/vsftpd.conf + echo 'Listing Config Dir' + ls /root/ImSwitchConfig/imcontrol_setups + + PATCH_DIR=/tmp/ImSwitch-changes + PATCH_FILE=$PATCH_DIR/diff.patch + + mkdir -p "$PATCH_DIR" + if [[ -f "$PATCH_FILE" ]] + then + echo "Applying stored patch from $PATCH_FILE" + cd /tmp/ImSwitch + git apply "$PATCH_FILE" + else + echo 'No patch file found, proceeding without applying changes' + fi + + if [[ "$UPDATE_CONFIG" = "true" ]] + then + echo 'Pulling the ImSwitchConfig repository' + cd /root/ImSwitchConfig + git pull + fi + if [[ -z "$CONFIG_PATH" ]] + then + CONFIG_FILE="${CONFIG_FILE:-/root/ImSwitchConfig/imcontrol_setups/example_virtual_microscope.json}" + else + CONFIG_FILE=None + fi + + PERSISTENT_PIP_DIR="${PERSISTENT_PIP_DIR:-/persistent_pip_packages}" + mkdir -p "$PERSISTENT_PIP_DIR" + export PYTHONUSERBASE="$PERSISTENT_PIP_DIR" + export PATH="$PERSISTENT_PIP_DIR/bin:$PATH" + if [[ -n "$PIP_PACKAGES" ]] + then + echo "Installing additional pip packages: $PIP_PACKAGES" + for package in $PIP_PACKAGES + do + /opt/conda/bin/conda run -n imswitch pip install --user $package + done + fi + if [[ "$UPDATE_GIT" == true || "$UPDATE_GIT" == "1" ]] + then + PATCH_DIR="/tmp/ImSwitch-changes" + PATCH_FILE="$PATCH_DIR/diff.patch" + mkdir -p "$PATCH_DIR" + cd /tmp/ImSwitch + if [[ -f "$PATCH_FILE" ]] + then + echo "Applying stored patch to ImSwitch from: $PATCH_FILE" + git apply "$PATCH_FILE" || { echo 'Failed to apply patch, aborting fetch'; exit 1; } + fi + echo 'Fetching the latest changes from ImSwitch repository' + git fetch origin + echo 'Checking for differences between local and remote branch' + git diff HEAD origin/master > "$PATCH_FILE" + if [[ -s "$PATCH_FILE" ]] + then + echo "New changes detected, patch saved at: $PATCH_FILE" + else + echo "No new changes detected in ImSwitch repository, patch not updated" + rm -f "$PATCH_FILE" + fi + echo 'Merging fetched changes from origin/master' + git merge origin/master + fi + if [[ "$UPDATE_INSTALL_GIT" == "true" || "$UPDATE_INSTALL_GIT" == "1" ]] + then + echo 'Pulling the ImSwitch repository and installing' + cd /tmp/ImSwitch + git pull + /bin/bash -c 'source /opt/conda/bin/activate imswitch && pip install --target /persistent_pip_packages /tmp/ImSwitch' + fi + source /opt/conda/bin/activate imswitch + USB_DEVICE_PATH=${USB_DEVICE_PATH:-/dev/bus/usb} + + params=() + if [[ $HEADLESS == "1" || $HEADLESS == "True" || $HEADLESS == "true" ]] + then + params+=" --headless" + fi; + if [[ $ssl == "0" || $ssl == "False" || $ssl == "false" ]] + then + params+=" --no-ssl" + fi; + params+=" --http-port ${HTTP_PORT:-8001}" + params+=" --config-folder ${CONFIG_PATH:-None}" + params+=" --config-file ${CONFIG_FILE:-None}" + params+=" --ext-data-folder ${DATA_PATH:-None}" + + echo 'Starting Imswitch with the following parameters:' + echo "${params[@]}" + python3 /tmp/ImSwitch/main.py $params +else + echo 'Starting the container in terminal mode' + exec bash +fi diff --git a/imswitch/__main__.py b/imswitch/__main__.py index ae2520a1..0320e5be 100644 --- a/imswitch/__main__.py +++ b/imswitch/__main__.py @@ -17,7 +17,7 @@ def main(is_headless:bool=None, default_config:str=None, http_port:int=None, ssl parser = argparse.ArgumentParser(description='Process some integers.') # specify if run in headless mode - parser.add_argument('--headless', dest='headless', type=bool, default=0, + parser.add_argument('--headless', dest='headless', default=False, action='store_true', help='run in headless mode') # specify config file name - None for default @@ -29,7 +29,7 @@ def main(is_headless:bool=None, default_config:str=None, http_port:int=None, ssl help='specify http port') # specify ssl - parser.add_argument('--ssl', dest='ssl', type=bool, default=True, + parser.add_argument('--no-ssl', dest='ssl', default=True, action='store_false', help='specify ssl') # specify the config folder (e.g. if running from a different location / container)