hashicorp / hc-install

Go module for downloading or locating HashiCorp binaries, verifying signatures and checksums, and asserting version constraints.
https://pkg.go.dev/github.com/hashicorp/hc-install
Mozilla Public License 2.0
50 stars 19 forks source link

cmd/hc-install: Enable logging into a file #193

Closed radeksimko closed 5 months ago

radeksimko commented 5 months ago

A few times in the past and recently I found myself struggling to answer some detailed questions about what exactly happens during the installation and why an installation may be failing.

I think opt-in logging can help understand what's going and aid debugging.

Example

$ go run ./cmd/hc-install install -log-file=/dev/stderr -version 1.0.0 terraform
hc-install: will install terraform@1.0.0
[DEBUG] 2024/04/04 10:25:18.133986 exact_version.go:103: will install into dir at /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install
[DEBUG] 2024/04/04 10:25:18.134274 releases.go:131: requesting version from https://releases.hashicorp.com/terraform/1.0.0/index.json
[DEBUG] 2024/04/04 10:25:18.223458 releases.go:154: received 200 OK
failed to install terraform@1.0.0: no ZIP archive found for terraform <nil> darwin/arm64
exit status 1
$ go run ./cmd/hc-install install -log-file=./foo.log -version 1.1.0 terraform
hc-install: will install terraform@1.1.0
installed terraform@1.1.0 to /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install/terraform

$ cat foo.log
[DEBUG] 2024/04/04 10:26:02.230453 exact_version.go:103: will install into dir at /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install
[DEBUG] 2024/04/04 10:26:02.230856 releases.go:131: requesting version from https://releases.hashicorp.com/terraform/1.1.0/index.json
[DEBUG] 2024/04/04 10:26:02.395232 releases.go:154: received 200 OK
[DEBUG] 2024/04/04 10:26:02.403076 checksum_downloader.go:60: downloading signature from https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_SHA256SUMS.72D7468F.sig
[DEBUG] 2024/04/04 10:26:02.484267 checksum_downloader.go:81: downloading checksums from https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_SHA256SUMS
[DEBUG] 2024/04/04 10:26:02.581662 checksum_downloader.go:149: checksum signature is valid
[DEBUG] 2024/04/04 10:26:02.581853 downloader.go:82: downloading archive from https://releases.hashicorp.com/terraform/1.1.0/terraform_1.1.0_darwin_arm64.zip
[DEBUG] 2024/04/04 10:26:02.667995 downloader.go:116: copying "terraform_1.1.0_darwin_arm64.zip" (19491369 bytes) to /var/folders/9w/pddq2x656j76vxvsbhcs4nwr0000gq/T/terraform_1.1.0_darwin_arm64.zip3633819228
[DEBUG] 2024/04/04 10:26:02.668127 downloader.go:120: verifying checksum of "terraform_1.1.0_darwin_arm64.zip"
[DEBUG] 2024/04/04 10:26:03.345805 downloader.go:143: copied 19491369 bytes to /var/folders/9w/pddq2x656j76vxvsbhcs4nwr0000gq/T/terraform_1.1.0_darwin_arm64.zip3633819228
[DEBUG] 2024/04/04 10:26:03.346679 downloader.go:175: unpacking terraform to /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install
[DEBUG] 2024/04/04 10:26:03.657731 exact_version.go:148: changing perms of /Users/radeksimko/gopath/src/github.com/hashicorp/hc-install/terraform
radeksimko commented 5 months ago

I think it would be a good idea to consider a -log-stdout flag too, what do you think?

I don't disagree but I think it's basically a syntactic sugar at this point. We already allow logging to stdout or stderr, as shown in the example above with /dev/stderr - similar one can be crafted with /dev/stdout.

It is true though that this may not be as obvious to people and also that this may only work on Unix based systems.

All that said - I think we can still introduce this flag in a separate PR.