generated from caicloud/common-template-project
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Makefile
97 lines (78 loc) · 3.45 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
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
# Copyright 2019 The Caicloud Authors.
#
# The old school Makefile, following are required targets. The Makefile is written
# to allow building multiple images. You are free to add more targets or change
# existing implementations, as long as the semantics are preserved.
#
# make - default to 'build' target
# make lint - code analysis
# make test - run unit test (or plus integration test)
# make build - alias to build-local target
# make build-local - build code
# make container - build containers
# $ docker login REGISTRY -u username -p xxxxx
# make push - push containers
# make clean - clean up targets
#
# The makefile is also responsible to populate project version information.
#
#
# Tweak the variables based on your project.
#
# Current version of the project.
VERSION ?= $(shell git describe --tags --always --dirty)
# Available cpus for compiling, please refer to https://github.com/caicloud/engineering/issues/8186#issuecomment-518656946 for more information.
CPUS ?= $(shell bash scripts/read_cpus_available.sh)
# Container REGISTRY.
REGISTRY ?= cargo.dev.caicloud.xyz/release
BUILD_ENV ?= local
# cache_folder for yarn (default folder: https://github.com/caicloud/cyclone/blob/master/pkg/server/biz/accelerator/accelerate.go#L72)
YARN_CACHE_DIR ?= /root/.npm
# Track code version with Docker Label.
DOCKER_LABELS ?= git-describe="$(shell date -u +v%Y%m%d)-$(shell git describe --tags --always --dirty)"
# image prefix and suffix added to targets.
# The final built images are:
# $[REGISTRY]/$[IMAGE_PREFIX]$[TARGET]$[IMAGE_SUFFIX]:$[VERSION]
# $[TARGET] is an item from $[TARGETS].
IMAGE_PREFIX ?= $(strip )
IMAGE_SUFFIX ?= $(strip )
#
# These variables should not need tweaking.
#
# Target images. You can build multiple images for a single project.
TARGETS := x-web
# Build direcotory.
BUILD_DIR := ./build
#
# Define all targets. At least the following commands are required:
#
# All targets.
.PHONY: build container push lint test install
# install node_modules with cache
install:
sh -c 'yarn --cache-folder $(YARN_CACHE_DIR)'
lint:
sh -c 'yarn lint'
test:
sh -c 'yarn test'
build:
@for target in $(TARGETS); do \
bash -c 'set -ex && \
yarn && \
CPUS=$(CPUS) yarn run build'; \
done
container: build
@for target in $(TARGETS); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker build -t $(REGISTRY)/$${image}:$(VERSION) \
--label $(DOCKER_LABELS) \
-f $(BUILD_DIR)/$${target}/Dockerfile .; \
if [ $(BUILD_ENV) == local ]; then \
docker image prune --filter label="stage=web_cacher"; \
fi \
done
push: container
@for target in $(TARGETS); do \
image=$(IMAGE_PREFIX)$${target}$(IMAGE_SUFFIX); \
docker push $(REGISTRY)/$${image}:$(VERSION); \
done