feature: Send isInContainer to update service

This commit is contained in:
jamesread 2022-01-11 23:17:50 +00:00
parent 59f214fd45
commit 62a45bd214
1 changed files with 14 additions and 0 deletions

View File

@ -11,6 +11,8 @@ import (
"net/http" "net/http"
"runtime" "runtime"
"time" "time"
"errors"
"os"
) )
type updateRequest struct { type updateRequest struct {
@ -19,6 +21,7 @@ type updateRequest struct {
OS string OS string
Arch string Arch string
MachineID string MachineID string
InContainer bool
} }
// AvailableVersion is updated when checking with the update service. // AvailableVersion is updated when checking with the update service.
@ -38,6 +41,14 @@ func machineID() string {
return v 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 // StartUpdateChecker will start a job that runs periodically, checking
// for updates. // for updates.
func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config) { func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config.Config) {
@ -54,6 +65,7 @@ func StartUpdateChecker(currentVersion string, currentCommit string, cfg *config
OS: runtime.GOOS, OS: runtime.GOOS,
Arch: runtime.GOARCH, Arch: runtime.GOARCH,
MachineID: machineID(), MachineID: machineID(),
InContainer: isInContainer(),
} }
s := gocron.NewScheduler(time.UTC) s := gocron.NewScheduler(time.UTC)
@ -92,6 +104,8 @@ func doRequest(jsonUpdateRequest []byte) string {
func actualCheckForUpdate(payload updateRequest) { func actualCheckForUpdate(payload updateRequest) {
jsonUpdateRequest, err := json.Marshal(payload) jsonUpdateRequest, err := json.Marshal(payload)
log.Debugf("Update request payload: %+v", payload)
if err != nil { if err != nil {
log.Errorf("Update check failed %v", err) log.Errorf("Update check failed %v", err)
return return