From 44105daf4ad46dfb8a0e4dd63e4e3ef053518c82 Mon Sep 17 00:00:00 2001 From: bpinsard Date: Wed, 31 Jan 2024 13:38:32 -0500 Subject: [PATCH] add command/entrypoin --- docker/dicom_indexer/Dockerfile | 6 ++--- docker/dicom_indexer/entrypoint.sh | 37 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+), 3 deletions(-) create mode 100644 docker/dicom_indexer/entrypoint.sh diff --git a/docker/dicom_indexer/Dockerfile b/docker/dicom_indexer/Dockerfile index f7f4c4c..22ec83d 100644 --- a/docker/dicom_indexer/Dockerfile +++ b/docker/dicom_indexer/Dockerfile @@ -1,6 +1,6 @@ -FROM alpine:3.19 +FROM python:3.12-alpine RUN apk add --no-cache ca-certificates tzdata \ - python3 py3-pip git openssh-client git-annex curl bzip2 bash glab\ + git openssh-client git-annex curl bzip2 bash glab\ && cp /usr/share/zoneinfo/UTC /etc/localtime \ && apk del tzdata \ && rm -rf /tmp/* /var/cache/apk/* @@ -12,6 +12,6 @@ RUN pip install --break-system-packages --no-cache-dir datalad ssh_agent_setup p ADD indexer /indexer COPY entrypoint.sh /entrypoint.sh RUN chmod +x /entrypoint.sh -ENTRYPOINT /entrypoint.sh +CMD /entrypoint.sh WORKDIR /work diff --git a/docker/dicom_indexer/entrypoint.sh b/docker/dicom_indexer/entrypoint.sh new file mode 100644 index 0000000..05d50ac --- /dev/null +++ b/docker/dicom_indexer/entrypoint.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +CONTAINER_ID=$(basename $(cat /proc/1/cpuset)) +GITLAB_TOKEN_SECRET=/var/run/secrets/dicom_bot_gitlab_token + +# only export keys when deploying as a service on swarm +# TODO: should try using gitlab runner mechanism if not +if [ -e $GITLAB_TOKEN_SECRET ] ; then + # generate container specific ssh-key + ssh-keygen -f /root/.ssh/id_rsa -N '' + # register it for dicom_bot user + curl -X POST -F "private_token=$(cat $GITLAB_TOKEN_SECRET)" \ + -F "title="$(cat /etc/hostname)${CONTAINER_ID:0:12} -F "key=$(cat ~/.ssh/id_rsa.pub)" \ + "${GITLAB_API_URL}/user/keys" + fi + +git config --global init.defaultBranch main + + +# example +# /usr/bin/storescp \ +# -aet DICOM_SERVER_SEQUOIA\ +# -pm\ +# -od $DICOM_TMP_DIR -su ''\ +# --eostudy-timeout ${STORESCP_STUDY_TIMEOUT:=60} \ +# --exec-on-eostudy "python3 $DICOM_ROOT/exec_on_study_received.py #p " 2100 >> $DICOM_DATA_ROOT/storescp.log + +# run whatever command was passed (storescp or python index_dicoms directly) +echo $@ +bash -c "$@" + +if [ -e $GITLAB_TOKEN_SECRET ] ; then + # unregister the temporary ssh key + curl -X DELETE -F "private_token=$(cat $GITLAB_TOKEN_SECRET)" \ + -F "title="$(cat /etc/hostname)${CONTAINER_ID:0:12} + "${GITLAB_API_URL}/user/keys" +fi