forked from postgis/docker-postgis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
149 lines (119 loc) · 4.95 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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# When processing the rules for tagging and pushing container images with the
# "latest" tag, the following variable will be the version that is considered
# to be the latest.
LATEST_VERSION=15-3.3
# The following flags are set based on VERSION and VARIANT environment variables
# that may have been specified, and are used by rules to determine which
# versions/variants are to be processed. If no VERSION or VARIANT environment
# variables were specified, process everything (the default).
do_default=true
do_alpine=true
# The following logic evaluates VERSION and VARIANT variables that may have
# been previously specified, and modifies the "do" flags depending on the values.
# The VERSIONS variable is also set to contain the version(s) to be processed.
ifdef VERSION
VERSIONS=$(VERSION) # If a version was specified, VERSIONS only contains the specified version
ifdef VARIANT # If a variant is specified, unset all do flags and allow subsequent logic to set them again where appropriate
do_default=false
do_alpine=false
ifeq ($(VARIANT),default)
do_default=true
endif
ifeq ($(VARIANT),alpine)
do_alpine=true
endif
endif
ifeq ("$(wildcard $(VERSION)/alpine)","") # If no alpine subdirectory exists, don't process the alpine version
do_alpine=false
endif
else # If no version was specified, VERSIONS should contain all versions
VERSIONS = $(foreach df,$(wildcard */Dockerfile),$(df:%/Dockerfile=%))
endif
# The "latest" tag will only be provided for default images (no variant) so
# only define the dependencies when the default image will be built.
ifeq ($(do_default),true)
BUILD_LATEST_DEP=build-$(LATEST_VERSION)
PUSH_LATEST_DEP=push-$(LATEST_VERSION)
PUSH_DEP=push-latest $(PUSH_LATEST_DEP)
# The "latest" tag shouldn't be processed if a VERSION was explicitly
# specified but does not correspond to the latest version.
ifdef VERSION
ifneq ($(VERSION),$(LATEST_VERSION))
PUSH_LATEST_DEP=
BUILD_LATEST_DEP=
PUSH_DEP=
endif
endif
endif
# The repository and image names default to the official but can be overriden
# via environment variables.
REPO_NAME ?= postgis
IMAGE_NAME ?= postgis
DOCKER=docker
DOCKERHUB_DESC_IMG=peterevans/dockerhub-description:latest
GIT=git
OFFIMG_LOCAL_CLONE=$(HOME)/official-images
OFFIMG_REPO_URL=https://github.com/docker-library/official-images.git
build: $(foreach version,$(VERSIONS),build-$(version))
all: update build test
update:
$(DOCKER) run --rm -v $$(pwd):/work -w /work buildpack-deps ./update.sh
### RULES FOR BUILDING ###
define build-version
build-$1:
ifeq ($(do_default),true)
$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1) $1
endif
ifeq ($(do_alpine),true)
ifneq ("$(wildcard $1/alpine)","")
$(DOCKER) build --pull -t $(REPO_NAME)/$(IMAGE_NAME):$(shell echo $1)-alpine $1/alpine
endif
endif
endef
$(foreach version,$(VERSIONS),$(eval $(call build-version,$(version))))
## RULES FOR TESTING ###
test-prepare:
ifeq ("$(wildcard $(OFFIMG_LOCAL_CLONE))","")
$(GIT) clone $(OFFIMG_REPO_URL) $(OFFIMG_LOCAL_CLONE)
endif
test: $(foreach version,$(VERSIONS),test-$(version))
define test-version
test-$1: test-prepare build-$1
ifeq ($(do_default),true)
$(OFFIMG_LOCAL_CLONE)/test/run.sh -c $(OFFIMG_LOCAL_CLONE)/test/config.sh -c test/postgis-config.sh $(REPO_NAME)/$(IMAGE_NAME):$(version)
endif
ifeq ($(do_alpine),true)
ifneq ("$(wildcard $1/alpine)","")
$(OFFIMG_LOCAL_CLONE)/test/run.sh -c $(OFFIMG_LOCAL_CLONE)/test/config.sh -c test/postgis-config.sh $(REPO_NAME)/$(IMAGE_NAME):$(version)-alpine
endif
endif
endef
$(foreach version,$(VERSIONS),$(eval $(call test-version,$(version))))
### RULES FOR TAGGING ###
tag-latest: $(BUILD_LATEST_DEP)
$(DOCKER) image tag $(REPO_NAME)/$(IMAGE_NAME):$(LATEST_VERSION) $(REPO_NAME)/$(IMAGE_NAME):latest
### RULES FOR PUSHING ###
push: $(foreach version,$(VERSIONS),push-$(version)) $(PUSH_DEP)
define push-version
push-$1: test-$1
ifeq ($(do_default),true)
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):$(version)
endif
ifeq ($(do_alpine),true)
ifneq ("$(wildcard $1/alpine)","")
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):$(version)-alpine
endif
endif
endef
$(foreach version,$(VERSIONS),$(eval $(call push-version,$(version))))
push-latest: tag-latest $(PUSH_LATEST_DEP)
$(DOCKER) image push $(REPO_NAME)/$(IMAGE_NAME):latest
@$(DOCKER) run -v "$(PWD)":/workspace \
-e DOCKERHUB_USERNAME='$(DOCKERHUB_USERNAME)' \
-e DOCKERHUB_PASSWORD='$(DOCKERHUB_ACCESS_TOKEN)' \
-e DOCKERHUB_REPOSITORY='$(REPO_NAME)/$(IMAGE_NAME)' \
-e README_FILEPATH='/workspace/README.md' $(DOCKERHUB_DESC_IMG)
.PHONY: build all update test-prepare test tag-latest push push-latest \
$(foreach version,$(VERSIONS),build-$(version)) \
$(foreach version,$(VERSIONS),test-$(version)) \
$(foreach version,$(VERSIONS),push-$(version))