-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
44 lines (37 loc) · 1.22 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
REGISTRY := ghcr.io
REPO := nicklasfrahm/infrastructure
TARGET ?= cloudapi
SOURCES := $(shell find . -name "*.go")
PLATFORM ?= $(shell go version | cut -d " " -f 4)
GOOS := $(shell echo $(PLATFORM) | cut -d "/" -f 1)
GOARCH := $(shell echo $(PLATFORM) | cut -d "/" -f 2)
SUFFIX := $(GOOS)-$(GOARCH)
VERSION ?= $(shell git describe --always --tags --dirty)
BUILD_FLAGS := -ldflags="-s -w -X main.version=$(VERSION)"
ifeq ($(GOOS),windows)
SUFFIX = $(GOOS)-$(GOARCH).exe
endif
BINARY ?= bin/$(TARGET)-$(SUFFIX)
build: bin/$(TARGET)-$(SUFFIX)
bin/$(TARGET)-$(SUFFIX): $(SOURCES)
@mkdir -p $(@D)
CGO_ENABLED=0 GOOS=$(GOOS) GOARCH=$(GOARCH) go build $(BUILD_FLAGS) -o $(BINARY) cmd/$(TARGET)/*
.PHONY: docker
docker:
docker build \
-t $(TARGET):latest \
-t $(TARGET):$(VERSION) \
-t $(REPO)-$(TARGET):latest \
-t $(REPO)-$(TARGET):$(VERSION) \
-t $(REGISTRY)/$(REPO)-$(TARGET):latest \
-t $(REGISTRY)/$(REPO)-$(TARGET):$(VERSION) \
--build-arg TARGET=$(TARGET) \
--build-arg VERSION=$(VERSION) \
-f build/package/Dockerfile .
# Make sure you have `inotify-tools` installed.
watch:
while true; do \
$(MAKE) build; \
# TODO: Run server and restart it on changes.
inotifywait -qre close_write .; \
done