forked from neo4j/docker-neo4j
-
Notifications
You must be signed in to change notification settings - Fork 0
/
make-common.mk
144 lines (120 loc) · 4.84 KB
/
make-common.mk
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.SECONDEXPANSION:
.SECONDARY:
ifeq ($(origin .RECIPEPREFIX), undefined)
$(error This Make does not support .RECIPEPREFIX. Please use GNU Make 4.0 or later)
endif
.RECIPEPREFIX = >
ifndef NEO4JVERSION
$(error NEO4JVERSION is not set)
endif
tarball = neo4j-$(1)-$(2)-unix.tar.gz
dist_site := https://dist.neo4j.org
series := $(shell echo "$(NEO4JVERSION)" | sed -E 's/^([0-9]+\.[0-9]+)\..*/\1/')
out/%/.sentinel: tmp/image-%/.sentinel
> mkdir -p $(@D)
> cp -r $(<D)/* $(@D)
> touch $@
## building the image ##
build: build-community build-enterprise
.PHONY: build
build-community: tmp/.image-id-community tmp/.image-id-neo4j-admin-community tmp/devenv-community.env
.PHONY: build-community
build-enterprise: tmp/.image-id-enterprise tmp/.image-id-neo4j-admin-enterprise tmp/devenv-enterprise.env
.PHONY: build-enterprise
tmp/devenv-%.env: tmp/.image-id-% tmp/.image-id-neo4j-admin-%
> echo "NEO4JVERSION=$(NEO4JVERSION)" > ${@}
> echo "NEO4J_IMAGE=$$(cat tmp/.image-id-${*})" >> ${@}
> echo "NEO4JADMIN_IMAGE=$$(cat tmp/.image-id-neo4j-admin-${*})" >> ${@}
> echo "NEO4J_EDITION=${*}" >> ${@}
# copy the releaseable version of the image to the output folder.
out/%/.sentinel: tmp/image-%/.sentinel
> mkdir -p $(@D)
> cp -r $(<D)/* $(@D)
> touch $@
# create image from local build context
tmp/.image-id-%: tmp/local-context-%/.sentinel
> mkdir -p $(@D)
> image=test/$$RANDOM
> docker build --tag=$$image \
--build-arg="NEO4J_URI=file:///startup/$(call tarball,$*,$(NEO4JVERSION))" \
$(<D)
> echo -n $$image >$@
tmp/.image-id-neo4j-admin-%: tmp/local-context-neo4j-admin-%/.sentinel
> mkdir -p $(@D)
> image=test/admin-$$RANDOM
> docker build --tag=$$image \
--build-arg="NEO4J_URI=file:///startup/$(call tarball,$*,$(NEO4JVERSION))" \
$(<D)
> echo -n $$image >$@
## local build context ##
# tmp/local-context-{community,enterprise} is a local folder containing the
# Dockerfile/entrypoint/Neo4j/etc required to build a complete image locally.
tmp/local-context-%/.sentinel: tmp/image-%/.sentinel in/$(call tarball,%,$(NEO4JVERSION))
> rm -rf $(@D)
> mkdir -p $(@D)
> cp -r $(<D)/* $(@D)
> cp $(filter %.tar.gz,$^) $(@D)/local-package
> touch $@
tmp/local-context-neo4j-admin-%/.sentinel: tmp/image-neo4j-admin-%/.sentinel in/$(call tarball,%,$(NEO4JVERSION))
> rm -rf $(@D)
> mkdir -p $(@D)
> cp -r $(<D)/* $(@D)
> cp $(filter %.tar.gz,$^) $(@D)/local-package
> touch $@
## create Dockerfiles ##
# tmp/image-{community,enterprise} contains the Dockerfile, docker-entrypoint.sh and plugins.json
# with all the variables (eg tini) filled in, but *NO Neo4j tar*. This is what gets released to dockerhub.
# You can successfully do `docker build tmp/image-{community,enterprise}` so long as the Neo4j is a released version.
tmp/image-%/.sentinel: docker-image-src/$(series)/Dockerfile docker-image-src/$(series)/docker-entrypoint.sh \
in/$(call tarball,%,$(NEO4JVERSION))
> mkdir -p $(@D)/local-package
> cp docker-image-src/common/* $(@D)/local-package
> cp $(filter %.sh,$^) $(@D)/local-package
> NEO4JPLUGINS_OVERRIDE=docker-image-src/$(series)/neo4jlabs-plugins.json
> if [ -e $${NEO4JPLUGINS_OVERRIDE} ]; then cp $${NEO4JPLUGINS_OVERRIDE} $(@D)/local-package; fi
> sha=$$(shasum --algorithm=256 $(filter %.tar.gz,$^) | cut -d' ' -f1)
> <$(filter %/Dockerfile,$^) sed \
-e "s|%%NEO4J_BASE_IMAGE%%|${NEO4J_BASE_IMAGE}|" \
-e "s|%%NEO4J_SHA%%|$${sha}|" \
-e "s|%%NEO4J_TARBALL%%|$(call tarball,$*,$(NEO4JVERSION))|" \
-e "s|%%NEO4J_EDITION%%|$*|" \
-e "s|%%NEO4J_DIST_SITE%%|$(dist_site)|" \
>$(@D)/Dockerfile
> touch $(@D)/local-package/.sentinel
> touch $@
tmp/image-neo4j-admin-%/.sentinel: docker-image-src/$(series)/neo4j-admin/Dockerfile \
docker-image-src/$(series)/neo4j-admin/docker-entrypoint.sh \
in/$(call tarball,%,$(NEO4JVERSION))
> mkdir -p $(@D)
> cp $(filter %/docker-entrypoint.sh,$^) $(@D)/docker-entrypoint.sh
> sha=$$(shasum --algorithm=256 $(filter %.tar.gz,$^) | cut -d' ' -f1)
> <$(filter %/Dockerfile,$^) sed \
-e "s|%%NEO4J_BASE_IMAGE%%|${NEO4J_BASE_IMAGE}|" \
-e "s|%%NEO4J_SHA%%|$${sha}|" \
-e "s|%%NEO4J_TARBALL%%|$(call tarball,$*,$(NEO4JVERSION))|" \
-e "s|%%NEO4J_EDITION%%|$*|" \
-e "s|%%NEO4J_DIST_SITE%%|$(dist_site)|" \
>$(@D)/Dockerfile
> mkdir -p $(@D)/local-package
> touch $(@D)/local-package/.sentinel
> touch $@
fetch_tarball = curl --fail --silent --show-error --location --remote-name \
$(dist_site)/$(call tarball,$(1),$(NEO4JVERSION))
cache: in/neo4j-%-$(NEO4JVERSION)-unix.tar.gz
.PHONY: cache
in/neo4j-community-$(NEO4JVERSION)-unix.tar.gz:
> mkdir -p in
> cd in
> $(call fetch_tarball,community)
in/neo4j-enterprise-$(NEO4JVERSION)-unix.tar.gz:
> mkdir -p in
> cd in
> $(call fetch_tarball,enterprise)
clean:
> rm -rf tmp
> rm -rf out
.PHONY: clean