refactor: move main to cmd/

master
Evan Chen 2021-10-18 09:14:30 +08:00
parent 18b81a4a32
commit aa3d4a1615
4 changed files with 21 additions and 24 deletions

View File

@ -9,7 +9,7 @@ COPY . .
RUN VERSION=$(git describe --tags) BUILD=$(git rev-parse --short HEAD) && \ RUN VERSION=$(git describe --tags) BUILD=$(git rev-parse --short HEAD) && \
GOOS=linux GOARCH=amd64 \ GOOS=linux GOARCH=amd64 \
go build -ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w" \ go build -ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w" \
-o /go/bin/myip main.go -o /go/bin/myip cmd/myip/main.go
FROM alpine:3.14 FROM alpine:3.14

View File

@ -10,12 +10,8 @@ LDFLAGS=-ldflags "-X main.Version=${VERSION} -X main.Build=${BUILD} -w"
PLATFORMS=darwin linux PLATFORMS=darwin linux
ARCHITECTURES=amd64 ARCHITECTURES=amd64
BASIC_PATH=cmd/basic/main.go
BASIC=myip-basic APPS=myip myip-basic
FULL_PATH=cmd/myip/main.go
FULL=myip
GUI_PATH=cmd/myip/main.go
GUI=cmd/myip/main.go
default: build default: build
@ -34,25 +30,25 @@ build:
go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH} go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}
build-unix: build-unix:
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \ $(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), $(foreach APP, $(APPS),\
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${FULL} ${FULL_PATH}) \ $(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/$(APP) cmd/$(APP)/main.go) \
$(shell cd dist; tar -czf ${FULL}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${FULL}) \ $(shell cd dist; tar -czf ${APP}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${APP}) \
)) $(shell rm dist/${APP}) \
rm dist/${FULL} )))
$(foreach GOOS, $(PLATFORMS), $(foreach GOARCH, $(ARCHITECTURES), \
$(shell export GOOS=$(GOOS); export GOARCH=$(GOARCH); go build ${LDFLAGS} -o dist/${BASIC} ${BASIC_PATH}) \
$(shell cd dist; tar -czf ${BASIC}_$(VERSION)_$(GOOS)_$(GOARCH).tar.gz ${BASIC}) \
))
rm dist/${BASIC}
build-win: build-win:
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_windows_amd64/${FULL}.exe ${FULL_PATH}) $(foreach APP, $(APPS), \
$(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_windows_amd64/${BASIC}.exe ${BASIC_PATH}) $(shell export GOOS=windows; export GOARCH=amd64; go build ${LDFLAGS} -o dist/${APP}.exe cmd/$(APP)/main.go) \
$(shell cd dist; tar -czf ${APP}_$(VERSION)_windows_amd64.tar.gz ${APP}.exe) \
$(shell rm dist/${APP}.exe) \
)
build-mac-m1: build-mac-m1:
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)_$(VERSION)_darwin_arm64/${FULL} ${FULL_PATH}) $(foreach APP, $(APPS),\
$(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(PROJ)-basic_$(VERSION)_darwin_arm64/${BASIC} ${BASIC_PATH}) $(shell export GOOS=darwin; export GOARCH=arm64; go build ${LDFLAGS} -o dist/$(APP) cmd/$(APP)/main.go) \
$(shell cd dist; tar -czf ${APP}_$(VERSION)_darwin_arm64.tar.gz ${APP}) \
$(shell rm dist/${APP}) \
)
build-zip: build-zip:
cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done cd dist; for f in * ;do if ! [[ $$f =~ "gz" ]] ; then tar -czf $${f}.tar.gz $${f}; fi done
@ -74,6 +70,7 @@ docker-save:
docker save $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) | gzip > dist/$(PROJ)-image-$(VERSION)-${BUILD}.tar.gz docker save $(HUB)/$(HUB_PROJECT)/$(PROJ):$(VERSION) | gzip > dist/$(PROJ)-image-$(VERSION)-${BUILD}.tar.gz
release: clean binary build-zip docker docker-save docker-push release: clean binary docker docker-save
.PHONY: build docker release clean all binary install .PHONY: build docker release clean all binary install

View File

@ -78,7 +78,7 @@ docker run --name myip -d --restart=always hub.kumoly.io/tools/myip myip --cron
## Cron ## Cron
``` ```
ield name | Mandatory? | Allowed values | Allowed special characters field name | Mandatory? | Allowed values | Allowed special characters
---------- | ---------- | -------------- | -------------------------- ---------- | ---------- | -------------- | --------------------------
Seconds | Yes | 0-59 | * / , - Seconds | Yes | 0-59 | * / , -
Minutes | Yes | 0-59 | * / , - Minutes | Yes | 0-59 | * / , -