This repository has been archived by the owner on Apr 21, 2021. It is now read-only.
forked from eksctl-io/eksctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.docker
108 lines (91 loc) · 4.82 KB
/
Makefile.docker
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
include Makefile.common
build_image_input := Dockerfile install-build-deps.sh go.mod go.sum
# We use git object hashes for determining the input files used for any given build image
# E.g. given `weaveworks/eksctl-build:e6e8800773d3adf8e7999a23dcdb07414c66a4da` one can
# run `git show e6e8800773d3adf8e7999a23dcdb07414c66a4da` to get contents of `.build_image_manifest`,
# and `git show <hash>` for each of the hashes in the manifest to determine contents of each of the
# files used in `$(build_image_input)` at the time.
build_image_tag_cmd = git ls-tree --full-tree @ -- .build_image_manifest | awk '{ print $$3 }'
build_image_tag = $(shell $(build_image_tag_cmd))
build_image_name = weaveworks/eksctl-build:$(build_image_tag)
intermidiate_container_name = eksctl-build-$(unique_tag)
docker_build := time docker build
# We should eventually switch to buildkit, as it has a many feature and cleaner output with timing info,
# but right now 'docker build' doesn't allow us to export build cache images, so we cannot use it yet
# docker_build := env DOCKER_BUILDKIT=1 $(docker_build)
update_build_image_manifest = git ls-tree --full-tree @ -- $(build_image_input) > .build_image_manifest
.PHONY: check-build-image-manifest-up-to-date
check-build-image-manifest-up-to-date: ## Update build image manifest and commits the changes
git diff --quiet -- $(build_image_input) \
|| (git --no-pager diff $(build_image_input); exit 1)
$(update_build_image_manifest)
git diff --quiet -- .build_image_manifest \
|| (git --no-pager diff .build_image_manifest; echo "HINT: to fix this, run 'make -f Makefile.docker update-build-image-manifest'"; exit 1)
.PHONY: update-build-image-manifest
update-build-image-manifest: ## Update build image manifest and commits the changes
$(update_build_image_manifest)
git diff --quiet -- .build_image_manifest \
|| git commit --quiet .build_image_manifest --message 'Update build image manifest'
@# There is no portable way of using sed -i on BSD and GNU, so we use temporary files instead
for i in .github/workflows/commit.yaml .circleci/config.yml ; do \
sed "s|\(weaveworks/eksctl-build\):.*$$|\1:$$($(build_image_tag_cmd))|" "$${i}" > "$${i}.sedtmp" && mv "$${i}.sedtmp" "$${i}" ; \
done
git diff --quiet -- .github/workflows/commit.yaml .circleci/config.yml \
|| git commit --quiet .github/workflows/commit.yaml .circleci/config.yml --message 'Update build image in CI'
.PHONY: build-image
build-image: check-build-image-manifest-up-to-date ## Build the build image that has all of external dependencies
-docker pull $(build_image_name)
rm -rf .build_image_context
mkdir .build_image_context
cp $(build_image_input) .build_image_context/
@# git only ensures owner's perssions are set, it ignores group and other's permissions,
@# we need to force permissions here to avoid cache misses
chmod go-wrx .build_image_context/*
$(docker_build) \
--iidfile=.build_image.iid \
--cache-from=$(build_image_name) \
--tag=$(build_image_name) \
.build_image_context/
.PHONY: push-build-image
push-build-image: build-image ## Push the build image to the Docker Hub registry
docker push $(build_image_name)
.PHONY: push-build-image-github
push-build-image-github: build-image ## Push the build image to the GitHub registry
docker tag $(build_image_name) docker.pkg.github.com/errordeveloper/eksctl/build:$(build_image_tag)
docker push docker.pkg.github.com/errordeveloper/eksctl/build:$(build_image_tag)
.PHONY: intermediate-image
intermediate-image: build-image ## Build the intermediate image that has all artefacts
time docker run \
--tty \
--name=$(intermidiate_container_name) \
--volume=$(git_toplevel):/src \
$(build_image_name) /src/eksctl-image-builder.sh \
|| (docker rm $(intermidiate_container_name) ; exit 1)
time docker commit $(intermidiate_container_name) $(intermediate_image_name) \
&& docker rm $(intermidiate_container_name)
.PHONY: eksctl-image
eksctl-image: intermediate-image ## Build the eksctl image that has release artefacts and no build dependencies
printf 'FROM scratch\nCMD eksctl\nCOPY --from=%s /out /' $(intermediate_image_name) \
| $(docker_build) \
--iidfile=.eksctl_image.iid \
--tag="$(eksctl_image_name)" -
.PHONY: build test
build test: ## Run targets from Makefile using the build image
time docker run \
--tty \
--rm \
--volume=$(git_toplevel):/src \
$(build_image_name) make $@
docker_run_release_script = docker run \
--env=GITHUB_TOKEN \
--env=CIRCLE_TAG \
--env=CIRCLE_PROJECT_USERNAME \
--volume=$(git_toplevel):/src \
--workdir=/src \
$(intermediate_image_name)
.PHONY: release-candidate
release-candidate: eksctl-image ## Create a new eksctl release candidate
$(call docker_run_release_script) ./do-release-candidate.sh
.PHONY: release
release: eksctl-image ## Create a new eksctl release
$(call docker_run_release_script) ./do-release.sh