From 0f538e46c36903a6ab2465024a69c3a5c050ea41 Mon Sep 17 00:00:00 2001 From: Changkun Ou Date: Wed, 24 Mar 2021 21:25:42 +0100 Subject: [PATCH] all: add release build --- .gitignore | 1 + Makefile | 24 +++++++++++++++++++++-- README.md | 39 +++++++++++++++++++++++++------------ internal/version/.version | 1 + internal/version/version.go | 6 ++++++ redir.go | 18 ++++++++++++++--- server.go | 4 +++- 7 files changed, 75 insertions(+), 18 deletions(-) create mode 100644 internal/version/.version create mode 100644 internal/version/version.go diff --git a/.gitignore b/.gitignore index eea1862..56945cb 100644 --- a/.gitignore +++ b/.gitignore @@ -16,3 +16,4 @@ migrate/dump/ips migrate/dump/alias data/mongo node_modules +build diff --git a/Makefile b/Makefile index 7badb2a..4c191ee 100644 --- a/Makefile +++ b/Makefile @@ -7,9 +7,24 @@ IMAGE = redir BINARY = redir TARGET = -o $(BINARY) BUILD_FLAGS = $(TARGET) -mod=vendor +GOOS = linux darwin +GOARCH = amd64 arm64 all: go build $(BUILD_FLAGS) + +$(GOOS): $(GOARCH) + echo $(VERSION) > internal/version/.version + for goarch in $^ ; do \ + mkdir -p build/$(BINARY); \ + cp internal/config/config.yml build/$(BINARY)/config.yml; \ + CGO_ENABLED=0 GOARCH=$${goarch} GOOS=$@ go build -o build/$(BINARY)/$(BINARY) -mod=vendor; \ + zip -r build/redir-$(VERSION)-$@-$${goarch}.zip build/$(BINARY); \ + rm -rf build/$(BINARY); \ + done +# restore + echo dev > internal/version/.version + run: ./$(BINARY) -s dashboard: @@ -21,8 +36,13 @@ up: docker-compose -f docker/docker-compose.yml up -d down: docker-compose -f docker/docker-compose.yml down + + +release: $(GOOS) + clean: - rm -rf $(BINARY) + rm -rf $(BINARY) build docker rmi -f $(shell docker images -f "dangling=true" -q) 2> /dev/null; true docker rmi -f $(IMAGE):latest 2> /dev/null; true -.PHONY: run dashboard build up down clean \ No newline at end of file + +.PHONY: $(GOOS) $(GOARCH) run dashboard build up down clean \ No newline at end of file diff --git a/README.md b/README.md index c7fbb64..3860b2f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # redir [![Latest relsease](https://img.shields.io/github/v/tag/changkun/redir?label=latest)](https://github.com/changkun/redir/releases) [![PkgGoDev](https://pkg.go.dev/badge/changkun.de/x/redir)](https://pkg.go.dev/changkun.de/x/redir) ![](https://changkun.de/urlstat?mode=github&repo=changkun/redir) -Self-hosted link shortener and request redirector. +Self-hosted URL shortener. ## Features @@ -45,7 +45,15 @@ The `redir` command offers server side operation feature from shell: ``` $ redir -usage: redir [-s] [-f ] [-d ] [-op -a -l -p -vt