From 13ff6080022f1deba554dadf774be81b7d533bb8 Mon Sep 17 00:00:00 2001 From: Matthieu Vachon Date: Wed, 10 May 2023 20:44:53 -0400 Subject: [PATCH] Added checks that `docker` CLI exists and also that `docker info` works properly --- CHANGELOG.md | 4 ++++ cmd/sfreleaser/main.go | 15 +++++++++++++++ cmd/sfreleaser/release.go | 40 ++++++++++++++++++++++++++++++--------- 3 files changed, 50 insertions(+), 9 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 18c4b18..f201153 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## v0.4.1 + +* Added checks that `docker` CLI exists and also that `docker info` works properly. + ## v0.4.0 * Added full `CGO` support when building Go application/library, `.goreleaser.yaml` file now has `C_INCLUDE_PATH` and `LIBRARY_PATH` sets correctly so it's possible to build Go that depends on C libraries. diff --git a/cmd/sfreleaser/main.go b/cmd/sfreleaser/main.go index f1d5a84..19e16f1 100644 --- a/cmd/sfreleaser/main.go +++ b/cmd/sfreleaser/main.go @@ -67,3 +67,18 @@ func verifyCommand(command string, onErrorText string) { cli.Exit(1) } } + +func verifyCommandRunSuccesfully(command string, onErrorText string) { + verifyCommand("docker", onErrorText) + + output, _, err := maybeResultOf(command) + if err != nil { + zlog.Debug("command check failed", zap.String("command", command), zap.String("output", output)) + + fmt.Printf("Command %q did not execute succesfully, error with %q\n", command, err.Error()) + fmt.Println() + fmt.Println(onErrorText) + + cli.Exit(1) + } +} diff --git a/cmd/sfreleaser/release.go b/cmd/sfreleaser/release.go index 6b021ca..d9f1fbd 100644 --- a/cmd/sfreleaser/release.go +++ b/cmd/sfreleaser/release.go @@ -115,15 +115,7 @@ func release(cmd *cobra.Command, args []string) error { cli.NoError(os.Chdir(global.WorkingDirectory), "Unable to change directory to %q", global.WorkingDirectory) - verifyCommand("gh", cli.Dedent(` - The GitHub CLI utility (https://cli.github.com/) is required to obtain - information about the current draft release. - - Install via brew with 'brew install gh' or refer https://github.com/cli/cli#installation - otherwise. - - Don't forget to activate link with GitHub by doing 'gh auth login'. - `)) + verifyTools() if release.Version == "" { release.Version = promptVersion() @@ -274,3 +266,33 @@ func prepareSubstreamsSpkg(spkgPath string, global *GlobalModel, release *Releas return spkgPath } + +func verifyTools() { + verifyCommand("docker", cli.Dedent(` + The 'docker' utility (https://docs.docker.com/get-docker/) is perform the + release. + + Install it via https://docs.docker.com/get-docker/. Ensure you have it enough + resources allocated to it. You should use the fastest available options for your + system. You should also allocate minimally 4 CPU and 8GiB of RAM. + `)) + + verifyCommandRunSuccesfully("docker info", cli.Dedent(` + Ensure that your Docker Engine is currently running, it seems it's not running + right now because the command 'docker info' failed. + + Try running the command 'docker info' locally to see the output. Ensure that it + execute successuflly and exits with a 0 exit code (run 'echo $?' right after + execution of the 'docker info' command to get its exit code). + `)) + + verifyCommand("gh", cli.Dedent(` + The GitHub CLI utility (https://cli.github.com/) is required to obtain + information about the current draft release. + + Install via brew with 'brew install gh' or refer https://github.com/cli/cli#installation + otherwise. + + Don't forget to activate link with GitHub by doing 'gh auth login'. + `)) +}