Skip to content

Commit

Permalink
fix: add ldflag version
Browse files Browse the repository at this point in the history
  • Loading branch information
pierre818181 committed Jan 4, 2025
1 parent 58beb19 commit 28d56a3
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
11 changes: 9 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
7 changes: 3 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
6 changes: 2 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -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=
Expand Down Expand Up @@ -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=
Expand Down
30 changes: 19 additions & 11 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import (
)

var mutex = &sync.Mutex{}
var Version = "dev"

type Test struct {
ID int `json:"id,omitempty"`
Expand Down Expand Up @@ -91,7 +92,6 @@ func init() {
}
}

log.Info(os.Getenv("RUNPOD_TEST"))
if os.Getenv("RUNPOD_TEST") == "true" {
tests := os.Getenv("RUNPOD_TESTS")

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}

0 comments on commit 28d56a3

Please sign in to comment.