forked from elastic/kibana-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
123 lines (101 loc) · 4.33 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
SHELL=/bin/bash
ELASTIC_REGISTRY ?= docker.elastic.co
export PATH := ./bin:./venv/bin:$(PATH)
# Determine the version to build. Override by setting ELASTIC_VERSION env var.
ELASTIC_VERSION := $(shell ./bin/elastic-version)
ifdef STAGING_BUILD_NUM
VERSION_TAG=$(ELASTIC_VERSION)-${STAGING_BUILD_NUM}
else
VERSION_TAG=$(ELASTIC_VERSION)
endif
PYTHON ?= $(shell command -v python3.5 || command -v python3.6)
# Build different images for OSS-only and full versions.
IMAGE_FLAVORS ?= oss full
# Which image will get the default, unqualified name?
DEFAULT_IMAGE_FLAVOR ?= full
IMAGE_TAG ?= $(ELASTIC_REGISTRY)/kibana/kibana
HTTPD ?= kibana-docker-artifact-server
FIGLET := pyfiglet -w 160 -f puffy
all: build test
test: lint docker-compose
$(foreach FLAVOR, $(IMAGE_FLAVORS), \
$(FIGLET) "test: $(FLAVOR)"; \
./bin/pytest tests --image-flavor=$(FLAVOR); \
)
lint: venv
flake8 tests
build: dockerfile
docker pull centos:7
$(foreach FLAVOR, $(IMAGE_FLAVORS), \
$(FIGLET) "build: $(FLAVOR)"; \
docker build -t $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) \
-f build/kibana/Dockerfile-$(FLAVOR) build/kibana; \
if [[ $(FLAVOR) == $(DEFAULT_IMAGE_FLAVOR) ]]; then \
docker tag $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) $(IMAGE_TAG):$(VERSION_TAG); \
fi; \
)
release-manager-snapshot: clean
ARTIFACTS_DIR=$(ARTIFACTS_DIR) ELASTIC_VERSION=$(ELASTIC_VERSION)-SNAPSHOT make build-from-local-artifacts
release-manager-release: clean
ARTIFACTS_DIR=$(ARTIFACTS_DIR) ELASTIC_VERSION=$(ELASTIC_VERSION) make build-from-local-artifacts
# Build from artifacts on the local filesystem, using an http server (running
# in a container) to provide the artifacts to the Dockerfile.
build-from-local-artifacts: venv dockerfile docker-compose
docker run --rm -d --name=$(HTTPD) \
--network=host -v $(ARTIFACTS_DIR):/mnt \
python:3 bash -c 'cd /mnt && python3 -m http.server'
timeout 120 bash -c 'until curl -s localhost:8000 > /dev/null; do sleep 1; done'
-$(foreach FLAVOR, $(IMAGE_FLAVORS), \
pyfiglet -f puffy -w 160 "Building: $(FLAVOR)"; \
docker build --network=host -t $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) -f build/kibana/Dockerfile-$(FLAVOR) build/kibana || \
(docker kill $(HTTPD); false); \
if [[ $(FLAVOR) == $(DEFAULT_IMAGE_FLAVOR) ]]; then \
docker tag $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) $(IMAGE_TAG):$(VERSION_TAG); \
fi; \
)
-docker kill $(HTTPD)
# Build images from the latest snapshots on snapshots.elastic.co
from-snapshot:
rm -rf snapshots
(cd snapshots/kibana/target && \
wget https://snapshots.elastic.co/downloads/kibana/kibana-$(ELASTIC_VERSION)-SNAPSHOT-linux-x86_64.tar.gz && \
wget https://snapshots.elastic.co/downloads/kibana/kibana-oss-$(ELASTIC_VERSION)-SNAPSHOT-linux-x86_64.tar.gz)
ARTIFACTS_DIR=$$PWD/snapshots make release-manager-snapshot
# Push the image to the dedicated push endpoint at "push.docker.elastic.co"
push: test
$(foreach FLAVOR, $(IMAGE_FLAVORS), \
docker tag $(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG) push.$(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG); \
docker push push.$(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG); \
docker rmi push.$(IMAGE_TAG)-$(FLAVOR):$(VERSION_TAG); \
)
# Also push the default version, with no suffix like '-oss' or '-full'
docker tag $(IMAGE_TAG):$(VERSION_TAG) push.$(IMAGE_TAG):$(VERSION_TAG);
docker push push.$(IMAGE_TAG):$(VERSION_TAG);
docker rmi push.$(IMAGE_TAG):$(VERSION_TAG);
clean-test:
$(TEST_COMPOSE) down
$(TEST_COMPOSE) rm --force
venv: requirements.txt
test -d venv || virtualenv --python=$(PYTHON) venv
pip install -r requirements.txt
touch venv
# Generate the Dockerfiles from Jinja2 templates.
dockerfile: venv templates/Dockerfile.j2
$(foreach FLAVOR, $(IMAGE_FLAVORS), \
jinja2 \
-D image_flavor='$(FLAVOR)' \
-D elastic_version='$(ELASTIC_VERSION)' \
-D staging_build_num='$(STAGING_BUILD_NUM)' \
-D artifacts_dir='$(ARTIFACTS_DIR)' \
templates/Dockerfile.j2 > build/kibana/Dockerfile-$(FLAVOR); \
)
# Generate docker-compose files from Jinja2 templates.
docker-compose: venv
$(foreach FLAVOR, $(IMAGE_FLAVORS), \
jinja2 \
-D version_tag='$(VERSION_TAG)' \
-D image_flavor='$(FLAVOR)' \
templates/docker-compose.yml.j2 > docker-compose-$(FLAVOR).yml; \
)
ln -sf docker-compose-$(DEFAULT_IMAGE_FLAVOR).yml docker-compose.yml
.PHONY: build clean flake8 push pytest test dockerfile docker-compose