This commit is contained in:
C菌
2022-04-11 20:37:19 +08:00
parent 2f848fda1e
commit 9631ecf68b
3 changed files with 54 additions and 22 deletions

1
.gitignore vendored
View File

@@ -1 +1,2 @@
test.go test.go
bin/

View File

@@ -6,6 +6,10 @@ ENV GO111MODULE=off
RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o hello main.go RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o hello main.go
FROM alpine:latest AS runner FROM alpine:latest AS runner
# 设置alpine 时间为上海时间
RUN apk add tzdata && cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime \
&& echo "Asia/Shanghai" > /etc/timezone \
&& apk del tzdata
COPY --from=builder /app/hello /app/hello COPY --from=builder /app/hello /app/hello
WORKDIR /app WORKDIR /app
EXPOSE 80 EXPOSE 80

View File

@@ -1,28 +1,55 @@
# https://eddycjy.com/posts/go/gin/2018-08-26-makefile/ GOPATH:=$(shell go env GOPATH)
.PHONY: build clean tool lint docker help VERSION=$(shell git describe --tags --always)
APP='helloworld'
all: build
.PHONY: build
# build
build: build:
go build -v . mkdir -p bin
GOARCH=amd64 GOOS=linux go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-linux-amd64" ./...
tool: GOARCH=arm64 GOOS=linux go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-linux-arm64" ./...
go tool vet . |& grep -v vendor; true GOARCH=amd64 GOOS=darwin go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-darwin-amd64" ./...
gofmt -w . GOARCH=arm64 GOOS=darwin go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-darwin-arm64" ./...
lint:
golint ./...
clean:
rm -rf main helloworld
go clean -i .
.PHONY: docker
# build docker image
docker: docker:
docker build -t mirrors2/helloworld:latest . docker buildx build \
--platform linux/amd64,linux/arm64 \
-t mirrors2/$(APP):latest . --push
.PHONY: clean
# clean build
clean:
rm -rf bin/
.PHONY: cleand
# clean docker
cleand:
docker rmi $(docker images |grep none|awk '{print $3}') -f
docker rm $(docker ps -aq)
# docker rm $(docker ps -a |grep -v Up)
.PHONY: all
# generate all
all:
# show help
help: help:
@echo "make: compile packages and dependencies" @echo ''
@echo "make tool: run specified go tool" @echo 'Usage:'
@echo "make lint: golint ./..." @echo ' make [target]'
@echo "make clean: remove object files and cached files" @echo ''
@echo "make docker: build docker image" @echo 'Targets:'
@awk '/^[a-zA-Z\-\_0-9]+:/ { \
helpMessage = match(lastLine, /^# (.*)/); \
if (helpMessage) { \
helpCommand = substr($$1, 0, index($$1, ":")-1); \
helpMessage = substr(lastLine, RSTART + 2, RLENGTH); \
printf "\033[36m%-22s\033[0m %s\n", helpCommand,helpMessage; \
} \
} \
{ lastLine = $$0 }' $(MAKEFILE_LIST)
.DEFAULT_GOAL := help