Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/openUC2/ImSwitch
Browse files Browse the repository at this point in the history
  • Loading branch information
beniroquai committed Sep 24, 2024
2 parents bce3ee1 + d8a8c00 commit 3e6a627
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 85 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/imswitch-docker-multiarch-noqt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
85 changes: 3 additions & 82 deletions docker/HIK/dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
110 changes: 110 additions & 0 deletions docker/HIK/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions imswitch/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 3e6a627

Please sign in to comment.