forked from eksctl-io/eksctl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile.docker
98 lines (81 loc) · 4.06 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
include Makefile.common
image_manifest_file = .docker/build_image_manifest
# 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_file = .docker/image_tag
build_image_tag = $(shell cat $(build_image_tag_file))
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)
.PHONY: update-build-image-tag
update-build-image-tag:
./build-image-manifest.sh > $(image_manifest_file)
git hash-object $(image_manifest_file) > $(build_image_tag_file)
.PHONY: check-build-image-manifest-up-to-date
check-build-image-manifest-up-to-date: update-build-image-tag ## Update build image manifest and commits the changes
git diff --quiet -- $(image_manifest_file) \
|| (git --no-pager diff $(image_manifest_file); echo "HINT: to fix this, run 'make -f Makefile.docker update-build-image-tag'"; exit 1)
.PHONY: commit-new-image-tag
commit-new-image-tag: update-build-image-tag ## Update build image manifest and commits the changes
git commit --quiet $(image_manifest_file) $(build_image_tag_file) --message 'Update build image manifest and tag file'
.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)
cp .requirements install-build-deps.sh go.mod go.sum .docker/
$(docker_build) \
--iidfile=.build_image.iid \
--cache-from=$(build_image_name) \
--tag=$(build_image_name) \
--file Dockerfile \
.docker/
.PHONY: push-build-image
push-build-image: build-image ## Push the build image to the Docker Hub registry
docker push $(build_image_name)
echo "Remember to commit the image_tag and build_image_manifest files"
.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 \
--env=CIRCLE_PROJECT_REPONAME \
--volume=$(git_toplevel):/src \
--workdir=/src \
$(build_image_name)
.PHONY: release-candidate
release-candidate: ## Create a new eksctl release candidate
$(call docker_run_release_script) ./do-release-candidate.sh
.PHONY: release
release: ## Create a new eksctl release
$(call docker_run_release_script) ./do-release.sh