diff --git a/files/porter_bootstrap b/files/porter_bootstrap index 6187d57..436df4b 100644 --- a/files/porter_bootstrap +++ b/files/porter_bootstrap @@ -1,4 +1,4 @@ -#!/bin/bash -ex +#!/bin/bash -e{{ if .LogDebug -}}x{{- end }} echo "porter bootstrap BEGIN" export PORTER_VERSION={{ .PorterVersion }} diff --git a/files/porter_hotswap b/files/porter_hotswap index 86e008b..a020066 100644 --- a/files/porter_hotswap +++ b/files/porter_hotswap @@ -4,7 +4,7 @@ aws s3 cp s3://{{ .ServicePayloadBucket }}/{{ .ServicePayloadKey }} payload.tar # load all the containers in this tar echo "loading containers" {{ range $imageName := .ImageNames -}} -tar -xOf /payload.tar ./{{ $imageName }}.docker | docker load +tar -xOf payload.tar ./{{ $imageName }}.docker | docker load {{ end -}} echo "starting containers" diff --git a/hook/hook.go b/hook/hook.go index b535ed6..766f2f1 100644 --- a/hook/hook.go +++ b/hook/hook.go @@ -18,6 +18,7 @@ import ( "os/exec" "path" "strings" + "sync/atomic" "github.com/adobe-platform/porter/aws/elb" "github.com/adobe-platform/porter/aws_session" @@ -37,6 +38,10 @@ type ( } ) +// Multi-region deployment means we need an additional unique id for git clones +// and image names +var globalCounter *uint32 = new(uint32) + func newOpts() *Opts { return &Opts{ BuildStdout: os.Stdout, @@ -140,8 +145,6 @@ func Execute(log log15.Logger, return } - log := log.New("Region", region.Name) - roleARN, err := env.GetRoleARN(region.Name) if err != nil { log.Error("GetRoleARN", "Error", err) @@ -337,16 +340,16 @@ func runConfigHook(log log15.Logger, config conf.Config, hookName string, } dockerFilePath := hook.Dockerfile + hookCounter := atomic.AddUint32(globalCounter, 1) if hook.Repo != "" { - repoDir := fmt.Sprintf("%s-clone-%d", hookName, hookIndex) + repoDir := fmt.Sprintf("%s_clone_%d_%d", hookName, hookIndex, hookCounter) repoDir = path.Join(constants.TempDir, repoDir) - defer func() { - exec.Command("rm", "-fr", repoDir).Run() - }() - log.Info("Cloning", + defer exec.Command("rm", "-fr", repoDir).Run() + + log.Info("git clone", "Repo", hook.Repo, "Ref", hook.Ref, "Directory", repoDir, @@ -365,7 +368,8 @@ func runConfigHook(log log15.Logger, config conf.Config, hookName string, return } - // TODO do this in conf.SetDefaults() + // Validation ensures that local hooks have a dockerfile path + // Plugins default to Dockerfile if dockerFilePath == "" { dockerFilePath = "Dockerfile" } @@ -373,7 +377,7 @@ func runConfigHook(log log15.Logger, config conf.Config, hookName string, dockerFilePath = path.Join(repoDir, dockerFilePath) } - imageName := fmt.Sprintf("%s-%s-%d", config.ServiceName, hookName, hookIndex) + imageName := fmt.Sprintf("%s-%s-%d-%d", config.ServiceName, hookName, hookIndex, hookCounter) if !buildAndRun(log, imageName, dockerFilePath, runArgs, opts) { return @@ -386,6 +390,12 @@ func runConfigHook(log log15.Logger, config conf.Config, hookName string, func buildAndRun(log log15.Logger, imageName, dockerFilePath string, runArgs []string, opts *Opts) (success bool) { + log = log.New("Dockerfile", dockerFilePath, "ImageName", imageName) + + log.Debug("buildAndRun() BEGIN") + defer log.Debug("buildAndRun() END") + log.Info("docker build") + dockerBuildCmd := exec.Command("docker", "build", "-t", imageName, "-f", dockerFilePath, @@ -406,6 +416,8 @@ func buildAndRun(log log15.Logger, imageName, dockerFilePath string, runCmd.Stdout = opts.RunStdout runCmd.Stderr = opts.RunStderr + log.Debug("docker run", "Args", runArgs) + err = runCmd.Run() if err != nil { log.Error("docker run", "Error", err) diff --git a/testintegration/.porter/config b/testintegration/.porter/config index f194984..cae56f3 100644 --- a/testintegration/.porter/config +++ b/testintegration/.porter/config @@ -47,6 +47,15 @@ hooks: environment: DEV_MODE: FOO: bar + concurrent: true + - repo: $TEST_REPO_URL + ref: $TEST_REPO_BRANCH + dockerfile: testintegration/plugins/ec2-bootstrap + concurrent: true + - repo: $TEST_REPO_URL + ref: $TEST_REPO_BRANCH + dockerfile: testintegration/plugins/ec2-bootstrap + concurrent: true _container_base_inet: &CONTAINER_BASE_INET name: inet diff --git a/testintegration/Dockerfile b/testintegration/Dockerfile new file mode 100644 index 0000000..81948ad --- /dev/null +++ b/testintegration/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:16.04 + +ADD ec2-bootstrap.cmd / +RUN chmod 544 /ec2-bootstrap.cmd + +# TODO generate config +CMD /ec2-bootstrap.cmd diff --git a/testintegration/Dockerfile.cmd b/testintegration/Dockerfile.cmd new file mode 100644 index 0000000..b3088ce --- /dev/null +++ b/testintegration/Dockerfile.cmd @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "DEV_MODE $DEV_MODE" 1>&2 diff --git a/testintegration/hooks/ec2-bootstrap.cmd b/testintegration/hooks/ec2-bootstrap.cmd index ffb619e..b3088ce 100644 --- a/testintegration/hooks/ec2-bootstrap.cmd +++ b/testintegration/hooks/ec2-bootstrap.cmd @@ -1,3 +1,3 @@ -#!/bin/bash -x +#!/bin/bash echo "DEV_MODE $DEV_MODE" 1>&2 diff --git a/testintegration/plugins/ec2-bootstrap b/testintegration/plugins/ec2-bootstrap new file mode 100644 index 0000000..81948ad --- /dev/null +++ b/testintegration/plugins/ec2-bootstrap @@ -0,0 +1,7 @@ +FROM ubuntu:16.04 + +ADD ec2-bootstrap.cmd / +RUN chmod 544 /ec2-bootstrap.cmd + +# TODO generate config +CMD /ec2-bootstrap.cmd diff --git a/testintegration/plugins/ec2-bootstrap.cmd b/testintegration/plugins/ec2-bootstrap.cmd new file mode 100644 index 0000000..b3088ce --- /dev/null +++ b/testintegration/plugins/ec2-bootstrap.cmd @@ -0,0 +1,3 @@ +#!/bin/bash + +echo "DEV_MODE $DEV_MODE" 1>&2