From 62a45bd214dda656e73986b922be7b67e090f949 Mon Sep 17 00:00:00 2001 From: jamesread Date: Tue, 11 Jan 2022 23:17:50 +0000 Subject: [PATCH] feature: Send isInContainer to update service --- internal/updatecheck/updateCheck.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/internal/updatecheck/updateCheck.go b/internal/updatecheck/updateCheck.go index 63cb469..cf0ae81 100644 --- a/internal/updatecheck/updateCheck.go +++ b/internal/updatecheck/updateCheck.go @@ -11,6 +11,8 @@ import ( "net/http" "runtime" "time" + "errors" + "os" ) type updateRequest struct { @@ -19,6 +21,7 @@ type updateRequest struct { OS string Arch string MachineID string + InContainer bool } // AvailableVersion is updated when checking with the update service. @@ -38,6 +41,14 @@ func machineID() string { return v } +func isInContainer() bool { + if _, err := os.Stat("/.dockerenv"); errors.Is(err, os.ErrNotExist) { + return false; + } + + return true; +} + // StartUpdateChecker will start a job that runs periodically, checking // for updates. func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config) { @@ -54,6 +65,7 @@ func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config OS: runtime.GOOS, Arch: runtime.GOARCH, MachineID: machineID(), + InContainer: isInContainer(), } s := gocron.NewScheduler(time.UTC) @@ -92,6 +104,8 @@ func doRequest(jsonUpdateRequest []byte) string { func actualCheckForUpdate(payload updateRequest) { jsonUpdateRequest, err := json.Marshal(payload) + log.Debugf("Update request payload: %+v", payload) + if err != nil { log.Errorf("Update check failed %v", err) return