-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathMakefile
129 lines (104 loc) · 3.35 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
MAKEFLAGS += --warn-undefined-variables
MAKEFLAGS += --no-builtin-rules
##
## Debug
##
print-% : ; $(info $* is a $(flavor $*) variable set to [$($*)]) @true
###
GEMSPECS = $(shell find . -maxdepth 3 -name \*.gemspec | sed 's/^.\///g')
GEMS = $(GEMSPECS:%.gemspec=%.gem)
PROJECTS = $(shell find . -maxdepth 3 -name Rakefile -exec dirname {} \;)
### GEM HANDLING
# Build a .gem from a .gemspec
%.gem: %.gemspec
@echo ===================================================================
@echo "Building gem $@"
@echo ===================================================================
@cd $(dir $@)
@gem build -o $(notdir $@) $(notdir $<)
# Build all gems
gems: $(GEMS)
# Push a built gem
%.gem.push: %.gem
@echo ===================================================================
@echo "Pushing gem $<"
@echo ===================================================================
@gem push $<
# Push all gems
gems.push: $(addsuffix .push, $(GEMS))
# Remove built gems
clean:
@rm -rf *.gem */**/*.gem .build
### BUNDLES
bundle: $(addsuffix .bundle,$(PROJECTS))
define bundle-targets
$1.bundle:
@echo ===================================================================
@echo "Bundling $1"
@echo ===================================================================
cd $1 && bundle install
endef
$(foreach project,$(PROJECTS),$(eval $(call bundle-targets,$(project))))
#####
### ADDITIONAL DEPS / TARGETS
#####
-include contrib/*/makefile.mk
#####
### TESTS
#####
tests: gems $(addsuffix .test,$(PROJECTS))
define test-targets
$1.test::
@echo ===================================================================
@echo "Executing $1 tests"
@echo ===================================================================
cd $1 && bundle exec rake test
endef
$(foreach project,$(PROJECTS),$(eval $(call test-targets,$(project))))
#####
### DOCKER
#####
# Specify which ruby version is used as base
DEFAULT_MRI_VERSION := 3.1
MRI_VERSION := $(or ${MRI_VERSION},${MRI_VERSION},$(DEFAULT_MRI_VERSION))
VERSION := $(or ${VERSION},${VERSION},latest)
TINY = ${VERSION}
MINOR = $(shell echo '${TINY}' | cut -f'1-2' -d'.')
# not used until 1.0
# MAJOR = $(shell echo '${MINOR}' | cut -f'1-2' -d'.')
DOCKER_REGISTRY := $(or ${DOCKER_REGISTRY},${DOCKER_REGISTRY},docker.io/enspirit)
PLATFORMS := linux/amd64,linux/arm64/v8
TARGETS := api web
IMAGES = $(TARGETS:%=.build/%/Dockerfile.built)
images: .build/buildx.builder ${IMAGES}
.build/buildx.builder:
mkdir -p .build
docker buildx create --use --name startback
touch .build/buildx.builder
ifeq (${VERSION},latest)
.build/%/Dockerfile.built: Dockerfile .build/
@docker buildx build -f $< ./\
--build-arg MRI_VERSION=${MRI_VERSION} \
--push \
--platform ${PLATFORMS} \
--target $* \
-t $(DOCKER_REGISTRY)/startback:$* \
-t $(DOCKER_REGISTRY)/startback:$*-ruby${MRI_VERSION}
else
.build/%/Dockerfile.built: Dockerfile
@docker buildx build -f $< ./ \
--push \
--build-arg MRI_VERSION=${MRI_VERSION} \
--platform ${PLATFORMS} \
--target $* \
-t $(DOCKER_REGISTRY)/startback:$* \
-t $(DOCKER_REGISTRY)/startback:$*-${TINY} \
-t $(DOCKER_REGISTRY)/startback:$*-${MINOR} \
-t $(DOCKER_REGISTRY)/startback:$*-ruby${MRI_VERSION} \
-t $(DOCKER_REGISTRY)/startback:$*-$(TINY)-ruby${MRI_VERSION} \
-t $(DOCKER_REGISTRY)/startback:$*-$(MINOR)-ruby${MRI_VERSION}
endif