Преглед на файлове

feature: Send isInContainer to update service

jamesread преди 4 години
родител
ревизия
62a45bd214
променени са 1 файла, в които са добавени 14 реда и са изтрити 0 реда
  1. 14 0
      internal/updatecheck/updateCheck.go

+ 14 - 0
internal/updatecheck/updateCheck.go

@@ -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