-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathMakefile
More file actions
65 lines (53 loc) · 1.81 KB
/
Copy pathMakefile
File metadata and controls
65 lines (53 loc) · 1.81 KB
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# Makefile for Figurine
# Variables
BINARY_NAME=figurine
VERSION=$(shell git describe --tags --always --dirty)
LDFLAGS=-ldflags "-s -w -X main.version=$(VERSION)"
GO_FILES=$(shell find . -name "*.go" -type f)
DOCKER_IMAGE=figurine
DOCKER_CONTAINER=figurine-container
PLATFORMS=linux/amd64 linux/arm64 darwin/amd64 darwin/arm64 windows/amd64
OUTPUT_DIR=dist
# Go commands
build:
go build $(LDFLAGS) -o $(BINARY_NAME) .
install:
go install $(LDFLAGS) .
test:
go test -v ./...
clean:
go clean
[ -f $(BINARY_NAME) ] && rm -f $(BINARY_NAME) || true
rm -rf $(OUTPUT_DIR)
# Multi-platform builds
build-all: clean
mkdir -p $(OUTPUT_DIR)
$(foreach platform,$(PLATFORMS),\
$(eval OS := $(word 1,$(subst /, ,$(platform)))) \
$(eval ARCH := $(word 2,$(subst /, ,$(platform)))) \
$(eval EXTENSION := $(if $(filter windows,$(OS)),.exe,)) \
echo "Building $(OS)/$(ARCH)..." && \
GOOS=$(OS) GOARCH=$(ARCH) CGO_ENABLED=0 \
go build $(LDFLAGS) -o $(OUTPUT_DIR)/$(BINARY_NAME)_$(OS)_$(ARCH)$(EXTENSION) . && \
cd $(OUTPUT_DIR) && \
tar -czvf $(BINARY_NAME)_$(OS)_$(ARCH).tar.gz $(BINARY_NAME)_$(OS)_$(ARCH)$(EXTENSION) && \
cd - ;\
)
release: build-all
cd $(OUTPUT_DIR) && sha256sum *.tar.gz > checksums.txt
# Docker commands
docker-build:
docker build -t $(DOCKER_IMAGE) .
docker-run:
docker run --rm --name $(DOCKER_CONTAINER) $(DOCKER_IMAGE)
docker-clean:
docker rm -f $(DOCKER_CONTAINER) 2>/dev/null || true
docker rmi -f $(DOCKER_IMAGE) 2>/dev/null || true
# Docker multi-platform build
docker-buildx:
docker buildx create --use --name multiplatform-builder || true
docker buildx build --platform linux/amd64,linux/arm64,linux/arm/v7 \
--tag $(DOCKER_IMAGE):$(VERSION) \
--tag $(DOCKER_IMAGE):latest \
--push .
.PHONY: build install test clean build-all release docker-build docker-run docker-clean docker-buildx