Commit bb283ec7 authored by Benjamin Bertrand's avatar Benjamin Bertrand
Browse files

Switch to curl to upload vagrant box

Uploading a file bigger than  2GB with httpie raises:
http: error: OverflowError: string longer than 2147483647 bytes

See https://github.com/requests/requests/issues/2717
parent be405398
Loading
Loading
Loading
Loading
+21 −9
Original line number Original line Diff line number Diff line
@@ -80,19 +80,31 @@ function upload_to_vagrant_cloud() {
  # Exit on any error
  # Exit on any error
  set -e
  set -e
  # create new box (don't check the status because it will return 422 if the box exists)
  # create new box (don't check the status because it will return 422 if the box exists)
  http --session=vagrantup --ignore-stdin POST ${VAGRANTCLOUD_API_URL}/boxes "Authorization: Bearer ${VAGRANTCLOUD_TOKEN}" \
  curl \
    box:="{\"username\": \"esss\", \"name\": \"${box_name}\", \"is_private\": false}"
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $VAGRANTCLOUD_TOKEN" \
    ${VAGRANTCLOUD_API_URL}/boxes \
    --data "{ \"box\": { \"username\": \"myuser\", \"name\": \"${box_name}\", \"is_private\": false } }"
  # create new version
  # create new version
  http --session=vagrantup --check-status --ignore-stdin POST ${box_api_url}/versions \
  curl \
    version:="{\"version\": \"${box_version}\"}"
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $VAGRANTCLOUD_TOKEN" \
    ${box_api_url}/versions \
    --data "{ \"version\": { \"version\": \"${box_version}\" } }"
  # create new provider
  # create new provider
  http --session=vagrantup --check-status --ignore-stdin POST ${box_api_url}/version/${box_version}/providers \
  curl \
    provider:='{"name": "virtualbox"}'
    --header "Content-Type: application/json" \
    --header "Authorization: Bearer $VAGRANTCLOUD_TOKEN" \
    ${box_api_url}/version/${box_version}/providers \
    --data '{ "provider": { "name": "virtualbox" } }'
  # get the path to upload the box
  # get the path to upload the box
  upload_path=$(http --session=vagrantup --check-status --ignore-stdin \
  upload_path=$(curl --header "Authorization: Bearer $VAGRANTCLOUD_TOKEN" \
    ${box_api_url}/version/${box_version}/provider/virtualbox/upload | jq -r .upload_path)
    ${box_api_url}/version/${box_version}/provider/virtualbox/upload | jq -r .upload_path)
  # upload the box
  # upload the box
  http --session=vagrantup --check-status --ignore-stdin PUT ${upload_path} @${box_path}
  curl $upload_path --request PUT --upload-file ${box_path}
  # release the new version
  # release the new version
  http --session=vagrantup --check-status --ignore-stdin PUT ${box_api_url}/version/${box_version}/release
  curl \
    --header "Authorization: Bearer $VAGRANTCLOUD_TOKEN" \
    --request PUT \
    ${box_api_url}/version/${box_version}/release
}
}