diff --git a/Dockerfile b/Dockerfile index fd1b2c2..ab34221 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,21 +1,15 @@ -ARG IMAGE=golang:1.22 +ARG IMAGE FROM $IMAGE as builder WORKDIR /data0/src/bbx - ENV CGO_ENABLED=0 - COPY . . - -# 静态编译 -# RUN go build -ldflags '-linkmode "external" -extldflags "-static"' RUN go build + FROM alpine as runner WORKDIR /data0/apps/bbx - -COPY --from=builder /data0/src/bbx/bbx /data0/apps/bbx/ - +COPY --from=builder /data0/src/bbx/bbx /data0/apps/bbx/bbx ENTRYPOINT ["/data0/apps/bbx/bbx"] diff --git a/Makefile b/Makefile index 23ff034..888aadf 100644 --- a/Makefile +++ b/Makefile @@ -1,58 +1,50 @@ OS := $(shell uname) -ifeq ($(OS),Windows_NT) - TARGET := windows -else - ifeq ($(OS),Darwin) - TARGET := mac - else - TARGET := linux - endif + +TARGET := windows + +ifeq ($(OS),Darwin) + TARGET := darwin +endif + +ifeq ($(OS),Linux) + TARGET := linux endif + VERSION_FILE := cmd/version.go TAG := $(shell sed -rn 's/const version = "(.*)"/\1/p' $(VERSION_FILE)) OS_LIST := windows darwin linux ARCH_LIST := 386 amd64 arm64 -IMAGE := golang:1.22 -GOOS := linux -GOARCH := amd64 -GOPROXY := goproxy.io auto: $(TARGET) test: @echo $(IMAGE) $(TAG) $(GOOS) $(GOARCH) $(GOPROXY) -tidy: - @go mod tidy - build: - @go build - - -compile: - @make tidy && make build + @export CGO_ENABLED=0 go mod tidy && go build -mac: - @echo "build for mac" - @export GOOS=darwin && make compile +darwin: + @echo "build for darwin" + @env GOOS=darwin $(MAKE) build linux: @echo "build for linux" - @export GOOS=linux && make compile + @env GOOS=linux $(MAKE) build windows: @echo "build for windows" - @export GOOS=windows && make compile + @env GOOS=windows $(MAKE) build install: @echo "install bbx" @go install -gen-releases: +release: @echo Generate releases for $(TAG) @RELEASE_DIR=releases/$(TAG) && mkdir -p $$RELEASE_DIR && \ + export CGO_ENABLED=0 ; \ for os in $(OS_LIST); do \ for arch in $(ARCH_LIST); do \ exe=bbx-$$os-$$arch; \ @@ -69,17 +61,10 @@ gen-releases: build-image: @echo "build docker image" - @echo "build $(TAG) $(GOOS)" - @docker build -t snail2sky/bbx:$(TAG) \ - --build-arg GOOS=$(GOOS) \ - --build-arg GOARCH=$(GOARCH) \ - --build-arg GOPROXY=$(GOPROXY) \ - --build-arg BUILD_TYPE=$(BUILD_TYPE) \ - --build-arg IMAGE=$(IMAGE) . - -push-image: - @echo "push docker image" - @docker push snail2sky/bbx:$(TAG) + @echo "build $(IMAGE) $(GOARCH) $(GOPROXY) $(TAG)" + docker build --no-cache -t snail2sky/bbx:$(TAG) \ + --build-arg IMAGE=$(IMAGE) \ + . clean: @echo "clean bbx bbx.exe program" @@ -89,12 +74,12 @@ clean: clean-all: @echo "clean all binary file, such bbx, bbx.exe and all releases" @rm -rf bbx bbx.exe releases + @docker image rm snail2sky/bbx:$(TAG) help: - @echo "build: make [ mac | linux | windows ] build for mac linux or windows" - @echo "clean: make clean clean bbx and bbx.exe file" - @echo "clean-all make clean-all clean all binary files" - @echo "install: make install install binary file to GOBIN dir" - @echo "build-image: make build-image [GOOS=[linux|darwin|windows] | GOARCH=[amd64|arm64|...] | GOPROXY=goproxy.io | IMAGE=golang:1.22]" - @echo "push-image: make push-image push image to docker hub" - @echo "gen-releases: make gen-releases generate releases into releases/$(TAG)" \ No newline at end of file + @echo "build: make [ darwin | linux | windows ] build for mac linux or windows" + @echo "clean: make clean clean bbx and bbx.exe file" + @echo "clean-all make clean-all clean all binary files" + @echo "install: make install install binary file to GOBIN dir" + @echo "build-image: make build-image IMAGE=golang:1.22 build docker image" + @echo "release: make release generate releases into releases/$(TAG)" \ No newline at end of file diff --git a/cmd/version.go b/cmd/version.go index bb6880a..ae0df62 100644 --- a/cmd/version.go +++ b/cmd/version.go @@ -6,7 +6,7 @@ import ( "github.com/spf13/cobra" ) -const version = "v1.1.1" +const version = "v1.1.2" // versionCmd represents the version command var versionCmd = &cobra.Command{