diff --git a/.gitignore b/.gitignore index 7e85a917bd..bd5163ee7a 100644 --- a/.gitignore +++ b/.gitignore @@ -8,7 +8,7 @@ __pycache__ build dist *.egg-info -pkg/dockerfile/embed/*.whl +pkg/dockerfile/embed/* # Used by a vim plugin (projectionist) .projections.json .tox/ diff --git a/.goreleaser.yaml b/.goreleaser.yaml index 061d7acda9..a0d5fff1a9 100644 --- a/.goreleaser.yaml +++ b/.goreleaser.yaml @@ -16,8 +16,14 @@ builds: - amd64 - arm64 main: ./cmd/cog + flags: + - -trimpath ldflags: - - "-s -w -X github.com/replicate/cog/pkg/global.Version={{.Version}} -X github.com/replicate/cog/pkg/global.Commit={{.Commit}} -X github.com/replicate/cog/pkg/global.BuildTime={{.Date}}" + - -s + - -w + - -X github.com/replicate/cog/pkg/global.Version={{ if index .Env "COG_VERSION_OVERRIDE" }}{{ .Env.COG_VERSION_OVERRIDE }}{{ else }}{{ .Version }}{{ end }} + - -X github.com/replicate/cog/pkg/global.Commit={{ if index .Env "COG_COMMIT_OVERRIDE" }}{{ .Env.COG_COMMIT_OVERRIDE }}{{ else }}{{ .Commit }}{{ end }} + - -X github.com/replicate/cog/pkg/global.BuildTime={{ .Date }} - binary: base-image id: base-image goos: @@ -27,8 +33,14 @@ builds: - amd64 - arm64 main: ./cmd/base-image + flags: + - -trimpath ldflags: - - "-s -w -X github.com/replicate/cog/pkg/global.Version={{.Version}} -X github.com/replicate/cog/pkg/global.Commit={{.Commit}} -X github.com/replicate/cog/pkg/global.BuildTime={{.Date}}" + - -s + - -w + - -X github.com/replicate/cog/pkg/global.Version={{ if index .Env "COG_VERSION_OVERRIDE" }}{{ .Env.COG_VERSION_OVERRIDE }}{{ else }}{{ .Version }}{{ end }} + - -X github.com/replicate/cog/pkg/global.Commit={{ if index .Env "COG_COMMIT_OVERRIDE" }}{{ .Env.COG_COMMIT_OVERRIDE }}{{ else }}{{ .Commit }}{{ end }} + - -X github.com/replicate/cog/pkg/global.BuildTime={{ .Date }} archives: - format: binary builds: diff --git a/Makefile b/Makefile index 7578904089..ad620a4bfc 100644 --- a/Makefile +++ b/Makefile @@ -14,19 +14,8 @@ GORELEASER := $(GO) run github.com/goreleaser/goreleaser/v2@v2.2.0 PYTHON ?= python TOX := $(PYTHON) -Im tox -# If cog's wheel has been prebuilt, it can be specified with the COG_WHEEL -# environment variable and we will not attempt to build it. -ifndef COG_WHEEL -COG_PYTHON_VERSION := $(shell $(PYTHON) -m setuptools_scm 2>/dev/null) -ifndef COG_PYTHON_VERSION -$(error Could not determine a version for cog! Did you `pip install -e '.[dev]'` first?) -endif -COG_WHEEL := dist/cog-$(COG_PYTHON_VERSION)-py3-none-any.whl -endif - COG_GO_SOURCE := $(shell find cmd pkg -type f) COG_PYTHON_SOURCE := $(shell find python/cog -type f -name '*.py') -COG_EMBEDDED_WHEEL := pkg/dockerfile/embed/$(notdir $(COG_WHEEL)) COG_BINARIES := cog base-image @@ -36,17 +25,24 @@ default: all all: cog .PHONY: wheel -wheel: $(COG_EMBEDDED_WHEEL) +wheel: pkg/dockerfile/embed/.wheel -$(COG_EMBEDDED_WHEEL): $(COG_WHEEL) +ifdef COG_WHEEL +pkg/dockerfile/embed/.wheel: $(COG_WHEEL) @mkdir -p pkg/dockerfile/embed @rm -f pkg/dockerfile/embed/*.whl # there can only be one embedded wheel - cp $< $@ - -$(COG_WHEEL): $(COG_PYTHON_SOURCE) - $(PYTHON) -m build + @echo "Using prebuilt COG_WHEEL $<" + cp $< pkg/dockerfile/embed/ + @touch $@ +else +pkg/dockerfile/embed/.wheel: $(COG_PYTHON_SOURCE) + @mkdir -p pkg/dockerfile/embed + @rm -f pkg/dockerfile/embed/*.whl # there can only be one embedded wheel + $(PYTHON) -m pip wheel --no-deps --no-binary=:all: --wheel-dir=pkg/dockerfile/embed . + @touch $@ +endif -$(COG_BINARIES): $(COG_GO_SOURCE) $(COG_EMBEDDED_WHEEL) +$(COG_BINARIES): $(COG_GO_SOURCE) pkg/dockerfile/embed/.wheel $(GORELEASER) build --clean --snapshot --single-target --id $@ --output $@ .PHONY: install