From 9631ecf68bf0abaa9fa6a2864c078c8e1e9f8e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=E8=8F=8C?= Date: Mon, 11 Apr 2022 20:37:19 +0800 Subject: [PATCH] up --- .gitignore | 1 + Dockerfile | 4 +++ Makefile | 71 +++++++++++++++++++++++++++++++++++++----------------- 3 files changed, 54 insertions(+), 22 deletions(-) diff --git a/.gitignore b/.gitignore index 7665f9c..e74197f 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ test.go +bin/ diff --git a/Dockerfile b/Dockerfile index 6a5b13c..3ac9686 100644 --- a/Dockerfile +++ b/Dockerfile @@ -6,6 +6,10 @@ ENV GO111MODULE=off RUN GOARCH=amd64 GOOS=linux go build -ldflags="-s -w" -o hello main.go 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 WORKDIR /app EXPOSE 80 diff --git a/Makefile b/Makefile index 0db88e1..49d8ff6 100644 --- a/Makefile +++ b/Makefile @@ -1,28 +1,55 @@ -# https://eddycjy.com/posts/go/gin/2018-08-26-makefile/ -.PHONY: build clean tool lint docker help - -all: build +GOPATH:=$(shell go env GOPATH) +VERSION=$(shell git describe --tags --always) +APP='helloworld' +.PHONY: build +# build build: - go build -v . - -tool: - go tool vet . |& grep -v vendor; true - gofmt -w . - -lint: - golint ./... - -clean: - rm -rf main helloworld - go clean -i . + mkdir -p bin + GOARCH=amd64 GOOS=linux go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-linux-amd64" ./... + GOARCH=arm64 GOOS=linux go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-linux-arm64" ./... + GOARCH=amd64 GOOS=darwin go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-darwin-amd64" ./... + GOARCH=arm64 GOOS=darwin go build -ldflags "-X main.Version=$(VERSION)" -o ./bin/$(APP)"-darwin-arm64" ./... +.PHONY: docker +# build docker image 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: - @echo "make: compile packages and dependencies" - @echo "make tool: run specified go tool" - @echo "make lint: golint ./..." - @echo "make clean: remove object files and cached files" - @echo "make docker: build docker image" \ No newline at end of file + @echo '' + @echo 'Usage:' + @echo ' make [target]' + @echo '' + @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