Guest User

Untitled

a guest
Jul 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #### Functions ###
  4. display_usage() {
  5. echo "This script must be run with Docker capable privileges and you should login to your registry before pushing!"
  6. echo -e "\nUsage:\n$0 <saved_image> [--push]\n"
  7. echo -e " <saved_image>\t\t\tThe image file to load and push"
  8. echo -e " [--push]\t\t\tPush to registry"
  9. echo -e "\nExample: $0 /mydir/ubuntu.tar --push "
  10. }
  11.  
  12. # Check params
  13. if [ $# -le 0 ]
  14. then
  15. display_usage
  16. exit 1
  17. fi
  18.  
  19. # Check Docker command executable exit code
  20. docker images > /dev/null 2>&1; rc=$?;
  21. if [[ $rc != 0 ]]; then
  22. display_usage
  23. exit 1
  24. fi
  25.  
  26. echo -e "\nLoading $1..."
  27.  
  28. # Load image and save output
  29. RESULT=$(docker load -i $1)
  30.  
  31. # Get image name and registry
  32. IMAGE=${RESULT#*: }
  33. REGISTRY=${IMAGE#*\/}
  34.  
  35. echo $RESULT
  36.  
  37. # Push if flag provided
  38. if [[ $* == *--push* ]]; then
  39.  
  40. echo -e "\nPushing $IMAGE to $REGISTRY..."
  41. docker push $IMAGE
  42.  
  43. # Check result
  44. if [[ $rc != 0 ]]; then
  45. echo -e "\nERROR: Push failed, are you logged in to $REGISTRY? (e.g. \$ docker login $REGISTRY)"
  46. exit 1
  47. fi
  48.  
  49. fi
  50.  
  51. echo "Done!"
  52. exit 0
Add Comment
Please, Sign In to add comment