forked from jenkinsci/docker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
165 lines (123 loc) · 5.77 KB
/
Makefile
File metadata and controls
165 lines (123 loc) · 5.77 KB
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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
ROOT_DIR="$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))/"
## For Docker <=20.04
export DOCKER_BUILDKIT=1
## For Docker <=20.04
export DOCKER_CLI_EXPERIMENTAL=enabled
## Required to have docker build output always printed on stdout
export BUILDKIT_PROGRESS=plain
current_arch := $(shell uname -m)
export ARCH ?= $(shell case $(current_arch) in (x86_64) echo "amd64" ;; (i386) echo "386";; (aarch64|arm64) echo "arm64" ;; (armv6*) echo "arm/v6";; (armv7*) echo "arm/v7";; (ppc64*|s390*|riscv*) echo $(current_arch);; (*) echo "UNKNOWN-CPU";; esac)
all: shellcheck build test
# Set to 'true' to disable parellel tests
DISABLE_PARALLEL_TESTS ?= false
# Set to the path of a specific test suite to restrict execution only to this
# default is "all test suites in the "tests/" directory
TEST_SUITES ?= $(CURDIR)/tests
##### Macros
## Check the presence of a CLI in the current PATH
check_cli = type "$(1)" >/dev/null 2>&1 || { echo "Error: command '$(1)' required but not found. Exiting." ; exit 1 ; }
## Check if a given image exists in the current manifest docker-bake.hcl
check_image = make --silent list | grep -w '$(1)' >/dev/null 2>&1 || { echo "Error: the image '$(1)' does not exist in manifest for the platform 'linux/$(ARCH)'. Please check the output of 'make list'. Exiting." ; exit 1 ; }
## Base "docker buildx base" command to be reused everywhere
bake_base_cli := docker buildx bake -f docker-bake.hcl --load
check-reqs:
## Build requirements
@$(call check_cli,bash)
@$(call check_cli,git)
@$(call check_cli,docker)
@docker info | grep 'buildx:' >/dev/null 2>&1 || { echo "Error: Docker BuildX plugin required but not found. Exiting." ; exit 1 ; }
## Test requirements
@$(call check_cli,curl)
@$(call check_cli,jq)
shellcheck:
$(ROOT_DIR)/tools/shellcheck -e SC1091 jenkins-support *.sh
build: check-reqs
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' $(shell make --silent list)
build-%: check-reqs
@$(call check_image,$*)
@set -x; $(bake_base_cli) --set '*.platform=linux/$(ARCH)' '$*'
show:
@$(bake_base_cli) linux --print
list: check-reqs
@set -x; make --silent show | jq -r '.target | path(.. | select(.platforms[] | contains("linux/$(ARCH)"))?) | add'
bats:
git clone https://github.com/bats-core/bats-core bats ;\
cd bats ;\
git checkout eac1e9d047b2b8137d85307fc94439c90bdc25ae
prepare-test: bats check-reqs
git submodule update --init --recursive
mkdir -p target
## Define bats options based on environment
# common flags for all tests
bats_flags := $(TEST_SUITES)
# if DISABLE_PARALLEL_TESTS true, then disable parallel execution
ifneq (true,$(DISABLE_PARALLEL_TESTS))
# If the GNU 'parallel' command line is absent, then disable parallel execution
parallel_cli := $(shell command -v parallel 2>/dev/null)
ifneq (,$(parallel_cli))
# If parallel execution is enabled, then set 2 tests per core available for the Docker Engine
test-%: PARALLEL_JOBS ?= $(shell echo $$(( $(shell docker run --rm alpine grep -c processor /proc/cpuinfo) * 2)))
test-%: bats_flags += --jobs $(PARALLEL_JOBS)
endif
endif
test-%: prepare-test
# Check that the image exists in the manifest
@$(call check_image,$*)
# Ensure that the image is built
@make --silent build-$*
# Execute the test harness and write result to a TAP file
IMAGE=$* bats/bin/bats $(bats_flags) | tee target/results-$*.tap
# convert TAP to JUNIT
docker run --rm -v "$(CURDIR)":/usr/src/app -w /usr/src/app node:12-alpine \
sh -c "npm install tap-xunit -g && cat target/results-$*.tap | tap-xunit --package='jenkinsci.docker.$*' > target/junit-results-$*.xml"
test: prepare-test
@make --silent list | while read image; do make --silent "test-$${image}"; done
test-install-plugins: prepare-test
@make --silent test TEST_SUITES=tests/install-plugins.bats tests/plugins-cli.bats
publish:
./.ci/publish.sh
publish-images-variant:
./.ci/publish-images.sh --variant ${VARIANT} --arch ${ARCH} ;
publish-images-debian:
./.ci/publish-images.sh --variant debian --arch ${ARCH} ;
publish-images-alpine:
./.ci/publish-images.sh --variant alpine --arch ${ARCH} ;
publish-images-slim:
./.ci/publish-images.sh --variant slim --arch ${ARCH} ;
publish-images: publish-images-debian publish-images-alpine publish-images-slim
publish-tags-debian:
./.ci/publish-tags.sh --tag debian ;
publish-tag-alpine:
./.ci/publish-tags.sh --tag alpine ;
publish-tags-slim:
./.ci/publish-tags.sh --tag slim ;
publish-tags-lts-debian:
./.ci/publish-tags.sh --tag lts-debian ;
publish-tag-lts-alpine:
./.ci/publish-tags.sh --tag lts-alpine ;
publish-tags-lts-slim:
./.ci/publish-tags.sh --tag lts-slim ;
publish-tags: publish-tags-debian publish-tag-alpine publish-tags-slim publish-tags-lts-debian publish-tag-lts-alpine publish-tags-lts-slim
publish-manifests-debian:
./.ci/publish-manifests.sh --variant debian ;
publish-manifests-alpine:
./.ci/publish-manifests.sh --variant alpine ;
publish-manifests-slim:
./.ci/publish-manifests.sh --variant slim ;
publish-manifests-lts-debian:
./.ci/publish-manifests.sh --variant lts-debian ;
publish-manifests-lts-alpine:
./.ci/publish-manifests.sh --variant lts-alpine ;
publish-manifests-lts-slim:
./.ci/publish-manifests.sh --variant lts-slim ;
publish-manifests-versions-debian:
./.ci/publish-manifests.sh --variant versions-debian ;
publish-manifests-versions-alpine:
./.ci/publish-manifests.sh --variant versions-alpine ;
publish-manifests-versions-slim:
./.ci/publish-manifests.sh --variant versions-slim ;
publish-manifests: publish-manifests-debian publish-manifests-alpine publish-manifests-slim publish-manifests-lts-debian publish-manifests-lts-alpine publish-manifests-lts-slim publish-manifests-versions-debian publish-manifests-versions-alpine publish-manifests-versions-slim
clean:
rm -rf tests/test_helper/bats-*; \
rm -rf bats
.PHONY: shellcheck check-reqs build clean test list test-install-plugins show