Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix ancient Vagrantfile & fix imports #18

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: go
go:
- 1.9
- 1.9.2
- tip
cache:
directories:
Expand Down
22 changes: 16 additions & 6 deletions Gopkg.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

# Gopkg.toml example
#
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
Expand All @@ -17,16 +16,27 @@
# source = "github.com/myfork/project2"
#
# [[override]]
# name = "github.com/x/y"
# version = "2.4.0"
# name = "github.com/x/y"
# version = "2.4.0"
#
# [prune]
# non-go = false
# go-tests = true
# unused-packages = true


[[constraint]]
name = "github.com/mitchellh/multistep"
name = "github.com/hashicorp/packer"
version = "1.2.2"

[[constraint]]
name = "github.com/mitchellh/packer"
version = "0.10.2"
name = "github.com/watson-platform/packer-builder-softlayer"
version = "1.0.1"

[[constraint]]
branch = "master"
name = "golang.org/x/crypto"

[prune]
go-tests = true
unused-packages = true
74 changes: 46 additions & 28 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :
# Original version of this file copied from: https://raw.githubusercontent.com/mitchellh/packer/master/Vagrantfile
# Original version of this file copied from: https://raw.githubusercontent.com/hashicorp/packer/master/Vagrantfile
#

# VM Specifications
Expand All @@ -11,60 +11,78 @@ VM_GUI=false
GOROOT = '/opt/go'
GOPATH = '/opt/gopath'
PACKAGE_PATH = 'src/github.com/watson-platform/packer-builder-softlayer'
GO_VERSION = '1.9.2'

script = <<SCRIPT
set -x

SRCROOT="#{GOROOT}"

# Install Go
sudo apt-get update
sudo apt-get install -y build-essential mercurial
sudo hg clone -u release https://code.google.com/p/go $SRCROOT
cd ${SRCROOT}/src
sudo ./all.bash

# Setup the GOPATH
sudo mkdir -p #{GOPATH}
cat <<EOF >/tmp/gopath.sh

download="https://storage.googleapis.com/golang/go#{GO_VERSION}.linux-amd64.tar.gz"

wget -q -O /tmp/go.tar.gz ${download}

tar -C /tmp -xf /tmp/go.tar.gz
sudo mv /tmp/go /usr/local
sudo chown -R root:root /usr/local/go

# Ensure that the GOPATH tree is owned by vagrant:vagrant
mkdir -p #{GOPATH}
sudo chown -R vagrant:vagrant #{GOPATH}
sudo chown -R -f vagrant:vagrant $SRCROOT

# Ensure Go is on PATH
if [ ! -e /usr/bin/go ] ; then
ln -s /usr/local/go/bin/go /usr/bin/go
fi
if [ ! -e /usr/bin/gofmt ] ; then
ln -s /usr/local/go/bin/gofmt /usr/bin/gofmt
fi


# Ensure new sessions know about GOPATH
if [ ! -f /etc/profile.d/gopath.sh ] ; then
cat <<EOT > /etc/profile.d/gopath.sh
export GOPATH="#{GOPATH}"
export PATH="#{GOROOT}/bin:\\$GOPATH/bin:\\$PATH"
export SL_USERNAME=#{ENV['SL_USERNAME']}
export SL_API_KEY=#{ENV['SL_API_KEY']}
EOF
sudo mv /tmp/gopath.sh /etc/profile.d/gopath.sh
sudo chmod 0755 /etc/profile.d/gopath.sh
export PATH="#{GOPATH}/bin:\$PATH"
EOT

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

EOT?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a heredoc for adding that text to gopath.sh

chmod 755 /etc/profile.d/gopath.sh
fi

source /etc/profile.d/gopath.sh


# Install some other stuff we need
sudo apt-get install -y curl git-core zip
sudo apt-get update && sudo apt-get install -y curl git-core zip build-essential

# Download and build Packer
source /etc/profile.d/gopath.sh
go get -u github.com/mitchellh/gox
gox -build-toolchain
go get -d -u github.com/mitchellh/packer
cd $GOPATH/src/github.com/mitchellh/packer
make updatedeps
# These next two lines cause duplicate files in $GOPATH/bin
go get -d -u github.com/hashicorp/packer
cd $GOPATH/src/github.com/hashicorp/packer
make
make dev

# Build packer-builder-softlayer
cd $GOPATH/#{PACKAGE_PATH}
curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh
dep ensure
go build
go test ./...
go install

# Make sure the gopath is usable by vagrant
sudo chown -R -f vagrant:vagrant $SRCROOT
sudo chown -R -f vagrant:vagrant #{GOPATH}
# Ensure vagrant still owns the GOPATH
sudo chown -R vagrant:vagrant #{GOPATH}

echo "Ready for development. Begin with cd $GOPATH/#{PACKAGE_PATH}"

SCRIPT

Vagrant.configure(2) do |config|
config.vm.box = "chef/ubuntu-12.04"
config.vm.box = "ubuntu/trusty64"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use generic/ubuntu1604 instead since it supports more providers?


config.vm.synced_folder '.', "#{GOPATH}/#{PACKAGE_PATH}", id: 'src'
config.vm.synced_folder '.', "#{GOPATH}/#{PACKAGE_PATH}", id: 'src'

config.vm.provision 'shell', inline: script

