From cd93c1f4da37582a9ec7b3b5bfaa56771dd904c5 Mon Sep 17 00:00:00 2001 From: Tim Gross Date: Thu, 20 Aug 2020 16:10:00 -0400 Subject: [PATCH] E2E: move Nomad installation to script on remote hosts (#8706) This changeset moves the installation of Nomad binaries out of the provisioning framework and into scripts that are installed on the remote host during AMI builds. This provides a few advantages: * The provisioning framework can be reduced in scope (with the goal of moving most of it into the Terraform stack entirely). * The scripts can be arbitrarily complex if we don't have to stuff them into ssh commands, so it's easier to make them idempotent. In this changeset, the scripts check the version of the existing binary and don't re-download when using the `--nomad_sha` or `--nomad_version` flags. * The scripts can be OS/distro specific, which helps in building new test targets. --- e2e/framework/provisioning/deploy.go | 57 +----- e2e/terraform/packer/linux/install-nomad | 103 ++++++++++ e2e/terraform/packer/linux/setup.sh | 12 +- e2e/terraform/packer/packer-windows.json | 14 +- e2e/terraform/packer/packer.json | 5 + .../packer/windows/install-nomad.ps1 | 178 +++++++++++++++--- 6 files changed, 289 insertions(+), 80 deletions(-) create mode 100755 e2e/terraform/packer/linux/install-nomad diff --git a/e2e/framework/provisioning/deploy.go b/e2e/framework/provisioning/deploy.go index 8fae45000..479e4ad7d 100644 --- a/e2e/framework/provisioning/deploy.go +++ b/e2e/framework/provisioning/deploy.go @@ -2,7 +2,6 @@ package provisioning import ( "fmt" - "path/filepath" "testing" ) @@ -38,35 +37,15 @@ func deployLinux(t *testing.T, target *ProvisioningTarget) error { return fmt.Errorf("copying Nomad failed: %v", err) } } else if deployment.NomadSha != "" { - if deployment.RemoteBinaryPath == "" { - return fmt.Errorf("remote binary path not set") - } - s3_url := fmt.Sprintf("s3://nomad-team-dev-test-binaries/builds-oss/nomad_%s_%s.tar.gz", - deployment.Platform, deployment.NomadSha, - ) - remoteDir := filepath.Dir(deployment.RemoteBinaryPath) - script := fmt.Sprintf(`aws s3 cp --quiet %s nomad.tar.gz - sudo tar -zxvf nomad.tar.gz -C %s - sudo chmod 0755 %s - sudo chown root:root %s`, - s3_url, remoteDir, deployment.RemoteBinaryPath, deployment.RemoteBinaryPath) + script := fmt.Sprintf( + `/opt/install-nomad --nomad_sha %s --nostart`, deployment.NomadSha) err = runner.Run(script) if err != nil { return err } } else if deployment.NomadVersion != "" { - if deployment.RemoteBinaryPath == "" { - return fmt.Errorf("remote binary path not set") - } - url := fmt.Sprintf("https://releases.hashicorp.com/nomad/%s/nomad_%s_%s.zip", - deployment.NomadVersion, deployment.NomadVersion, deployment.Platform, - ) - remoteDir := filepath.Dir(deployment.RemoteBinaryPath) - script := fmt.Sprintf(`curl -L --fail -o /tmp/nomad.zip %s - sudo unzip -o /tmp/nomad.zip -d %s - sudo chmod 0755 %s - sudo chown root:root %s`, - url, remoteDir, deployment.RemoteBinaryPath, deployment.RemoteBinaryPath) + script := fmt.Sprintf( + `/opt/install-nomad --nomad_version %s --nostart`, deployment.NomadVersion) err = runner.Run(script) if err != nil { return err @@ -82,6 +61,7 @@ func deployLinux(t *testing.T, target *ProvisioningTarget) error { return fmt.Errorf("copying bundle '%s' failed: %v", bundle.Source, err) } } + for _, step := range deployment.Steps { err = runner.Run(step) if err != nil { @@ -115,33 +95,15 @@ func deployWindows(t *testing.T, target *ProvisioningTarget) error { return fmt.Errorf("copying Nomad failed: %v", err) } } else if deployment.NomadSha != "" { - if deployment.RemoteBinaryPath == "" { - return fmt.Errorf("remote binary path not set") - } - script := fmt.Sprintf(` - Read-S3Object -BucketName nomad-team-dev-test-binaries -Key "builds-oss/nomad_windows_amd64_%s.zip" -File ./nomad.zip - Expand-Archive ./nomad.zip ./ -Force - Remove-Item %s -ErrorAction Ignore - Move-Item -Path .\pkg\windows_amd64\nomad.exe -Destination %s -Force`, - deployment.NomadSha, deployment.RemoteBinaryPath, - deployment.RemoteBinaryPath) + script := fmt.Sprintf( + `C:/opt/install-nomad.ps1 -nomad_sha %s -nostart`, deployment.NomadSha) err = runner.Run(script) if err != nil { return err } } else if deployment.NomadVersion != "" { - if deployment.RemoteBinaryPath == "" { - return fmt.Errorf("remote binary path not set") - } - url := fmt.Sprintf("https://releases.hashicorp.com/nomad/%s/nomad_%s_%s.zip", - deployment.NomadVersion, deployment.NomadVersion, deployment.Platform, - ) - script := fmt.Sprintf(` - Invoke-WebRequest -Uri "%s" -Outfile /.nomad.zip - Expand-Archive ./nomad.zip ./ -Force - Remove-Item %s -ErrorAction Ignore - Move-Item -Path .\pkg\windows_amd64\nomad.exe -Destination %s -Force`, - url, deployment.RemoteBinaryPath, deployment.RemoteBinaryPath) + script := fmt.Sprintf( + `C:/opt/install-nomad.ps1 -nomad_version %s -nostart`, deployment.NomadVersion) err = runner.Run(script) if err != nil { return err @@ -157,6 +119,7 @@ func deployWindows(t *testing.T, target *ProvisioningTarget) error { return fmt.Errorf("copying bundle '%s' failed: %v", bundle.Source, err) } } + for _, step := range deployment.Steps { err = runner.Run(step) if err != nil { diff --git a/e2e/terraform/packer/linux/install-nomad b/e2e/terraform/packer/linux/install-nomad new file mode 100755 index 000000000..b9fe8b292 --- /dev/null +++ b/e2e/terraform/packer/linux/install-nomad @@ -0,0 +1,103 @@ +#!/bin/bash + +set -o errexit +set -o nounset +set +x + +usage() { + cat <