Skip to content

Commit

Permalink
Merge pull request #298 from DigitalSlideArchive/provision-always-repull
Browse files Browse the repository at this point in the history
Add an option to always repull slicer cli images.
  • Loading branch information
manthey committed Oct 12, 2023
2 parents ec6af63 + d0dcdd7 commit f93a313
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
19 changes: 15 additions & 4 deletions devops/dsa/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ def provision_resources(resources, adminUser):
result = model.save(result)


def get_slicer_images(imageList, adminUser):
def get_slicer_images(imageList, adminUser, alwaysPull=False):
"""
Load a list of cli docker images into the system.
:param imageList: a list of docker images.
:param adminUser: an admin user for permissions.
:param alwaysPull: true to ask to always pull the latest image.
"""
import threading

Expand All @@ -180,6 +181,7 @@ def get_slicer_images(imageList, adminUser):
kwargs={
'nameList': imageList,
'folder': Setting().get(PluginSettings.SLICER_CLI_WEB_TASK_FOLDER),
'pull': 'true' if alwaysPull else 'asneeded',
},
title='Pulling and caching docker images',
type=DockerResource.jobType,
Expand Down Expand Up @@ -284,6 +286,12 @@ def provision(opts): # noqa
value = value_from_resource(value, adminUser)
logger.info('Setting %s to %r', key, value)
Setting().set(key, value)
if getattr(opts, 'slicer-cli-image-pull', None):
try:
get_slicer_images(getattr(opts, 'slicer-cli-image-pull', None),
adminUser, alwaysPull=True)
except Exception:
logger.info('Cannot fetch slicer-cli-images.')
if getattr(opts, 'slicer-cli-image', None):
try:
get_slicer_images(getattr(opts, 'slicer-cli-image', None), adminUser)
Expand Down Expand Up @@ -424,8 +432,8 @@ def merge_default_opts(opts):
'slicer_cli_web.task_folder': 'resourceid:collection/Tasks/Slicer CLI Web Tasks',
})
opts.settings = settings
if getattr(opts, 'slicer-cli-image', None) is None:
setattr(opts, 'slicer-cli-image', ['dsarchive/histomicstk:latest'])
if getattr(opts, 'slicer-cli-image-pull', None) is None:
setattr(opts, 'slicer-cli-image-pull', ['dsarchive/histomicstk:latest'])
if getattr(opts, 'assetstore', None) is None:
opts.assetstore = {
'name': 'Assetstore',
Expand Down Expand Up @@ -549,7 +557,10 @@ def __call__(self, parser, namespace, values, option_string=None):
default=False, help='Rebuild the girder client.')
parser.add_argument(
'--slicer-cli-image', dest='slicer-cli-image', action='append',
help='Install slicer_cli images.')
help='Install slicer_cli images, only pulling if not present.')
parser.add_argument(
'--slicer-cli-image-pull', dest='slicer-cli-image-pull', action='append',
help='Install slicer_cli images, always pulling the latest.')

parser.add_argument(
'--rabbitmq-user', default='guest', dest='worker-rabbitmq-user',
Expand Down
7 changes: 5 additions & 2 deletions devops/dsa/provision.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,11 @@ settings:
The [HistomicsUI](histomics) application is enabled.
slicer_cli_web.task_folder: "resourceid:collection/Tasks/Slicer CLI Web Tasks"
# List slicer-cli-images to pull and load
slicer-cli-image:
# List slicer-cli-images to pull, if not present, and load
# slicer-cli-image:
# - dsarchive/histomicstk:latest
# List slicer-cli-images to always pull, and load
slicer-cli-image-pull:
- dsarchive/histomicstk:latest
# The worker can specify parameters for provisioning
# worker-rabbitmq-host: girder:8080
Expand Down
22 changes: 18 additions & 4 deletions devops/minimal/provision.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,13 @@ def provision_resources(resources, adminUser):
result = model.save(result)


def get_slicer_images(imageList, adminUser):
def get_slicer_images(imageList, adminUser, alwaysPull=False):
"""
Load a list of cli docker images into the system.
:param imageList: a list of docker images.
:param adminUser: an admin user for permissions.
:param alwaysPull: true to ask to always pull the latest image.
"""
import threading

Expand All @@ -180,6 +181,7 @@ def get_slicer_images(imageList, adminUser):
kwargs={
'nameList': imageList,
'folder': Setting().get(PluginSettings.SLICER_CLI_WEB_TASK_FOLDER),
'pull': 'true' if alwaysPull else 'asneeded',
},
title='Pulling and caching docker images',
type=DockerResource.jobType,
Expand Down Expand Up @@ -284,6 +286,12 @@ def provision(opts): # noqa
value = value_from_resource(value, adminUser)
logger.info('Setting %s to %r', key, value)
Setting().set(key, value)
if getattr(opts, 'slicer-cli-image-pull', None):
try:
get_slicer_images(getattr(opts, 'slicer-cli-image-pull', None),
adminUser, alwaysPull=True)
except Exception:
logger.info('Cannot fetch slicer-cli-images.')
if getattr(opts, 'slicer-cli-image', None):
try:
get_slicer_images(getattr(opts, 'slicer-cli-image', None), adminUser)
Expand Down Expand Up @@ -424,8 +432,8 @@ def merge_default_opts(opts):
'slicer_cli_web.task_folder': 'resourceid:collection/Tasks/Slicer CLI Web Tasks',
})
opts.settings = settings
if getattr(opts, 'slicer-cli-image', None) is None:
setattr(opts, 'slicer-cli-image', ['dsarchive/histomicstk:latest'])
if getattr(opts, 'slicer-cli-image-pull', None) is None:
setattr(opts, 'slicer-cli-image-pull', ['dsarchive/histomicstk:latest'])
if getattr(opts, 'assetstore', None) is None:
opts.assetstore = {
'name': 'Assetstore',
Expand Down Expand Up @@ -549,7 +557,10 @@ def __call__(self, parser, namespace, values, option_string=None):
default=False, help='Rebuild the girder client.')
parser.add_argument(
'--slicer-cli-image', dest='slicer-cli-image', action='append',
help='Install slicer_cli images.')
help='Install slicer_cli images, only pulling if not present.')
parser.add_argument(
'--slicer-cli-image-pull', dest='slicer-cli-image-pull', action='append',
help='Install slicer_cli images, always pulling the latest.')

parser.add_argument(
'--rabbitmq-user', default='guest', dest='worker-rabbitmq-user',
Expand Down Expand Up @@ -631,6 +642,9 @@ def __call__(self, parser, namespace, values, option_string=None):
except Exception:
logger.warning('Could not connect to mongo.')
try:
# In mongo shell, this is functionally
# db.adminCommand({setFeatureCompatibilityVersion:
# db.version().split('.').slice(0, 2).join('.')})
db.admin.command({'setFeatureCompatibilityVersion': '.'.join(
db.server_info()['version'].split('.')[:2]), 'confirm': True})
except Exception:
Expand Down

0 comments on commit f93a313

Please sign in to comment.