Force NoDirectUpload for vagrantcloud if asset size > 5 GB
This commit is contained in:
parent
3227d3da43
commit
9b641c9bfd
|
@ -3,11 +3,14 @@ package vagrantcloud
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
"github.com/hashicorp/packer-plugin-sdk/multistep"
|
||||||
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
packersdk "github.com/hashicorp/packer-plugin-sdk/packer"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const VAGRANT_CLOUD_DIRECT_UPLOAD_LIMIT = 5000000000 // Upload limit is 5GB
|
||||||
|
|
||||||
type Upload struct {
|
type Upload struct {
|
||||||
UploadPath string `json:"upload_path"`
|
UploadPath string `json:"upload_path"`
|
||||||
CallbackPath string `json:"callback"`
|
CallbackPath string `json:"callback"`
|
||||||
|
@ -25,6 +28,18 @@ func (s *stepPrepareUpload) Run(ctx context.Context, state multistep.StateBag) m
|
||||||
provider := state.Get("provider").(*Provider)
|
provider := state.Get("provider").(*Provider)
|
||||||
artifactFilePath := state.Get("artifactFilePath").(string)
|
artifactFilePath := state.Get("artifactFilePath").(string)
|
||||||
|
|
||||||
|
// If direct upload is enabled, the asset size must be <= 5 GB
|
||||||
|
if config.NoDirectUpload == false {
|
||||||
|
f, err := os.Stat(artifactFilePath)
|
||||||
|
if err != nil {
|
||||||
|
ui.Error(fmt.Sprintf("error determining size of upload artifact: %s", artifactFilePath))
|
||||||
|
}
|
||||||
|
if f.Size() > VAGRANT_CLOUD_DIRECT_UPLOAD_LIMIT {
|
||||||
|
ui.Say(fmt.Sprintf("Asset %s is larger than the direct upload limit. Setting `NoDirectUpload` to true", artifactFilePath))
|
||||||
|
config.NoDirectUpload = true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
path := fmt.Sprintf("box/%s/version/%v/provider/%s/upload", box.Tag, version.Version, provider.Name)
|
path := fmt.Sprintf("box/%s/version/%v/provider/%s/upload", box.Tag, version.Version, provider.Name)
|
||||||
if !config.NoDirectUpload {
|
if !config.NoDirectUpload {
|
||||||
path = path + "/direct"
|
path = path + "/direct"
|
||||||
|
|
Loading…
Reference in New Issue