diff --git a/addons/vagrant/docker/Vagrantfile b/addons/vagrant/docker/Vagrantfile index 96bc451..2731525 100644 --- a/addons/vagrant/docker/Vagrantfile +++ b/addons/vagrant/docker/Vagrantfile @@ -2,21 +2,37 @@ # vi: set ft=ruby : require 'getoptlong' -orthanc='' +orthanc=false +depth='--depth 1' branch='--branch latest-stable' +tag='' use_default_disk=false +dev_mode=false + +install_type = "docker" opts = GetoptLong.new( [ '--orthanc', GetoptLong::OPTIONAL_ARGUMENT ], [ '--dev', GetoptLong::OPTIONAL_ARGUMENT ], - [ '--smaller-disk', GetoptLong::OPTIONAL_ARGUMENT ] + [ '--smaller-disk', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--docker', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--dev-tag', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--no-provision', GetoptLong::OPTIONAL_ARGUMENT ] ) opts.each do |opt, arg| case opt when '--orthanc' - orthanc='yes' + orthanc=true + when '--dev-tag' + tag='export MERCURE_TAG=dev ' when '--dev' branch='' + depth='' + dev_mode=true + when '--docker' + install_type = 'docker' + when '--systemd' + install_type = 'systemd' when '--smaller-disk' use_default_disk=true end @@ -29,41 +45,34 @@ if !use_default_disk then end $script = <<-SCRIPT -echo "#### mercure installation in docker mode" +echo "#### mercure installation in #{install_type} mode" echo Cloning mercure and calling install script... cd ~ -git clone --depth 1 #{branch} https://github.com/mercure-imaging/mercure.git -cd mercure -./install.sh -y docker -SCRIPT - -$script_orthanc = <<-SCRIPT -echo "#### mercure installation in docker mode with Orthanc" -echo Cloning mercure and calling install script... -cd ~ -git clone --depth 1 #{branch} https://github.com/mercure-imaging/mercure.git -cd mercure -./install.sh -y docker -cd addons/orthanc -docker-compose up -d +git clone #{depth} #{branch} https://github.com/mercure-imaging/mercure.git && cd mercure +#{tag} +./install.sh -y #{install_type} $@ SCRIPT Vagrant.configure(2) do |config| - config.vm.box = "bento/ubuntu-22.04" # 20.04 LTS + config.vm.box = "bento/ubuntu-22.04" # 22.04 LTS config.vm.network "forwarded_port", guest: 8000, host: 8000, auto_correct: true, host_ip: "127.0.0.1" config.vm.network "forwarded_port", guest: 11112, host: 11112, auto_correct: true, host_ip: "127.0.0.1" if use_default_disk == false then config.disksize.size = "70GB" end - if orthanc == "yes" then + if dev_mode == true then + args = [ "-d" ] + else + args = [] + end + if orthanc == true then config.vm.network "forwarded_port", guest: 8008, host: 8008, auto_correct: true, host_ip: "127.0.0.1" config.vm.network "forwarded_port", guest: 8042, host: 8042, auto_correct: true, host_ip: "127.0.0.1" - config.vm.network "forwarded_port", guest: 4242, host: 4242, auto_correct: true, host_ip: "127.0.0.1" - config.vm.provision "shell", inline: $script_orthanc - else - config.vm.provision "shell", inline: $script + config.vm.network "forwarded_port", guest: 4242, host: 4242, auto_correct: true, host_ip: "127.0.0.1" + args = args + [ "-o" ] end + config.vm.provision "shell", inline: $script, privileged: false, args: args # Increase memory for Parallels Desktop config.vm.provider "parallels" do |p, o| @@ -72,7 +81,7 @@ Vagrant.configure(2) do |config| # Increase memory for Virtualbox config.vm.provider "virtualbox" do |vb| - vb.memory = "4096" + vb.memory = "4096" end # Increase memory for VMware @@ -81,4 +90,4 @@ Vagrant.configure(2) do |config| v.vmx["memsize"] = "4096" end end -end +end \ No newline at end of file diff --git a/addons/vagrant/systemd/Vagrantfile b/addons/vagrant/systemd/Vagrantfile index c41eaa2..b526c15 100644 --- a/addons/vagrant/systemd/Vagrantfile +++ b/addons/vagrant/systemd/Vagrantfile @@ -2,21 +2,37 @@ # vi: set ft=ruby : require 'getoptlong' -orthanc='' +orthanc=false +depth='--depth 1' branch='--branch latest-stable' +tag='' use_default_disk=false +dev_mode=false + +install_type = "systemd" opts = GetoptLong.new( [ '--orthanc', GetoptLong::OPTIONAL_ARGUMENT ], [ '--dev', GetoptLong::OPTIONAL_ARGUMENT ], - [ '--smaller-disk', GetoptLong::OPTIONAL_ARGUMENT ] + [ '--smaller-disk', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--docker', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--dev-tag', GetoptLong::OPTIONAL_ARGUMENT ], + [ '--no-provision', GetoptLong::OPTIONAL_ARGUMENT ] ) opts.each do |opt, arg| case opt when '--orthanc' - orthanc='yes' + orthanc=true + when '--dev-tag' + tag='export MERCURE_TAG=dev ' when '--dev' branch='' + depth='' + dev_mode=true + when '--docker' + install_type = 'docker' + when '--systemd' + install_type = 'systemd' when '--smaller-disk' use_default_disk=true end @@ -29,42 +45,34 @@ if !use_default_disk then end $script = <<-SCRIPT -echo "#### mercure installation in systemd mode" -echo Cloning mercure and calling install script... -cd ~ -git clone --depth 1 #{branch} https://github.com/mercure-imaging/mercure.git -cd mercure -./install.sh -y systemd -SCRIPT - -$script_orthanc = <<-SCRIPT -echo "#### mercure installation in systemd mode with Orthanc" +echo "#### mercure installation in #{install_type} mode" echo Cloning mercure and calling install script... cd ~ -git clone --depth 1 #{branch} https://github.com/mercure-imaging/mercure.git -cd mercure -./install.sh -y systemd -cd addons/orthanc -docker network create mercure_default -docker-compose up -d +git clone #{depth} #{branch} https://github.com/mercure-imaging/mercure.git && cd mercure +#{tag} +./install.sh -y #{install_type} $@ SCRIPT Vagrant.configure(2) do |config| - config.vm.box = "bento/ubuntu-22.04" # 20.04 LTS + config.vm.box = "bento/ubuntu-22.04" # 22.04 LTS config.vm.network "forwarded_port", guest: 8000, host: 8000, auto_correct: true, host_ip: "127.0.0.1" config.vm.network "forwarded_port", guest: 11112, host: 11112, auto_correct: true, host_ip: "127.0.0.1" if use_default_disk == false then config.disksize.size = "70GB" end - if orthanc == "yes" then + if dev_mode == true then + args = [ "-d" ] + else + args = [] + end + if orthanc == true then config.vm.network "forwarded_port", guest: 8008, host: 8008, auto_correct: true, host_ip: "127.0.0.1" config.vm.network "forwarded_port", guest: 8042, host: 8042, auto_correct: true, host_ip: "127.0.0.1" - config.vm.network "forwarded_port", guest: 4242, host: 4242, auto_correct: true, host_ip: "127.0.0.1" - config.vm.provision "shell", inline: $script_orthanc - else - config.vm.provision "shell", inline: $script + config.vm.network "forwarded_port", guest: 4242, host: 4242, auto_correct: true, host_ip: "127.0.0.1" + args = args + [ "-o" ] end + config.vm.provision "shell", inline: $script, privileged: false, args: args # Increase memory for Parallels Desktop config.vm.provider "parallels" do |p, o| @@ -73,7 +81,7 @@ Vagrant.configure(2) do |config| # Increase memory for Virtualbox config.vm.provider "virtualbox" do |vb| - vb.memory = "4096" + vb.memory = "4096" end # Increase memory for VMware diff --git a/docker-build.sh b/docker-build.sh index 597e813..d55504b 100644 --- a/docker-build.sh +++ b/docker-build.sh @@ -87,7 +87,7 @@ build_component () { docker build $CACHE -t $PREFIX/mercure-base:$TAG -t $PREFIX/mercure-base:latest -f docker/base/Dockerfile . -for component in ui bookkeeper receiver router processor dispatcher cleaner worker +for component in ui bookkeeper receiver router processor dispatcher cleaner worker worker do build_component $component done diff --git a/docker-push.sh b/docker-push.sh index 993a395..75dee35 100644 --- a/docker-push.sh +++ b/docker-push.sh @@ -1,3 +1,5 @@ +#!/bin/bash +set -euo pipefail # Read the version of the mercure source, which will be used for # tagging the Docker images, unless a tag has been provided # through the environment variable MERCURE_TAG diff --git a/install.sh b/install.sh index 6c2cc73..1836d96 100755 --- a/install.sh +++ b/install.sh @@ -310,14 +310,19 @@ install_docker () { } setup_docker () { - if [ ! -f "$MERCURE_BASE"/docker-compose.yml ]; then + local overwrite=${1:-false} + if [ "$overwrite" = true ] || [ ! -f "$MERCURE_BASE"/docker-compose.yml ]; then echo "## Copying docker-compose.yml..." sudo cp $MERCURE_SRC/docker/docker-compose.yml $MERCURE_BASE sudo sed -i -e "s/\\\${DOCKER_GID}/$(getent group docker | cut -d: -f3)/g" $MERCURE_BASE/docker-compose.yml sudo sed -i -e "s/\\\${UID}/$(getent passwd mercure | cut -d: -f3)/g" $MERCURE_BASE/docker-compose.yml sudo sed -i -e "s/\\\${GID}/$(getent passwd mercure | cut -d: -f4)/g" $MERCURE_BASE/docker-compose.yml - sudo sed -i "s/\\\${IMAGE_TAG}/$IMAGE_TAG/g" $MERCURE_BASE/docker-compose.yml + if [[ -v MERCURE_TAG ]]; then # a custom tag was provided + sudo sed -i "s/\\\${IMAGE_TAG}/\:$MERCURE_TAG/g" $MERCURE_BASE/docker-compose.yml + else + sudo sed -i "s/\\\${IMAGE_TAG}/$IMAGE_TAG/g" $MERCURE_BASE/docker-compose.yml + fi sudo chown $OWNER:$OWNER "$MERCURE_BASE"/docker-compose.yml fi } @@ -343,8 +348,9 @@ build_docker () { start_docker () { echo "## Starting docker compose..." - cd /opt/mercure + pushd $MERCURE_BASE sudo docker-compose up -d + popd } link_binaries() { @@ -505,6 +511,30 @@ systemd_update () { echo "Update complete." } +docker_update () { + if [ ! -f $MERCURE_BASE/docker-compose.yml ]; then + echo "ERROR: $MERCURE_BASE/docker-compose.yml does not exist; is Mercure installed?" + exit 1 + fi + if [ -f $MERCURE_BASE/docker-compose.override.yml ]; then + echo "ERROR: $MERCURE_BASE/docker-compose.override.yml exists. Updating a dev install is not supported." + exit 1 + fi + if [ $FORCE_INSTALL != "y" ]; then + echo "Update mercure to ${MERCURE_TAG:-VERSION} (y/n)?" + read -p "WARNING: Server may require manual fixes after update. Taking backups beforehand is recommended. " ANS + if [ "$ANS" != "y" ]; then + echo "Update aborted." + exit 0 + fi + fi + # sudo sed -E "s/(image\: mercureimaging.*?\:).*/\1foo/g" docker-compose.yml + pushd $MERCURE_BASE + sudo docker-compose down || true + popd + setup_docker true + start_docker +} FORCE_INSTALL="n" while getopts ":hy" opt; do @@ -553,10 +583,7 @@ while getopts ":dbuo" opt; do INSTALL_ORTHANC=true ;; u ) - if [ $INSTALL_TYPE != "systemd" ]; then - echo "Invalid option for \"$INSTALL_TYPE\": -u" 1>&2 - fi - INSTALL_TYPE="systemd_update" + DO_OPERATION="update" ;; d ) DO_DEV_INSTALL=true @@ -574,9 +601,17 @@ while getopts ":dbuo" opt; do esac done -if [ $INSTALL_TYPE == "systemd_update" ]; then +if [ $DO_DEV_INSTALL == true ] && [ $DO_OPERATION == "update" ]; then + echo "Invalid option: cannot update a dev installation" 1>&2 + exit 1 +fi + +if [ $INSTALL_TYPE == "systemd" ] && [ $DO_OPERATION == "update" ]; then systemd_update exit 0 +elif [ $INSTALL_TYPE == "docker" ] && [ $DO_OPERATION == "update" ]; then + docker_update + exit 0 fi if [ $FORCE_INSTALL = "y" ]; then @@ -608,9 +643,9 @@ case "$INSTALL_TYPE" in esac if [ $INSTALL_ORTHANC == true ]; then echo "Installing Orthanc..." - cd addons/orthanc + pushd addons/orthanc sudo docker network create mercure_default || true sudo docker-compose up -d - cd - + popd fi echo "Installation complete"