Expand Down
16 changes: 8 additions & 8 deletions builder/softlayer/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ package softlayer
import (
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common"
"github.com/mitchellh/packer/helper/communicator"
"github.com/mitchellh/packer/helper/config"
"github.com/mitchellh/packer/packer"
"github.com/mitchellh/packer/template/interpolate"
"github.com/hashicorp/packer/common"
"github.com/hashicorp/packer/helper/communicator"
"github.com/hashicorp/packer/helper/config"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"github.com/hashicorp/packer/template/interpolate"
"log"
"os"
"time"
Expand Down Expand Up @@ -38,8 +38,8 @@ type Config struct {
InstanceNetworkSpeed int `mapstructure:"instance_network_speed"`
InstanceDiskCapacities []int `mapstructure:"instance_disk_capacities"`

RawStateTimeout string `mapstructure:"instance_state_timeout"`
StateTimeout time.Duration
RawStateTimeout string `mapstructure:"instance_state_timeout"`
StateTimeout time.Duration

ctx interpolate.Context
}
Expand Down
3 changes: 2 additions & 1 deletion builder/softlayer/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package softlayer
import (
"errors"
"fmt"
"github.com/mitchellh/multistep"
"github.com/hashicorp/packer/helper/multistep"
"golang.org/x/crypto/ssh"
)

Expand Down Expand Up @@ -42,5 +42,6 @@ func sshConfig(state multistep.StateBag) (*ssh.ClientConfig, error) {
Auth: []ssh.AuthMethod{
ssh.PublicKeys(signer),
},
HostKeyCallback: ssh.InsecureIgnoreHostKey(),
}, nil
}
7 changes: 4 additions & 3 deletions builder/softlayer/step_capture_image.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package softlayer

import (
"context"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)

type stepCaptureImage struct{}

func (self *stepCaptureImage) Run(state multistep.StateBag) multistep.StepAction {
func (self *stepCaptureImage) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*SoftlayerClient)
ui := state.Get("ui").(packer.Ui)
instance := state.Get("instance_data").(map[string]interface{})
Expand Down
29 changes: 15 additions & 14 deletions builder/softlayer/step_create_instance.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
package softlayer

import (
"context"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"log"
)

type stepCreateInstance struct {
instanceId string
}

func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepAction {
func (self *stepCreateInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*SoftlayerClient)
config := state.Get("config").(Config)
ui := state.Get("ui").(packer.Ui)
Expand All @@ -24,19 +25,19 @@ func (self *stepCreateInstance) Run(state multistep.StateBag) multistep.StepActi
}

instanceDefinition := &InstanceType{
HostName: config.InstanceName,
Domain: config.InstanceDomain,
Datacenter: config.DatacenterName,
Cpus: config.InstanceCpu,
Memory: config.InstanceMemory,
HourlyBillingFlag: true,
LocalDiskFlag: true,
HostName: config.InstanceName,
Domain: config.InstanceDomain,
Datacenter: config.DatacenterName,
Cpus: config.InstanceCpu,
Memory: config.InstanceMemory,
HourlyBillingFlag: true,
LocalDiskFlag: true,
PrivateNetworkOnlyFlag: config.PrivateNetworkOnlyFlag,
DiskCapacities: config.InstanceDiskCapacities,
NetworkSpeed: config.InstanceNetworkSpeed,
ProvisioningSshKeyId: ProvisioningSshKeyId,
BaseImageId: config.BaseImageId,
BaseOsCode: config.BaseOsCode,
NetworkSpeed: config.InstanceNetworkSpeed,
ProvisioningSshKeyId: ProvisioningSshKeyId,
BaseImageId: config.BaseImageId,
BaseOsCode: config.BaseOsCode,
}

ui.Say("Creating an instance...")
Expand Down
9 changes: 5 additions & 4 deletions builder/softlayer/step_create_ssh_key.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package softlayer

import (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/pem"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/common/uuid"
"github.com/mitchellh/packer/packer"
"github.com/hashicorp/packer/common/uuid"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
"golang.org/x/crypto/ssh"
"io/ioutil"
"log"
Expand All @@ -20,7 +21,7 @@ type stepCreateSshKey struct {
PrivateKeyFile string
}

func (self *stepCreateSshKey) Run(state multistep.StateBag) multistep.StepAction {
func (self *stepCreateSshKey) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
ui := state.Get("ui").(packer.Ui)
if self.PrivateKeyFile != "" {
ui.Say(fmt.Sprintf("Reading private key file (%s)...", self.PrivateKeyFile))
Expand Down
7 changes: 4 additions & 3 deletions builder/softlayer/step_waitfor_instance.go
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package softlayer

import (
"context"
"fmt"
"github.com/mitchellh/multistep"
"github.com/mitchellh/packer/packer"
"github.com/hashicorp/packer/helper/multistep"
"github.com/hashicorp/packer/packer"
)

type stepWaitforInstance struct{}

func (self *stepWaitforInstance) Run(state multistep.StateBag) multistep.StepAction {
func (self *stepWaitforInstance) Run(_ context.Context, state multistep.StateBag) multistep.StepAction {
client := state.Get("client").(*SoftlayerClient)
config := state.Get("config").(Config)
ui := state.Get("ui").(packer.Ui)
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package main

import (
"github.com/hashicorp/packer/packer/plugin"
"github.com/watson-platform/packer-builder-softlayer/builder/softlayer"
"github.com/mitchellh/packer/packer/plugin"
)

func main() {
Expand Down
2 changes: 1 addition & 1 deletion script/test
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ set -euo pipefail
source "$(dirname "$0")/utilities.bash"

header "Tests"
go test $(glide novendor)
go test $(go list | grep -v vendor)

header "Linter"
gometalinter --deadline=2m --vendored-linters --vendor --disable=gotype
Expand Down