diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 4970257..d26bfe1 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -21,7 +21,7 @@ jobs: go-version: '1.22' cache: true - - run: go build -o dev-sls-local-server main.go + - run: go build -ldflags="-X 'sls-local-server/main.Version=$(github.ref_name)'" -o main main.go - name: Configure AWS credentials if: endsWith(github.ref_name, '-dev') diff --git a/Makefile b/Makefile index 131fe72..9d3f270 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,12 @@ -make-arm: - env GOOS=linux GOARCH=arm64 go build -o main main.go +VERSION ?= dev + +.PHONY: build +build: + go build -ldflags="-X 'sls-local-server/main.Version=$(VERSION)'" -o main main.go + +.PHONY: build-arm64 +build-arm64: + env GOARCH=arm64 go build -ldflags="-X 'sls-local-server/main.Version=$(VERSION)'" -o main main.go # sudo docker run -e RUNPOD_TEST=true -e RUNPOD_TEST_FILE=runpod.tests.json -e RUNPOD_ENDPOINT_BASE_URL=http://0.0.0.0:19981//v2 -e RUNPOD_WEBHOOK_GET_JOB=http://0.0.0.0:19981/v2//job-take/$RUNPOD_POD_ID -e RUNPOD_WEBHOOK_POST_OUTPUT=http://0.0.0.0:19981/v2//job-done/$RUNPOD_POD_ID/$ID -e RUNPOD_POD_ID=1234 pierre781/simple:tag \ No newline at end of file diff --git a/go.mod b/go.mod index 1ad65b4..d92aa83 100644 --- a/go.mod +++ b/go.mod @@ -1,15 +1,15 @@ -module github.com/runpod/sls-local-server +module sls-local-server -go 1.21.3 +go 1.21 require ( github.com/gin-gonic/gin v1.10.0 + github.com/thessem/zap-prettyconsole v0.5.2 go.uber.org/zap v1.27.0 ) require ( github.com/Code-Hex/dd v1.1.0 // indirect - github.com/alecthomas/kong v1.6.0 // indirect github.com/bytedance/sonic v1.11.6 // indirect github.com/bytedance/sonic/loader v0.1.1 // indirect github.com/cloudwego/base64x v0.1.4 // indirect @@ -28,7 +28,6 @@ require ( github.com/modern-go/reflect2 v1.0.2 // indirect github.com/pelletier/go-toml/v2 v2.2.2 // indirect github.com/pkg/errors v0.9.1 // indirect - github.com/thessem/zap-prettyconsole v0.5.2 // indirect github.com/twitchyliquid64/golang-asm v0.15.1 // indirect github.com/ugorji/go/codec v1.2.12 // indirect go.uber.org/multierr v1.11.0 // indirect diff --git a/go.sum b/go.sum index df794f7..e5aadbf 100644 --- a/go.sum +++ b/go.sum @@ -1,7 +1,5 @@ github.com/Code-Hex/dd v1.1.0 h1:VEtTThnS9l7WhpKUIpdcWaf0B8Vp0LeeSEsxA1DZseI= github.com/Code-Hex/dd v1.1.0/go.mod h1:VaMyo/YjTJ3d4qm/bgtrUkT2w+aYwJ07Y7eCWyrJr1w= -github.com/alecthomas/kong v1.6.0 h1:mwOzbdMR7uv2vul9J0FU3GYxE7ls/iX1ieMg5WIM6gE= -github.com/alecthomas/kong v1.6.0/go.mod h1:p2vqieVMeTAnaC83txKtXe8FLke2X07aruPWXyMPQrU= github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0= github.com/bytedance/sonic v1.11.6/go.mod h1:LysEHSvpvDySVdC2f87zGWf6CIKJcAvqab1ZaiQtds4= github.com/bytedance/sonic/loader v0.1.1 h1:c+e5Pt1k/cy5wMveRDyk2X4B9hF4g7an8N3zCYjJFNM= @@ -29,8 +27,8 @@ github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBEx github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= -github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= +github.com/google/go-cmp v0.5.7 h1:81/ik6ipDQS2aGcBfIN5dHDB36BwrStyeAQquSYCV4o= +github.com/google/go-cmp v0.5.7/go.mod h1:n+brtR0CgQNWTVd5ZUFpTBC8YFBDLK/h/bpaJ8/DtOE= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= diff --git a/main.go b/main.go index 153aa24..848f605 100644 --- a/main.go +++ b/main.go @@ -18,6 +18,7 @@ import ( ) var mutex = &sync.Mutex{} +var Version = "dev" type Test struct { ID int `json:"id,omitempty"` @@ -91,7 +92,6 @@ func init() { } } - log.Info(os.Getenv("RUNPOD_TEST")) if os.Getenv("RUNPOD_TEST") == "true" { tests := os.Getenv("RUNPOD_TESTS") @@ -309,16 +309,6 @@ func LoggerMiddleware(logger *zap.Logger) gin.HandlerFunc { } } -func main() { - defer log.Sync() - command := flag.String("command", "python3 handler.py", "the user command to run") - - go func() { - runCommand(*command) - }() - RunServer() -} - func runCommand(command string) { log.Info("Running command", zap.String("command", command)) cmd := exec.Command("sh", "-c", command) @@ -365,3 +355,21 @@ func RunServer() { log.Fatal("Failed to start server", zap.Error(err)) } } + +func main() { + command := flag.String("command", "python3 handler.py", "the user command to run") + check := flag.String("check", "null", "the version of the server to run") + + flag.Parse() + + if check != nil && *check == "version" { + fmt.Println(Version) + return + } + defer log.Sync() + + go func() { + runCommand(*command) + }() + RunServer() +}