From 19e6f4f5ba74435af7199dc3fbfb2bb30794fa56 Mon Sep 17 00:00:00 2001 From: Neville Li Date: Thu, 12 Dec 2024 16:29:23 -0500 Subject: [PATCH] Use Python version in Go --- .gitignore | 8 +++++--- cmd/cog-server/main.go | 3 +-- internal/util/util.go | 15 +++++++++++++++ script/build.sh | 19 +++++++++++++++++++ 4 files changed, 40 insertions(+), 5 deletions(-) create mode 100755 script/build.sh diff --git a/.gitignore b/.gitignore index 5b88fd1..61062df 100644 --- a/.gitignore +++ b/.gitignore @@ -1,7 +1,9 @@ *.egg-info .direnv/ .envrc -.idea +/.idea +/dist +/internal/util/version.txt +/python/coglet/_version.py +/uv.lock __pycache__ -python/coglet/_version.py -uv.lock diff --git a/cmd/cog-server/main.go b/cmd/cog-server/main.go index 6eb9857..5f15b1e 100644 --- a/cmd/cog-server/main.go +++ b/cmd/cog-server/main.go @@ -14,7 +14,6 @@ import ( "github.com/peterbourgon/ff/v4/ffhelp" "github.com/replicate/go/logging" "github.com/replicate/go/must" - "github.com/replicate/go/version" _ "go.uber.org/automaxprocs" "github.com/replicate/cog-runtime/internal/server" @@ -111,7 +110,7 @@ func main() { os.Exit(1) } - log.Infow("starting Cog HTTP server", "version", version.Version()) + log.Infow("starting Cog HTTP server", "version", util.Version()) ctx, cancel := context.WithCancel(context.Background()) go func() { ch := make(chan os.Signal, 1) diff --git a/internal/util/util.go b/internal/util/util.go index 5fccfcc..fcd1b25 100644 --- a/internal/util/util.go +++ b/internal/util/util.go @@ -1,6 +1,8 @@ package util import ( + "embed" + _ "embed" "encoding/base32" "fmt" "os" @@ -58,3 +60,16 @@ func JoinLogs(logs []string) string { } return r } + +// Wildcard match in case version.txt is not generated yet +// +//go:embed * +var embedFS embed.FS + +func Version() string { + bs, err := embedFS.ReadFile("version.txt") + if err != nil { + return "0.0.0+unknown" + } + return strings.TrimSpace(string(bs)) +} diff --git a/script/build.sh b/script/build.sh new file mode 100755 index 0000000..bb50569 --- /dev/null +++ b/script/build.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +# Build binaries + +set -euo pipefail + +base_dir="$(git rev-parse --show-toplevel)" + +cd "$base_dir" +python -m build + +# Export Python version to Go +python -c 'import coglet; print(coglet.__version__)' > internal/util/version.txt + +for os in darwin linux; do + for arch in amd64 arm64; do + CGO_ENABLED=0 GOOS=$os GOARCH=$arch go build -o dist/cog-server-$os-$arch ./cmd/cog-server + done +done