From 5ba84fb37c9d2b13985e975f93f30180e1975f1c Mon Sep 17 00:00:00 2001 From: Jeffrey Morgan Date: Thu, 6 Aug 2015 17:40:20 -0700 Subject: [PATCH] Boot2Docker migration on osx --- osx/Dockerfile | 2 ++ osx/mpkg/Distribution | 22 +++++++++---- .../Contents/Resources/Scripts/start.sh | 2 +- .../boot2dockeriso.pkg/Scripts/postinstall | 1 - osx/mpkg/dockermachine.pkg/PackageInfo | 3 ++ .../dockermachine.pkg/Scripts/postinstall | 33 +++++++++++++++++++ 6 files changed, 54 insertions(+), 9 deletions(-) create mode 100755 osx/mpkg/dockermachine.pkg/Scripts/postinstall diff --git a/osx/Dockerfile b/osx/Dockerfile index 3db43c8468..34e3bc0ec4 100644 --- a/osx/Dockerfile +++ b/osx/Dockerfile @@ -91,6 +91,8 @@ RUN cd /mpkg/docker.pkg && \ # dockermachine.pkg RUN cd /mpkg/dockermachine.pkg && \ + cd Scripts && find . | cpio -o --format odc | gzip -c > ../Scripts.bin && cd .. && \ + rm -r Scripts && mv Scripts.bin Scripts && \ mkdir rootfs && \ cd rootfs && \ mkdir -p usr/local/bin && \ diff --git a/osx/mpkg/Distribution b/osx/mpkg/Distribution index 826f5bde70..6aaab65b6b 100644 --- a/osx/mpkg/Distribution +++ b/osx/mpkg/Distribution @@ -18,9 +18,6 @@ - - - @@ -34,10 +31,6 @@ - #dockermachine.pkg - - - #dockercompose.pkg @@ -159,4 +152,19 @@ + #dockerquickstartterminalapp.pkg + + + + #kitematicapp.pkg + + + + + + + #dockermachine.pkg + + + diff --git a/osx/mpkg/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh b/osx/mpkg/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh index c312d8d2b8..68974a79a8 100755 --- a/osx/mpkg/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh +++ b/osx/mpkg/Docker Quickstart Terminal.app/Contents/Resources/Scripts/start.sh @@ -1,6 +1,6 @@ #!/bin/bash -VM=docker-vm +VM=default DOCKER_MACHINE=/usr/local/bin/docker-machine BLUE='\033[0;34m' diff --git a/osx/mpkg/boot2dockeriso.pkg/Scripts/postinstall b/osx/mpkg/boot2dockeriso.pkg/Scripts/postinstall index fdffd4f2dd..b755fdb87a 100755 --- a/osx/mpkg/boot2dockeriso.pkg/Scripts/postinstall +++ b/osx/mpkg/boot2dockeriso.pkg/Scripts/postinstall @@ -7,4 +7,3 @@ chown -R $USER:staff ~/.docker curl -H "Content-Type: application/json" -X POST "https://api.mixpanel.com/track/?data=%EVENT_DATA%" -# TODO: run migration diff --git a/osx/mpkg/dockermachine.pkg/PackageInfo b/osx/mpkg/dockermachine.pkg/PackageInfo index 69da875e9b..b62b6cb3ac 100644 --- a/osx/mpkg/dockermachine.pkg/PackageInfo +++ b/osx/mpkg/dockermachine.pkg/PackageInfo @@ -7,4 +7,7 @@ + + + diff --git a/osx/mpkg/dockermachine.pkg/Scripts/postinstall b/osx/mpkg/dockermachine.pkg/Scripts/postinstall new file mode 100755 index 0000000000..ab1c8d75ee --- /dev/null +++ b/osx/mpkg/dockermachine.pkg/Scripts/postinstall @@ -0,0 +1,33 @@ +#!/bin/bash + +ls -al ~/.docker/machine/cache/ + +# Migrate Boot2Docker VM +BOOT2DOCKER_VM=boot2docker-vm +VM=default + +sudo -u $USER /usr/local/bin/VBoxManage showvminfo $BOOT2DOCKER_VM &> /dev/null +BOOT2DOCKER_VM_EXISTS_CODE=$? + +sudo -u $USER /usr/local/bin/VBoxManage showvminfo $VM &> /dev/null +VM_EXISTS_CODE=$? + +# Exit if there's no boot2docker vm, or the destination VM already exists +if [ $BOOT2DOCKER_VM_EXISTS_CODE -ne 0 ] || [ $VM_EXISTS_CODE -eq 0 ]; then + exit 0 +fi + +osascript -e 'tell app "System Events" to display dialog "Migrate your existing Boot2Docker VM to work with the Docker Toolbox?\n \nYour existing Boot2Docker VM will not be affected. This should take about a minute." buttons {"Do not Migrate", "Migrate"} default button 2 cancel button 1 with icon 2 with title "Migrate Boot2Docker VM?"' +if [ $? -eq 0 ]; then + rm -rf ~/.docker/machine/machines/default + sudo -u $USER PATH=/Applications/VirtualBox.app/Contents/MacOS/:$PATH bash -c "/usr/local/bin/docker-machine -D create -d virtualbox --virtualbox-import-boot2docker-vm $BOOT2DOCKER_VM $VM" 2>&1 | sed -e '/BEGIN/,/END/d' > /tmp/toolbox-migration-logs.txt + if [ $? -ne 0 ]; then + osascript -e 'tell app "System Events" to display dialog "Boot2Docker VM migrated successfully to a Docker Machine VM named \"default\"" buttons {"Ok"} default button 1' + else + osascript -e 'tell app "System Events" to display dialog "Could not migrate the Boot2Docker VM. Please file an issue with the migration logs at https://github.com/docker/machine/issues/new." buttons {"Cancel", "View Migration Logs"} default button 2 cancel button 1 with icon 0 with title "Migration Failed"' + if [ $? -eq 0 ]; then + open -a TextEdit /tmp/toolbox-migration-logs.txt + fi + exit 1 + fi +fi