diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile index 895debe..6c78e3e 100644 --- a/.devcontainer/Dockerfile +++ b/.devcontainer/Dockerfile @@ -1,7 +1,7 @@ # See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.194.3/containers/go/.devcontainer/base.Dockerfile # [Choice] Go version: 1, 1.16, 1.17 -ARG VARIANT="1.19" +ARG VARIANT="1.20" FROM mcr.microsoft.com/vscode/devcontainers/go:0-${VARIANT} COPY --from=aquasec/trivy:0.32.1 /usr/local/bin/trivy /usr/bin/trivy diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index 583bcfd..2b009a7 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -3,12 +3,12 @@ { "name": "Go", "build": { - "dockerfile": "Dockerfile", + // "dockerfile": "Dockerfile", "args": { // Update the VARIANT arg to pick a version of Go: 1, 1.16, 1.17 // Append -bullseye or -buster to pin to an OS version. // Use -bullseye variants on local arm64/Apple Silicon. - "VARIANT": "1.19-bullseye", + // "VARIANT": "1.20-bullseye", // Options "NODE_VERSION": "none" } diff --git a/assets/docker/Dockerfile b/assets/docker/Dockerfile index 9f7d8b5..5bb9731 100644 --- a/assets/docker/Dockerfile +++ b/assets/docker/Dockerfile @@ -1,5 +1,5 @@ -FROM dragonheim/golang:1.19 as builder -ARG SEMVER +FROM dragonheim/golang:1.20 as builder +ARG SEMVER=${SEMVER:-0.0.7} WORKDIR /gagent COPY . . diff --git a/cmd/gagent/main.go b/cmd/gagent/main.go index 4eb56ce..0890664 100644 --- a/cmd/gagent/main.go +++ b/cmd/gagent/main.go @@ -9,6 +9,8 @@ import ( autorestart "github.com/slayer/autorestart" + env "github.com/caarlos0/env/v6" + fqdn "github.com/Showmax/go-fqdn" gstructs "github.com/dragonheim/gagent/internal/gstructs" @@ -52,6 +54,12 @@ var ( * 10 Router not connected */ +var environment struct { + Mode string `env:"GAGENT_MODE" envDefault:"setup"` + Port int `env:"PORT" envDefault:"3000"` + UUID string `env:"GAGENT_UUID" envDefault:""` +} + var config gstructs.GagentConfig func main() { @@ -112,9 +120,15 @@ func main() { func init() { // var err error - autorestart.StartWatcher() + cfg := environment + if err := env.Parse(&cfg); err != nil { + log.Printf("%+v\n", err) + } + + log.Printf("%+v\n", cfg) + filter := &logutils.LevelFilter{ Levels: []logutils.LogLevel{"DEBUG", "INFO", "WARN", "ERROR"}, MinLevel: logutils.LogLevel("DEBUG"), diff --git a/go.mod b/go.mod index 336a090..2eb63d0 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.18 require ( github.com/Showmax/go-fqdn v1.0.0 github.com/aviddiviner/docopt-go v0.0.0-20170807220726-d8a1d67efc6a + github.com/caarlos0/env/v6 v6.10.1 github.com/hashicorp/hcl/v2 v2.15.0 github.com/hashicorp/logutils v1.0.0 github.com/jakehl/goid v1.1.0 diff --git a/go.sum b/go.sum index 9eee2db..48bf405 100644 --- a/go.sum +++ b/go.sum @@ -50,6 +50,8 @@ github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24 github.com/beorn7/perks v1.0.0/go.mod h1:KWe93zE9D1o94FZ5RNwFwVgaQK1VOXiVxmqh+CedLV8= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= +github.com/caarlos0/env/v6 v6.10.1 h1:t1mPSxNpei6M5yAeu1qtRdPAK29Nbcf/n3G7x+b3/II= +github.com/caarlos0/env/v6 v6.10.1/go.mod h1:hvp/ryKXKipEkcuYjs9mI4bBCg+UI0Yhgm5Zu0ddvwc= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=