packer-cn/scripts
Megan Marsh f12269f124
fix builds on linux (#9031)
* fix builds on linux

* Build: Move to CGO_ENABLED=0 (#9057)

After further investigation on cross-compiling Go bins on Linux. I found
that statically linking against GCC (for libc) failed to build for ARM
and introduced a possible licensing issue as our bins would essentially
be bundling libc into the bin. Diving further into cross compiling on Linux
I found that the defacto solution is to compile with CGO disabled - this
was also found to be the case for other HashiCorp products.

Disabling CGO has the limitation of not allowing the use of any pkg that
calls out to C (net, os), but in looking into the Packer code base and
the relevant Go code base it appears that the latest versions of Go have
pure Go implementations of the said packages so I believe we are good to
go. I should also point out that CGO is disabled by default when cross
compiling via `go build`. However, the GOX tool will enable it if it is
not explicitly disabled.

Below are three test cases executed to validate the compile bins work as
expected.

Build results after change
```
⇶  make bin
WARN: 'make bin' is for debug / test builds only. Use 'make release' for
release builds.
==> Checking for necessary tools...
==> Entering Packer source dir...
==> Ensuring output directories are present...
==> Removing old builds...
==> Building...
Number of parallel builds: 7

-->   windows/amd64: github.com/hashicorp/packer
-->     linux/arm64: github.com/hashicorp/packer
-->       linux/386: github.com/hashicorp/packer
-->       linux/arm: github.com/hashicorp/packer
-->    darwin/amd64: github.com/hashicorp/packer
-->     windows/386: github.com/hashicorp/packer
-->     linux/amd64: github.com/hashicorp/packer
-->      darwin/386: github.com/hashicorp/packer
==> Copying binaries for this platform...
'./pkg/linux_amd64/packer' -> 'bin/packer'
'./pkg/linux_amd64/packer' -> '/home/wilken/Development/go/bin/packer'

==> Results:
total 111M
-rwxr-xr-x 1 wilken wilken 111M Apr 13 12:29 packer
```

Packer executed on ARM based machine
```
ubuntu@ip-172-31-10-18:~$ ./packer version
Packer v1.5.6-dev (314ac5b65+CHANGES

ubuntu@ip-172-31-10-18:~$ uname -a
Linux ip-172-31-10-18 4.15.0-1054-aws #56-Ubuntu SMP Thu Nov 7 16:18:50 UTC 2019 aarch64 aarch64 aarch64 GNU/Linux

ubuntu@ip-172-31-10-18:~$ ./packer build build.json
null: output will be in this color.

==> null: Running local shell script: /tmp/packer-shell170248556
    null: UUID from Packer: 79cc8532-6114-925d-2a79-33ef6ce281cd
Build 'null' finished.

==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder
```

Custom Docker image with updated bin
```
⇶  docker run packertest:latest version
Packer v1.5.6-dev (314ac5b65+CHANGES)

⇶  docker run packertest:latest build build.json
null: output will be in this color.

==> null: Running local shell script: /tmp/packer-shell065599452
    null: UUID from Packer: 852f0604-2be4-9e16-99af-6d7df972ac2e
Build 'null' finished.

==> Builds finished. The artifacts of successful builds are:
--> null: Did not export anything. This is the null builder
```

Windows AMI
```
[...]
==> amazon-ebs: Launching a source AWS instance...
==> amazon-ebs: Adding tags to source instance
    amazon-ebs: Adding tag: "Name": "Packer Builder"
    amazon-ebs: Instance ID: i-04387545cf3e2acd3
==> amazon-ebs: Waiting for instance (i-04387545cf3e2acd3) to become ready...
==> amazon-ebs: Skipping waiting for password since WinRM password set...
==> amazon-ebs: Using winrm communicator to connect: 18.206.100.104
==> amazon-ebs: Waiting for WinRM to become available...
    amazon-ebs: WinRM connected.
==> amazon-ebs: Connected to WinRM!
==> amazon-ebs: Uploading packertest => c:/Windows/Temp
==> amazon-ebs: Provisioning with Powershell...
==> amazon-ebs: Provisioning with powershell script: /tmp/powershell-provisioner173180945
    amazon-ebs: Packer v1.5.6-dev (314ac5b65+CHANGES)
    amazon-ebs: null: output will be in this color.
    amazon-ebs:
```

Co-authored-by: Wilken Rivera <dev@wilkenrivera.com>
2020-04-14 14:48:50 -04:00
..
build.ps1 refresh line endings 2019-05-17 14:58:20 -07:00
build.sh fix builds on linux (#9031) 2020-04-14 14:48:50 -04:00
codesign_example.sh Cut version 1.5.4 2020-02-14 16:14:01 -08:00
dist.sh Cut version 1.5.4 2020-02-14 16:14:01 -08:00
generate-plugins.go scripts/generate-plugins.go: programatically gofmt the file before outputing it to avoid having to do that later on 2020-03-17 11:56:32 +01:00
lint.sh circle-ci: update ci-lint steps (#9043) 2020-04-14 12:03:22 +02:00
off_gopath.sh change installation of pigeon if off gopath 2019-07-01 12:16:50 -07:00
prepare_changelog.sh scripts/prepare_changelog: Update unescape parenthesis for improved matching 2020-03-27 07:19:49 -04:00
sign.sh Cut version 1.5.4 2020-02-14 16:14:01 -08:00
sort-md-list.py comments 2017-06-05 12:56:46 -07:00
vagrant-freebsd-priv-config.sh vagrant: Correct name of vim package 2018-02-02 13:14:13 -06:00
vagrant-freebsd-unpriv-bootstrap.sh build: Allow multi-platform dev with Vagrantfile 2017-11-02 11:00:19 -07:00
vagrant-linux-priv-config.sh scripts: add gcc package for using gco on build 2018-10-31 16:58:07 +03:00
vagrant-linux-priv-go.sh scripts/vagrant: Update Vagrant bootstrapping scripts 2020-01-15 12:42:15 -05:00
vagrant-linux-unpriv-bootstrap.sh scripts/vagrant: Update Vagrant bootstrapping scripts 2020-01-15 12:42:15 -05:00