Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
587f057b
Commit
587f057b
authored
Dec 13, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/googlecompute: StepUploadImage
parent
20a074b4
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
106 additions
and
13 deletions
+106
-13
builder/googlecompute/builder.go
builder/googlecompute/builder.go
+1
-1
builder/googlecompute/step_upload_image.go
builder/googlecompute/step_upload_image.go
+17
-12
builder/googlecompute/step_upload_image_test.go
builder/googlecompute/step_upload_image_test.go
+88
-0
No files found.
builder/googlecompute/builder.go
View file @
587f057b
...
...
@@ -60,9 +60,9 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
new
(
common
.
StepProvision
),
new
(
StepUpdateGsutil
),
new
(
StepCreateImage
),
new
(
StepUploadImage
),
}
/*
new(stepUploadImage),
new(stepRegisterImage),
}*/
...
...
builder/googlecompute/step_upload_image.go
View file @
587f057b
...
...
@@ -7,34 +7,39 @@ import (
"github.com/mitchellh/packer/packer"
)
//
s
tepUploadImage represents a Packer build step that uploads GCE machine images.
type
s
tepUploadImage
int
//
S
tepUploadImage represents a Packer build step that uploads GCE machine images.
type
S
tepUploadImage
int
// Run executes the Packer build step that uploads a GCE machine image.
func
(
s
*
stepUploadImage
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
var
(
config
=
state
.
Get
(
"config"
)
.
(
*
Config
)
comm
=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
sudoPrefix
=
""
ui
=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
imageFilename
=
state
.
Get
(
"image_file_name"
)
.
(
string
)
)
ui
.
Say
(
"Uploading image..."
)
func
(
s
*
StepUploadImage
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
comm
:=
state
.
Get
(
"communicator"
)
.
(
packer
.
Communicator
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
imageFilename
:=
state
.
Get
(
"image_file_name"
)
.
(
string
)
ui
:=
state
.
Get
(
"ui"
)
.
(
packer
.
Ui
)
sudoPrefix
:=
""
if
config
.
SSHUsername
!=
"root"
{
sudoPrefix
=
"sudo "
}
ui
.
Say
(
"Uploading image..."
)
cmd
:=
new
(
packer
.
RemoteCmd
)
cmd
.
Command
=
fmt
.
Sprintf
(
"%s/usr/local/bin/gsutil cp %s gs://%s"
,
sudoPrefix
,
imageFilename
,
config
.
BucketName
)
err
:=
cmd
.
StartWithUi
(
comm
,
ui
)
if
err
==
nil
&&
cmd
.
ExitStatus
!=
0
{
err
=
fmt
.
Errorf
(
"gsutil exited with non-zero exit status: %d"
,
cmd
.
ExitStatus
)
}
if
err
!=
nil
{
err
:=
fmt
.
Errorf
(
"Error uploading image: %s"
,
err
)
state
.
Put
(
"error"
,
err
)
ui
.
Error
(
err
.
Error
())
return
multistep
.
ActionHalt
}
return
multistep
.
ActionContinue
}
// Cleanup.
func
(
s
*
s
tepUploadImage
)
Cleanup
(
state
multistep
.
StateBag
)
{}
func
(
s
*
S
tepUploadImage
)
Cleanup
(
state
multistep
.
StateBag
)
{}
builder/googlecompute/step_upload_image_test.go
0 → 100644
View file @
587f057b
package
googlecompute
import
(
"strings"
"testing"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
)
func
TestStepUploadImage_impl
(
t
*
testing
.
T
)
{
var
_
multistep
.
Step
=
new
(
StepUploadImage
)
}
func
TestStepUploadImage
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepUploadImage
)
defer
step
.
Cleanup
(
state
)
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
state
.
Put
(
"image_file_name"
,
"foo"
)
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
// Verify
if
!
comm
.
StartCalled
{
t
.
Fatal
(
"start should be called"
)
}
if
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatal
(
"should not sudo"
)
}
if
!
strings
.
Contains
(
comm
.
StartCmd
.
Command
,
"gsutil cp"
)
{
t
.
Fatalf
(
"bad command: %#v"
,
comm
.
StartCmd
.
Command
)
}
}
func
TestStepUploadImage_badExitStatus
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepUploadImage
)
defer
step
.
Cleanup
(
state
)
comm
:=
new
(
packer
.
MockCommunicator
)
comm
.
StartExitStatus
=
12
state
.
Put
(
"communicator"
,
comm
)
state
.
Put
(
"image_file_name"
,
"foo"
)
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionHalt
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
if
_
,
ok
:=
state
.
GetOk
(
"error"
);
!
ok
{
t
.
Fatal
(
"should have error"
)
}
}
func
TestStepUploadImage_nonRoot
(
t
*
testing
.
T
)
{
state
:=
testState
(
t
)
step
:=
new
(
StepUploadImage
)
defer
step
.
Cleanup
(
state
)
comm
:=
new
(
packer
.
MockCommunicator
)
state
.
Put
(
"communicator"
,
comm
)
state
.
Put
(
"image_file_name"
,
"foo"
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
config
.
SSHUsername
=
"bob"
// run the step
if
action
:=
step
.
Run
(
state
);
action
!=
multistep
.
ActionContinue
{
t
.
Fatalf
(
"bad action: %#v"
,
action
)
}
// Verify
if
!
comm
.
StartCalled
{
t
.
Fatal
(
"start should be called"
)
}
if
!
strings
.
HasPrefix
(
comm
.
StartCmd
.
Command
,
"sudo"
)
{
t
.
Fatal
(
"should sudo"
)
}
if
!
strings
.
Contains
(
comm
.
StartCmd
.
Command
,
"gsutil cp"
)
{
t
.
Fatalf
(
"bad command: %#v"
,
comm
.
StartCmd
.
Command
)
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment