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
944d0e2e
Commit
944d0e2e
authored
Aug 20, 2014
by
Eric Johnson
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1431 from mpage/gce-project-id-for-source-image
Allow specifying project for source images in GCE
parents
895db383
8f237b7b
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
56 additions
and
41 deletions
+56
-41
builder/googlecompute/config.go
builder/googlecompute/config.go
+36
-34
builder/googlecompute/driver.go
builder/googlecompute/driver.go
+6
-1
builder/googlecompute/driver_gce.go
builder/googlecompute/driver_gce.go
+5
-5
builder/googlecompute/step_create_instance.go
builder/googlecompute/step_create_instance.go
+9
-1
No files found.
builder/googlecompute/config.go
View file @
944d0e2e
...
@@ -16,25 +16,26 @@ import (
...
@@ -16,25 +16,26 @@ import (
type
Config
struct
{
type
Config
struct
{
common
.
PackerConfig
`mapstructure:",squash"`
common
.
PackerConfig
`mapstructure:",squash"`
BucketName
string
`mapstructure:"bucket_name"`
BucketName
string
`mapstructure:"bucket_name"`
ClientSecretsFile
string
`mapstructure:"client_secrets_file"`
ClientSecretsFile
string
`mapstructure:"client_secrets_file"`
DiskSizeGb
int64
`mapstructure:"disk_size"`
DiskSizeGb
int64
`mapstructure:"disk_size"`
ImageName
string
`mapstructure:"image_name"`
ImageName
string
`mapstructure:"image_name"`
ImageDescription
string
`mapstructure:"image_description"`
ImageDescription
string
`mapstructure:"image_description"`
InstanceName
string
`mapstructure:"instance_name"`
InstanceName
string
`mapstructure:"instance_name"`
MachineType
string
`mapstructure:"machine_type"`
MachineType
string
`mapstructure:"machine_type"`
Metadata
map
[
string
]
string
`mapstructure:"metadata"`
Metadata
map
[
string
]
string
`mapstructure:"metadata"`
Network
string
`mapstructure:"network"`
Network
string
`mapstructure:"network"`
Passphrase
string
`mapstructure:"passphrase"`
Passphrase
string
`mapstructure:"passphrase"`
PrivateKeyFile
string
`mapstructure:"private_key_file"`
PrivateKeyFile
string
`mapstructure:"private_key_file"`
ProjectId
string
`mapstructure:"project_id"`
ProjectId
string
`mapstructure:"project_id"`
SourceImage
string
`mapstructure:"source_image"`
SourceImage
string
`mapstructure:"source_image"`
SSHUsername
string
`mapstructure:"ssh_username"`
SourceImageProjectId
string
`mapstructure:"source_image_project_id"`
SSHPort
uint
`mapstructure:"ssh_port"`
SSHUsername
string
`mapstructure:"ssh_username"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
SSHPort
uint
`mapstructure:"ssh_port"`
RawStateTimeout
string
`mapstructure:"state_timeout"`
RawSSHTimeout
string
`mapstructure:"ssh_timeout"`
Tags
[]
string
`mapstructure:"tags"`
RawStateTimeout
string
`mapstructure:"state_timeout"`
Zone
string
`mapstructure:"zone"`
Tags
[]
string
`mapstructure:"tags"`
Zone
string
`mapstructure:"zone"`
clientSecrets
*
clientSecrets
clientSecrets
*
clientSecrets
instanceName
string
instanceName
string
...
@@ -103,21 +104,22 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
...
@@ -103,21 +104,22 @@ func NewConfig(raws ...interface{}) (*Config, []string, error) {
// Process Templates
// Process Templates
templates
:=
map
[
string
]
*
string
{
templates
:=
map
[
string
]
*
string
{
"bucket_name"
:
&
c
.
BucketName
,
"bucket_name"
:
&
c
.
BucketName
,
"client_secrets_file"
:
&
c
.
ClientSecretsFile
,
"client_secrets_file"
:
&
c
.
ClientSecretsFile
,
"image_name"
:
&
c
.
ImageName
,
"image_name"
:
&
c
.
ImageName
,
"image_description"
:
&
c
.
ImageDescription
,
"image_description"
:
&
c
.
ImageDescription
,
"instance_name"
:
&
c
.
InstanceName
,
"instance_name"
:
&
c
.
InstanceName
,
"machine_type"
:
&
c
.
MachineType
,
"machine_type"
:
&
c
.
MachineType
,
"network"
:
&
c
.
Network
,
"network"
:
&
c
.
Network
,
"passphrase"
:
&
c
.
Passphrase
,
"passphrase"
:
&
c
.
Passphrase
,
"private_key_file"
:
&
c
.
PrivateKeyFile
,
"private_key_file"
:
&
c
.
PrivateKeyFile
,
"project_id"
:
&
c
.
ProjectId
,
"project_id"
:
&
c
.
ProjectId
,
"source_image"
:
&
c
.
SourceImage
,
"source_image"
:
&
c
.
SourceImage
,
"ssh_username"
:
&
c
.
SSHUsername
,
"source_image_project_id"
:
&
c
.
SourceImageProjectId
,
"ssh_timeout"
:
&
c
.
RawSSHTimeout
,
"ssh_username"
:
&
c
.
SSHUsername
,
"state_timeout"
:
&
c
.
RawStateTimeout
,
"ssh_timeout"
:
&
c
.
RawSSHTimeout
,
"zone"
:
&
c
.
Zone
,
"state_timeout"
:
&
c
.
RawStateTimeout
,
"zone"
:
&
c
.
Zone
,
}
}
for
n
,
ptr
:=
range
templates
{
for
n
,
ptr
:=
range
templates
{
...
...
builder/googlecompute/driver.go
View file @
944d0e2e
...
@@ -23,10 +23,15 @@ type Driver interface {
...
@@ -23,10 +23,15 @@ type Driver interface {
WaitForInstance
(
state
,
zone
,
name
string
)
<-
chan
error
WaitForInstance
(
state
,
zone
,
name
string
)
<-
chan
error
}
}
type
Image
struct
{
Name
string
ProjectId
string
}
type
InstanceConfig
struct
{
type
InstanceConfig
struct
{
Description
string
Description
string
DiskSizeGb
int64
DiskSizeGb
int64
Image
string
Image
Image
MachineType
string
MachineType
string
Metadata
map
[
string
]
string
Metadata
map
[
string
]
string
Name
string
Name
string
...
...
builder/googlecompute/driver_gce.go
View file @
944d0e2e
...
@@ -134,7 +134,7 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
...
@@ -134,7 +134,7 @@ func (d *driverGCE) RunInstance(c *InstanceConfig) (<-chan error, error) {
}
}
// Get the image
// Get the image
d
.
ui
.
Message
(
fmt
.
Sprintf
(
"Loading image: %s
"
,
c
.
Image
))
d
.
ui
.
Message
(
fmt
.
Sprintf
(
"Loading image: %s
in project %s"
,
c
.
Image
.
Name
,
c
.
Image
.
ProjectId
))
image
,
err
:=
d
.
getImage
(
c
.
Image
)
image
,
err
:=
d
.
getImage
(
c
.
Image
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
...
@@ -229,17 +229,17 @@ func (d *driverGCE) WaitForInstance(state, zone, name string) <-chan error {
...
@@ -229,17 +229,17 @@ func (d *driverGCE) WaitForInstance(state, zone, name string) <-chan error {
return
errCh
return
errCh
}
}
func
(
d
*
driverGCE
)
getImage
(
name
string
)
(
image
*
compute
.
Image
,
err
error
)
{
func
(
d
*
driverGCE
)
getImage
(
img
Image
)
(
image
*
compute
.
Image
,
err
error
)
{
projects
:=
[]
string
{
d
.
p
rojectId
,
"centos-cloud"
,
"coreos-cloud"
,
"debian-cloud"
,
"google-containers"
,
"opensuse-cloud"
,
"rhel-cloud"
,
"suse-cloud"
,
"windows-cloud"
}
projects
:=
[]
string
{
img
.
P
rojectId
,
"centos-cloud"
,
"coreos-cloud"
,
"debian-cloud"
,
"google-containers"
,
"opensuse-cloud"
,
"rhel-cloud"
,
"suse-cloud"
,
"windows-cloud"
}
for
_
,
project
:=
range
projects
{
for
_
,
project
:=
range
projects
{
image
,
err
=
d
.
service
.
Images
.
Get
(
project
,
n
ame
)
.
Do
()
image
,
err
=
d
.
service
.
Images
.
Get
(
project
,
img
.
N
ame
)
.
Do
()
if
err
==
nil
&&
image
!=
nil
&&
image
.
SelfLink
!=
""
{
if
err
==
nil
&&
image
!=
nil
&&
image
.
SelfLink
!=
""
{
return
return
}
}
image
=
nil
image
=
nil
}
}
err
=
fmt
.
Errorf
(
"Image %s could not be found in any of these projects: %s"
,
n
ame
,
projects
)
err
=
fmt
.
Errorf
(
"Image %s could not be found in any of these projects: %s"
,
img
.
N
ame
,
projects
)
return
return
}
}
...
...
builder/googlecompute/step_create_instance.go
View file @
944d0e2e
...
@@ -16,6 +16,14 @@ type StepCreateInstance struct {
...
@@ -16,6 +16,14 @@ type StepCreateInstance struct {
instanceName
string
instanceName
string
}
}
func
(
config
*
Config
)
getImage
()
(
Image
)
{
project
:=
config
.
ProjectId
if
config
.
SourceImageProjectId
!=
""
{
project
=
config
.
SourceImageProjectId
}
return
Image
{
Name
:
config
.
SourceImage
,
ProjectId
:
project
}
}
// Run executes the Packer build step that creates a GCE instance.
// Run executes the Packer build step that creates a GCE instance.
func
(
s
*
StepCreateInstance
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
func
(
s
*
StepCreateInstance
)
Run
(
state
multistep
.
StateBag
)
multistep
.
StepAction
{
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
config
:=
state
.
Get
(
"config"
)
.
(
*
Config
)
...
@@ -29,7 +37,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
...
@@ -29,7 +37,7 @@ func (s *StepCreateInstance) Run(state multistep.StateBag) multistep.StepAction
errCh
,
err
:=
driver
.
RunInstance
(
&
InstanceConfig
{
errCh
,
err
:=
driver
.
RunInstance
(
&
InstanceConfig
{
Description
:
"New instance created by Packer"
,
Description
:
"New instance created by Packer"
,
DiskSizeGb
:
config
.
DiskSizeGb
,
DiskSizeGb
:
config
.
DiskSizeGb
,
Image
:
config
.
SourceImage
,
Image
:
config
.
getImage
()
,
MachineType
:
config
.
MachineType
,
MachineType
:
config
.
MachineType
,
Metadata
:
map
[
string
]
string
{
Metadata
:
map
[
string
]
string
{
"sshKeys"
:
fmt
.
Sprintf
(
"%s:%s"
,
config
.
SSHUsername
,
sshPublicKey
),
"sshKeys"
:
fmt
.
Sprintf
(
"%s:%s"
,
config
.
SSHUsername
,
sshPublicKey
),
...
...
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