Commit d08815fc authored by Mitchell Hashimoto's avatar Mitchell Hashimoto

command/push: works

parent c1fbc473
...@@ -7,8 +7,8 @@ import ( ...@@ -7,8 +7,8 @@ import (
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/hashicorp/harmony-go" "github.com/hashicorp/atlas-go/v1"
"github.com/hashicorp/harmony-go/archive" "github.com/hashicorp/atlas-go/archive"
"github.com/mitchellh/packer/packer" "github.com/mitchellh/packer/packer"
) )
...@@ -18,7 +18,7 @@ const archiveTemplateEntry = ".packer-template" ...@@ -18,7 +18,7 @@ const archiveTemplateEntry = ".packer-template"
type PushCommand struct { type PushCommand struct {
Meta Meta
client *harmony.Client client *atlas.Client
// For tests: // For tests:
uploadFn func(io.Reader, *uploadOpts) (<-chan struct{}, <-chan error, error) uploadFn func(io.Reader, *uploadOpts) (<-chan struct{}, <-chan error, error)
...@@ -64,9 +64,9 @@ func (c *PushCommand) Run(args []string) int { ...@@ -64,9 +64,9 @@ func (c *PushCommand) Run(args []string) int {
// Build our client // Build our client
defer func() { c.client = nil }() defer func() { c.client = nil }()
c.client = harmony.DefaultClient() c.client = atlas.DefaultClient()
if tpl.Push.Address != "" { if tpl.Push.Address != "" {
c.client, err = harmony.NewClient(tpl.Push.Address) c.client, err = atlas.NewClient(tpl.Push.Address)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf( c.Ui.Error(fmt.Sprintf(
"Error setting up API client: %s", err)) "Error setting up API client: %s", err))
...@@ -110,7 +110,7 @@ func (c *PushCommand) Run(args []string) int { ...@@ -110,7 +110,7 @@ func (c *PushCommand) Run(args []string) int {
} }
// Start the archiving process // Start the archiving process
r, archiveErrCh, err := archive.Archive(path, &opts) r, err := archive.CreateArchive(path, &opts)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf("Error archiving: %s", err)) c.Ui.Error(fmt.Sprintf("Error archiving: %s", err))
return 1 return 1
...@@ -126,8 +126,6 @@ func (c *PushCommand) Run(args []string) int { ...@@ -126,8 +126,6 @@ func (c *PushCommand) Run(args []string) int {
err = nil err = nil
select { select {
case err = <-archiveErrCh:
err = fmt.Errorf("Error archiving: %s", err)
case err = <-uploadErrCh: case err = <-uploadErrCh:
err = fmt.Errorf("Error uploading: %s", err) err = fmt.Errorf("Error uploading: %s", err)
case <-doneCh: case <-doneCh:
...@@ -138,6 +136,7 @@ func (c *PushCommand) Run(args []string) int { ...@@ -138,6 +136,7 @@ func (c *PushCommand) Run(args []string) int {
return 1 return 1
} }
c.Ui.Output(fmt.Sprintf("Push successful to '%s'", tpl.Push.Name))
return 0 return 0
} }
...@@ -173,7 +172,7 @@ func (c *PushCommand) create(name string, create bool) error { ...@@ -173,7 +172,7 @@ func (c *PushCommand) create(name string, create bool) error {
} }
// Separate the slug into the user and name components // Separate the slug into the user and name components
user, name, err := harmony.ParseSlug(name) user, name, err := atlas.ParseSlug(name)
if err != nil { if err != nil {
return fmt.Errorf("Malformed push name: %s", err) return fmt.Errorf("Malformed push name: %s", err)
} }
...@@ -181,7 +180,7 @@ func (c *PushCommand) create(name string, create bool) error { ...@@ -181,7 +180,7 @@ func (c *PushCommand) create(name string, create bool) error {
// Check if it exists. If so, we're done. // Check if it exists. If so, we're done.
if _, err := c.client.BuildConfig(user, name); err == nil { if _, err := c.client.BuildConfig(user, name); err == nil {
return nil return nil
} else if err != harmony.ErrNotFound { } else if err != atlas.ErrNotFound {
return err return err
} }
...@@ -201,13 +200,13 @@ func (c *PushCommand) create(name string, create bool) error { ...@@ -201,13 +200,13 @@ func (c *PushCommand) create(name string, create bool) error {
} }
func (c *PushCommand) upload( func (c *PushCommand) upload(
r io.Reader, opts *uploadOpts) (<-chan struct{}, <-chan error, error) { r *archive.Archive, opts *uploadOpts) (<-chan struct{}, <-chan error, error) {
if c.uploadFn != nil { if c.uploadFn != nil {
return c.uploadFn(r, opts) return c.uploadFn(r, opts)
} }
// Separate the slug into the user and name components // Separate the slug into the user and name components
user, name, err := harmony.ParseSlug(opts.Slug) user, name, err := atlas.ParseSlug(opts.Slug)
if err != nil { if err != nil {
return nil, nil, fmt.Errorf("upload: %s", err) return nil, nil, fmt.Errorf("upload: %s", err)
} }
...@@ -219,13 +218,13 @@ func (c *PushCommand) upload( ...@@ -219,13 +218,13 @@ func (c *PushCommand) upload(
} }
// Build the version to send up // Build the version to send up
version := harmony.BuildConfigVersion{ version := atlas.BuildConfigVersion{
User: bc.User, User: bc.User,
Name: bc.Name, Name: bc.Name,
Builds: make([]harmony.BuildConfigBuild, 0, len(opts.Builds)), Builds: make([]atlas.BuildConfigBuild, 0, len(opts.Builds)),
} }
for name, t := range opts.Builds { for name, t := range opts.Builds {
version.Builds = append(version.Builds, harmony.BuildConfigBuild{ version.Builds = append(version.Builds, atlas.BuildConfigBuild{
Name: name, Name: name,
Type: t, Type: t,
}) })
...@@ -234,7 +233,7 @@ func (c *PushCommand) upload( ...@@ -234,7 +233,7 @@ func (c *PushCommand) upload(
// Start the upload // Start the upload
doneCh, errCh := make(chan struct{}), make(chan error) doneCh, errCh := make(chan struct{}), make(chan error)
go func() { go func() {
err := c.client.UploadBuildConfigVersion(&version, r) err := c.client.UploadBuildConfigVersion(&version, r, r.Size)
if err != nil { if err != nil {
errCh <- err errCh <- err
return return
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment