-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
104 lines (87 loc) · 3.04 KB
/
Makefile
File metadata and controls
104 lines (87 loc) · 3.04 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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# Path parameters
GO ?= $(shell which go 2>/dev/null)
DOCKER ?= $(shell which docker 2>/dev/null)
WASMBUILD ?= $(shell which wasmbuild 2>/dev/null)
BUILDDIR ?= build
CMDDIR=$(wildcard cmd/*)
# Set OS and Architecture
ARCH ?= $(shell arch | tr A-Z a-z | sed 's/x86_64/amd64/' | sed 's/i386/amd64/' | sed 's/armv7l/arm/' | sed 's/aarch64/arm64/')
OS ?= $(shell uname | tr A-Z a-z)
VERSION ?= $(shell git describe --tags --always | sed 's/^v//')
# Build flags
BUILD_MODULE = $(shell cat go.mod | head -1 | cut -d ' ' -f 2)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitSource=${BUILD_MODULE}
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitTag=$(shell git describe --tags --always)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitBranch=$(shell git name-rev HEAD --name-only --always)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GitHash=$(shell git rev-parse HEAD)
BUILD_LD_FLAGS += -X $(BUILD_MODULE)/pkg/version.GoBuildTime=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
BUILD_FLAGS = -ldflags="-s -w ${BUILD_LD_FLAGS}"
# Docker
DOCKER_REPO ?= ghcr.io/mutablelogic/pgmanager
DOCKER_SOURCE ?= ${BUILD_MODULE}
DOCKER_TAG = ${DOCKER_REPO}-${OS}-${ARCH}:${VERSION}
# All targets
all: tidy $(CMDDIR)
# Rules for building
.PHONY: $(CMDDIR)
$(CMDDIR): go-dep mkdir
@echo 'go build $@'
@rm -rf ${BUILDDIR}/$(shell basename $@)
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/$(shell basename $@) ./$@
# Build pgmanager with embedded frontend
.PHONY: pgmanager
pgmanager: go-dep wasmbuild-dep tidy mkdir
@echo 'go generate frontend'
@$(GO) generate -tags frontend ./pkg/manager/httphandler/...
@echo 'go build cmd/pgmanager'
@$(GO) build -tags frontend $(BUILD_FLAGS) -o ${BUILDDIR}/pgmanager ./cmd/pgmanager
# Build the docker image
.PHONY: docker
docker: docker-dep ${NPM_DIR}
@echo build docker image ${DOCKER_TAG} OS=${OS} ARCH=${ARCH} SOURCE=${DOCKER_SOURCE} VERSION=${VERSION}
@${DOCKER} build \
--tag ${DOCKER_TAG} \
--build-arg ARCH=${ARCH} \
--build-arg OS=${OS} \
--build-arg SOURCE=${DOCKER_SOURCE} \
--build-arg VERSION=${VERSION} \
-f etc/Dockerfile .
# Push docker container
.PHONY: docker-push
docker-push: docker-dep
@echo push docker image: ${DOCKER_TAG}
@${DOCKER} push ${DOCKER_TAG}
# Print out the version
.PHONY: docker-version
docker-version: docker-dep
@echo "tag=${VERSION}"
# Rules for testing
.PHONY: test
test: tidy
@echo 'running tests...'
@$(GO) test .
@$(GO) test ./pkg/...
# Other rules
.PHONY: mkdir
mkdir:
@install -d $(BUILDDIR)
.PHONY: go-dep tidy
tidy:
@echo 'go tidy'
@$(GO) mod tidy
.PHONY: clean
clean: tidy
@echo 'clean'
@rm -fr $(BUILDDIR)
@$(GO) clean
###############################################################################
# DEPENDENCIES
.PHONY: go-dep
go-dep:
@test -f "${GO}" && test -x "${GO}" || (echo "Missing go binary" && exit 1)
.PHONY: docker-dep
docker-dep:
@test -f "${DOCKER}" && test -x "${DOCKER}" || (echo "Missing docker binary" && exit 1)
.PHONY: wasmbuild-dep
wasmbuild-dep:
@test -f "${WASMBUILD}" && test -x "${WASMBUILD}" || (echo "Missing wasmbuild binary" && exit 1)