Skip to content

Instantly share code, notes, and snippets.

@byplayer
Last active July 30, 2021 03:08
Show Gist options
  • Save byplayer/9c629eec572788d65fa87155d7e08ab4 to your computer and use it in GitHub Desktop.
Save byplayer/9c629eec572788d65fa87155d7e08ab4 to your computer and use it in GitHub Desktop.
packer to build ubuntu box
# packer https://www.packer.io/
# update pakcer before run
# get token token
https://app.vagrantup.com/settings/security
VAGRANT_CLOUD_TOKEN=
VUSER=
BOX_NAME=ubuntu2104-lubuntu
VERSION=1.0
PROVIDER_NAME=virtualbox
mkdir -p tmp
packer build -only=virtualbox-iso -var-file=${BOX_NAME}.json ubuntu.json >> tmp/packer.log
# https://www.vagrantup.com/docs/vagrant-cloud/api.html#upload-a-provider
# Create a new box
curl \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
https://app.vagrantup.com/api/v1/boxes \
--data '{ "box": { "username": "'"$VUSER"'", "name": "'"$BOX_NAME"'", "is_private": "false" } }'
curl \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
https://app.vagrantup.com/api/v1/box/$VUSER/$BOX_NAME/versions \
--data '{ "version": { "version": "'$VERSION'" } }'
# Create a new provider
curl \
--header "Content-Type: application/json" \
--header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
https://app.vagrantup.com/api/v1/box/$VUSER/$BOX_NAME/version/$VERSION/providers \
--data '{ "provider": { "name": "'$PROVIDER_NAME'" } }'
# upload url
response=$(curl \
--header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
https://app.vagrantup.com/api/v1/box/$VUSER/$BOX_NAME/version/$VERSION/provider/$PROVIDER_NAME/upload)
# Requires the jq command
upload_path=$(echo "$response" | jq .upload_path | tr -d '\"')
curl \
--progress-bar \
$upload_path \
--request PUT \
--upload-file $BOX_NAME-0.1.0.box
curl \
--header "Authorization: Bearer $VAGRANT_CLOUD_TOKEN" \
https://app.vagrantup.com/api/v1/box/$VUSER/$BOX_NAME/version/$VERSION/release \
--request PUT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment