forked from mesosphere/charts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
126 lines (106 loc) · 4.22 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
HELM_VERSION := v2.13.0
STABLE_CHARTS = $(wildcard stable/*/Chart.yaml)
STABLE_TARGETS = $(shell hack/chart_destination.sh $(STABLE_CHARTS))
STAGING_CHARTS = $(wildcard staging/*/Chart.yaml)
STAGING_TARGETS = $(shell hack/chart_destination.sh $(STAGING_CHARTS))
GIT_REMOTE_URL ?= $(shell git remote get-url origin)
# Extract the github user from the origin remote url.
# This let's the 'publish' task work with forks.
# Supports both SSH and HTTPS git url formats:
# - https://github.com/mesosphere/charts.git
# - [email protected]:mesosphere/charts.git
GITHUB_USER := $(shell git remote get-url origin | sed -E 's|.*github.com[/:]([^/]+)/charts.*|\1|')
GIT_REF ?= $(shell git rev-parse HEAD)
LAST_COMMIT_MESSAGE := $(shell git log -1 --pretty=format:'%B')
CT_VERSION ?= v2.4.0
TMPDIR := $(shell mktemp -d)
ifeq ($(shell uname),Darwin)
# OSX requires /private prefix as symlink doesn't work when
# mounting /var/folders/
TMPDIR := /private${TMPDIR}
endif
HELM := $(shell bash -c "command -v helm")
ifeq ($(HELM),)
HELM := $(TMPDIR)/helm
endif
ifeq (,$(wildcard /teamcity/system/git))
DRUN := docker run -t --rm -u $(shell id -u):$(shell id -g) \
-v ${PWD}:/charts -v ${PWD}/test/ct.yaml:/etc/ct/ct.yaml -v $(TMPDIR):/.helm \
-w /charts quay.io/helmpack/chart-testing:$(CT_VERSION)
else
DRUN := docker run -t --rm -v /teamcity/system/git:/teamcity/system/git -v ${PWD}:/charts \
-v ${PWD}/test/ct.yaml:/etc/ct/ct.yaml -w /charts \
quay.io/helmpack/chart-testing:$(CT_VERSION)
endif
.SECONDEXPANSION:
.PHONY: all
all: stagingrepo stablerepo
.PHONY: clean
clean:
rm -rf gh-pages
.PHONY: stagingrepo
stagingrepo: $(STAGING_TARGETS) | gh-pages/staging/index.yaml
.PHONY: stablerepo
stablerepo: $(STABLE_TARGETS) | gh-pages/stable/index.yaml
.PHONY: publish
publish:
-git remote add publish $(GIT_REMOTE_URL) >/dev/null 2>&1
rm -rf gh-pages
git fetch publish gh-pages
git worktree add gh-pages/ publish/gh-pages
$(MAKE) GIT_REF=$(GIT_REF) all
cd gh-pages && \
git add -A . && \
git commit -m "$(LAST_COMMIT_MESSAGE)" && \
git push publish HEAD:gh-pages
git worktree remove gh-pages/
rm -rf gh-pages
$(HELM):
ifeq ($(HELM),$(TMPDIR)/helm)
curl -Ls https://get.helm.sh/helm-$(HELM_VERSION)-linux-amd64.tar.gz | tar xz -C $(TMPDIR) --strip-components=1 'linux-amd64/helm'
endif
# Deterministically create helm packages by:
#
# - Using `helm package` to create the initial package (useful for including chart dependencies
# properly)
# - Untarring the package
# - Recreate the package using `tar`, speficying time of the last git commit to the package
# source as the files' mtime, as well as ordering files deterministically, meaning that unchanged
# content will result in the same output package
# - Use `gzip -n` to prevent any timestamps being added to `gzip` headers in archive.
$(STABLE_TARGETS) $(STAGING_TARGETS): $$(wildcard $$(patsubst gh-pages/%.tgz,%/*,$$@)) $$(wildcard $$(patsubst gh-pages/%.tgz,%/*/*,$$@))
$(STABLE_TARGETS) $(STAGING_TARGETS): $(TMPDIR)/.helm/repository/local/index.yaml
@mkdir -p $(shell dirname $@)
$(eval PACKAGE_SRC := $(shell echo $@ | sed 's@gh-pages/\(.*\)-[v0-9][0-9.]*.tgz@\1@'))
$(eval UNPACKED_TMP := $(shell mktemp -d))
$(HELM) --home $(TMPDIR)/.helm package $(PACKAGE_SRC) -d $(shell dirname $@)
tar -xzmf $@ -C $(UNPACKED_TMP)
tar -c \
--owner=root:0 --group=root:0 --numeric-owner \
--no-recursion \
--mtime="@$(shell git log -1 --format="%at" $(GIT_REF) -- $(PACKAGE_SRC))" \
-C $(UNPACKED_TMP) \
$$(find $(UNPACKED_TMP) -printf '%P\n' | sort) | gzip -n > $@
rm -rf $(UNPACKED_TMP)
%/index.yaml: $(STABLE_TARGETS) $(STAGING_TARGETS)
%/index.yaml: $(TMPDIR)/.helm/repository/local/index.yaml
@mkdir -p $(patsubst %/index.yaml,%,$@)
$(HELM) --home $(TMPDIR)/.helm repo index $(patsubst %/index.yaml,%,$@) --url=https://$(GITHUB_USER).github.io/charts/$(patsubst gh-pages/%index.yaml,%,$@)
$(TMPDIR)/.helm/repository/local/index.yaml: $(HELM)
$(HELM) --home $(TMPDIR)/.helm init --client-only
.PHONY: ct.lint
ct.lint:
ifneq (,$(wildcard /teamcity/system/git))
$(DRUN) git fetch origin master
endif
$(DRUN) ct lint
.PHONY: ct.test
ct.test:
ifneq (,$(wildcard /teamcity/system/git))
$(DRUN) git fetch origin master
endif
test/e2e-kind.sh $(CT_VERSION)
.PHONY: lint
lint: ct.lint
.PHONY: test
test: ct.test