Skip to content

Commit

Permalink
update Makefile and Dockerfile
Browse files Browse the repository at this point in the history
  • Loading branch information
snail2sky committed Nov 8, 2024
1 parent c6db475 commit a92d340
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 54 deletions.
12 changes: 3 additions & 9 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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"]
73 changes: 29 additions & 44 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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; \
Expand All @@ -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"
Expand All @@ -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)"
@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)"
2 changes: 1 addition & 1 deletion cmd/version.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down

0 comments on commit a92d340

Please sign in to comment.