Skip to content

Commit

Permalink
- update script for docker installs
Browse files Browse the repository at this point in the history
- docker install with the same vagrantfile
- fix docker-build, push
  • Loading branch information
Roy Wiggins authored and Roy Wiggins committed Dec 13, 2024
1 parent 3a440da commit ddeefb7
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 63 deletions.
61 changes: 35 additions & 26 deletions addons/vagrant/docker/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -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
Expand All @@ -81,4 +90,4 @@ Vagrant.configure(2) do |config|
v.vmx["memsize"] = "4096"
end
end
end
end
60 changes: 34 additions & 26 deletions addons/vagrant/systemd/Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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|
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docker-build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions docker-push.sh
Original file line number Diff line number Diff line change
@@ -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
Expand Down
55 changes: 45 additions & 10 deletions install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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"

0 comments on commit ddeefb7

Please sign in to comment.