-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
68 lines (56 loc) · 1.54 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# Copyright (c) Ultraviolet
# SPDX-License-Identifier: Apache-2.0
CUBE_DOCKER_IMAGE_NAME ?= ghcr.io/ultravioletrs/cube/proxy
CGO_ENABLED ?= 0
GOOS ?= linux
GOARCH ?= amd64
BUILD_DIR = build
TIME=$(shell date -u '+%Y-%m-%dT%H:%M:%SZ')
VERSION ?= $(shell git describe --abbrev=0 --tags 2>/dev/null || echo 'v0.0.0')
COMMIT ?= $(shell git rev-parse HEAD)
define compile_service
CGO_ENABLED=$(CGO_ENABLED) GOOS=$(GOOS) GOARCH=$(GOARCH) \
go build -ldflags "-s -w \
-X 'github.com/absmach/magistrala.BuildTime=$(TIME)' \
-X 'github.com/absmach/magistrala.Version=$(VERSION)' \
-X 'github.com/absmach/magistrala.Commit=$(COMMIT)'" \
-o ${BUILD_DIR}/cube-proxy cmd/main.go
endef
define make_docker
docker build \
--no-cache \
--build-arg GOOS=$(GOOS) \
--build-arg GOARCH=$(GOARCH) \
--build-arg VERSION=$(VERSION) \
--build-arg COMMIT=$(COMMIT) \
--tag=$(CUBE_DOCKER_IMAGE_NAME):$(VERSION) \
--tag=$(CUBE_DOCKER_IMAGE_NAME):latest \
-f docker/Dockerfile .
endef
define make_docker_dev
docker build \
--no-cache \
--tag=$(CUBE_DOCKER_IMAGE_NAME):$(VERSION) \
--tag=$(CUBE_DOCKER_IMAGE_NAME):latest \
-f docker/Dockerfile.dev ./build
endef
define docker_push
docker push $(CUBE_DOCKER_IMAGE_NAME):$(VERSION)
docker push $(CUBE_DOCKER_IMAGE_NAME):latest
endef
.PHONY: build
build:
$(call compile_service)
.PHONY: docker
docker:
$(call make_docker)
.PHONY: docker-dev
docker-dev:
$(call make_docker_dev)
all: build docker-dev
clean:
rm -rf build
lint:
golangci-lint run --config .golangci.yaml
latest: docker
$(call docker_push)