Skip to content

Commit f3c9560

Browse files
committed
HBASE-27829 Introduce build for kuttl image, basis for dev/test environment
1 parent 7434174 commit f3c9560

6 files changed

Lines changed: 432 additions & 0 deletions

File tree

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,11 @@ linklint-*.zip
2121
linklint/
2222
.checkstyle
2323
**/.checkstyle
24+
25+
# kubernetes download artifacts
26+
*kubectl*
27+
*checksums.txt
28+
awscli-exe*
29+
*aws_cli_public_key
30+
*.tar.gz
31+
*.sig
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
# syntax=docker/dockerfile:1.2
2+
#
3+
# Licensed to the Apache Software Foundation (ASF) under one
4+
# or more contributor license agreements. See the NOTICE file
5+
# distributed with this work for additional information
6+
# regarding copyright ownership. The ASF licenses this file
7+
# to you under the Apache License, Version 2.0 (the
8+
# "License"); you may not use this file except in compliance
9+
# with the License. You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
ARG IMG_BASE='golang'
20+
ARG IMG_BASE_TAG='1.19-alpine'
21+
ARG BASE_IMG_ALPINE='alpine'
22+
ARG BASE_IMG_TAG_ALPINE='latest'
23+
ARG YQ_IMG='mikefarah/yq'
24+
ARG YQ_IMG_TAG='latest'
25+
26+
FROM ${BASE_IMG_ALPINE}:${BASE_IMG_TAG_ALPINE} as alpine
27+
28+
FROM ${YQ_IMG}:${YQ_IMG_TAG} as yq
29+
30+
## -- Stages kubectl_${TARGETARCH} --
31+
# Define stages that facilitate bringing in platform-specific binaries.
32+
FROM alpine as kubectl_amd64
33+
ARG KUBECTL_SHA_AMD64
34+
ARG KUBECTL_BIN_AMD64
35+
WORKDIR /tmp/
36+
COPY ${KUBECTL_SHA_AMD64} /tmp/
37+
COPY ${KUBECTL_BIN_AMD64} /tmp/
38+
RUN echo "$(cat "${KUBECTL_SHA_AMD64}") ${KUBECTL_BIN_AMD64}" | sha512sum -c
39+
40+
FROM alpine as kubectl_arm64
41+
ARG KUBECTL_SHA_ARM64
42+
ARG KUBECTL_BIN_ARM64
43+
WORKDIR /tmp/
44+
COPY ${KUBECTL_SHA_ARM64} /tmp/
45+
COPY ${KUBECTL_BIN_ARM64} /tmp/
46+
RUN echo "$(cat "${KUBECTL_SHA_ARM64}") ${KUBECTL_BIN_ARM64}" | sha512sum -c
47+
48+
ARG TARGETARCH
49+
FROM kubectl_${TARGETARCH} as kubectl
50+
RUN mv /tmp/kubectl_* /tmp/kubectl \
51+
&& chmod a+x /tmp/kubectl
52+
53+
## -- Stages kuttl_${TARGETARCH} --
54+
# Define stages that facilitate bringing in platform-specific binaries.
55+
FROM alpine as kuttl_amd64
56+
ARG KUTTL_CHECKSUMS
57+
ARG KUTTL_BIN_AMD64
58+
WORKDIR /tmp/
59+
COPY ${KUTTL_CHECKSUMS} /tmp/
60+
COPY ${KUTTL_BIN_AMD64} /tmp/
61+
RUN sha256sum -c <(grep "${KUTTL_BIN_AMD64}" "${KUTTL_CHECKSUMS}")
62+
63+
FROM alpine as kuttl_arm64
64+
ARG KUTTL_CHECKSUMS
65+
ARG KUTTL_BIN_ARM64
66+
WORKDIR /tmp/
67+
COPY ${KUTTL_CHECKSUMS} /tmp/
68+
COPY ${KUTTL_BIN_ARM64} /tmp/
69+
RUN sha256sum -c <(grep "${KUTTL_BIN_ARM64}" "${KUTTL_CHECKSUMS}")
70+
71+
ARG TARGETARCH
72+
FROM kuttl_${TARGETARCH} as kuttl
73+
RUN mv /tmp/kubectl-kuttl_* /tmp/kubectl-kuttl \
74+
&& chmod a+x /tmp/kubectl-kuttl
75+
76+
## -- Stages kustomize_${TARGETARCH} --
77+
# Define stages that facilitate bringing in platform-specific binaries.
78+
FROM alpine as kustomize_amd64
79+
ARG KUSTOMIZE_CHECKSUMS
80+
ARG KUSTOMIZE_BIN_AMD64_TGZ
81+
WORKDIR /tmp/
82+
COPY ${KUSTOMIZE_CHECKSUMS} /tmp/
83+
COPY ${KUSTOMIZE_BIN_AMD64_TGZ} /tmp/
84+
RUN sha256sum -c <(grep "${KUSTOMIZE_BIN_AMD64_TGZ}" "${KUSTOMIZE_CHECKSUMS}") \
85+
&& cd /tmp \
86+
&& tar xzf "${KUSTOMIZE_BIN_AMD64_TGZ}"
87+
88+
FROM alpine as kustomize_arm64
89+
ARG KUSTOMIZE_CHECKSUMS
90+
ARG KUSTOMIZE_BIN_ARM64_TGZ
91+
WORKDIR /tmp/
92+
COPY ${KUSTOMIZE_CHECKSUMS} /tmp/
93+
COPY ${KUSTOMIZE_BIN_ARM64_TGZ} /tmp/
94+
RUN sha256sum -c <(grep "${KUSTOMIZE_BIN_ARM64_TGZ}" "${KUSTOMIZE_CHECKSUMS}")
95+
96+
ARG TARGETARCH
97+
FROM kustomize_${TARGETARCH} as kustomize
98+
RUN tar xzf /tmp/kustomize_*.tar.gz \
99+
&& chmod a+x /tmp/kustomize
100+
101+
## -- Stage aws_cli_builder
102+
FROM alpine as aws_cli_builder
103+
ARG AWS_CLI_PUBLIC_KEY
104+
ARG AWS_CLI_SOURCES_TGZ
105+
ARG AWS_CLI_SOURCES_TGZ_SIG
106+
COPY ${AWS_CLI_PUBLIC_KEY} /tmp/
107+
COPY ${AWS_CLI_SOURCES_TGZ} /tmp/
108+
COPY ${AWS_CLI_SOURCES_TGZ_SIG} /tmp/
109+
WORKDIR /tmp
110+
RUN apk add --no-cache \
111+
build-base \
112+
cmake \
113+
gnupg \
114+
groff \
115+
libffi-dev \
116+
python3 \
117+
python3-dev \
118+
tar \
119+
&& gpg --import /tmp/aws_cli_public_key \
120+
&& gpg --verify /tmp/${AWS_CLI_SOURCES_TGZ_SIG} /tmp/${AWS_CLI_SOURCES_TGZ} \
121+
&& tar -xzf ${AWS_CLI_SOURCES_TGZ} \
122+
&& cd "${AWS_CLI_SOURCES_TGZ%.tar.gz}" \
123+
&& ./configure --with-install-type=portable-exe --with-download-deps \
124+
&& make \
125+
&& make install \
126+
&& rm -rf \
127+
/usr/local/lib/aws-cli/aws_completer \
128+
/usr/local/lib/aws-cli/awscli/data/ac.index \
129+
/usr/local/lib/aws-cli/awscli/examples \
130+
&& find /usr/local/lib/aws-cli/awscli/data -name completions-1*.json -delete \
131+
&& find /usr/local/lib/aws-cli/awscli/botocore/data -name examples-1.json -delete \
132+
&& cd /usr/local/lib/aws-cli \
133+
&& for a in *.so* ; do test -f /lib/$a && rm $a; done
134+
135+
FROM ${IMG_BASE}:${IMG_BASE_TAG} as final
136+
ARG IMG_BASE
137+
ARG IMG_BASE_TAG
138+
139+
COPY --from=yq /usr/bin/yq /usr/bin/yq
140+
COPY --from=kubectl /tmp/kubectl /usr/local/bin/
141+
COPY --from=kuttl /tmp/kubectl-kuttl /usr/local/bin/
142+
COPY --from=kustomize /tmp/kustomize /usr/local/bin/
143+
COPY --from=aws_cli_builder /usr/local/lib/aws-cli/ /usr/local/lib/aws-cli/
144+
COPY hbase-kubernetes-deployment/dockerfiles/kuttl/entrypoint.sh /bin/
145+
146+
# install python, needed by aws-cli
147+
ENV LANG C.UTF-8
148+
RUN apk add --update --no-cache \
149+
bash \
150+
docker-cli \
151+
groff \
152+
less \
153+
python3 \
154+
python3-dev \
155+
&& ln -s /usr/local/lib/aws-cli/aws /usr/local/bin/aws \
156+
&& /usr/local/bin/aws --version
157+
158+
# replicate the test-related bits generated by `kubebuilder` into its Makefile.
159+
ENV GOBIN="${GOPATH}/bin"
160+
ENV ENVTEST_K8S_VERSION='1.23.x'
161+
RUN chmod a+x /bin/entrypoint.sh \
162+
&& go install sigs.k8s.io/controller-runtime/tools/setup-envtest@latest \
163+
&& "${GOBIN}/setup-envtest" use "${ENVTEST_K8S_VERSION}"
164+
# disable downloading remote content henceforth
165+
ENV ENVTEST_INSTALLED_ONLY=true
166+
167+
ENTRYPOINT ["/bin/entrypoint.sh"]
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<!--
2+
Licensed to the Apache Software Foundation (ASF) under one
3+
or more contributor license agreements. See the NOTICE file
4+
distributed with this work for additional information
5+
regarding copyright ownership. The ASF licenses this file
6+
to you under the Apache License, Version 2.0 (the
7+
"License"); you may not use this file except in compliance
8+
with the License. You may obtain a copy of the License at
9+
10+
http://www.apache.org/licenses/LICENSE-2.0
11+
12+
Unless required by applicable law or agreed to in writing, software
13+
distributed under the License is distributed on an "AS IS" BASIS,
14+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
See the License for the specific language governing permissions and
16+
limitations under the License.
17+
-->
18+
19+
# dockerfiles/kuttl
20+
21+
This directory builds a docker image containing everything required to run `kubectl-kuttl` in
22+
"mocked control plane" mode. This image is used as the basis for both dev and test environments.
23+
24+
## Build
25+
26+
Building the docker image locally is a little picky because there's lots of input arguments
27+
(download of dependencies is externalized from the build) and because binary file names required
28+
by the build do not necissarily match the distribution artifact names. Start by downloading all
29+
the relevant binaries for your platform and naming them appropriately, see comments in
30+
[docker-bake.override.hcl](./docker-bake.override.hcl) for details.
31+
32+
Next, create a buildx context that supports (optionally) multi-platform images. If you've created
33+
this context previously, it's enough to ensure that it's active via `docker buildx ls`.
34+
35+
```shell
36+
$ docker buildx create \
37+
--driver docker-container \
38+
--platform linux/amd64,linux/arm64 \
39+
--use \
40+
--bootstrap
41+
```
42+
43+
Finally, build the image using,
44+
45+
```shell
46+
$ docker buildx bake \
47+
--file dockerfiles/kuttl/docker-bake.hcl \
48+
--file dockerfiles/kuttl/docker-bake.override.hcl \
49+
--pull \
50+
--load
51+
```
52+
53+
This exports an image to your local repository that is tagged as `${USER}/hbase/operator-tools/kuttl:latest`.
54+
55+
## Usage
56+
57+
The image is configured with `kuttle` as the entrypoint.
58+
59+
```shell
60+
$ docker container run --rm -it ${USER}/hbase/operator-tools/kuttl:latest --help
61+
62+
```
63+
64+
Running tests in the image requires mounting the workspace into the container image and passing
65+
appropriate parameters to `kuttl`. For example, run the "small" tests like this:
66+
67+
```shell
68+
$ docker container run \
69+
--mount type=bind,source=$(pwd),target=/workspace \
70+
--workdir /workspace \
71+
${USER}/hbase/operator-tools/kuttl:latest \
72+
--config tests/kuttl-test-small.yaml
73+
```
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
#
17+
# A convenience script for build the kuttl image.
18+
# See hbase-kubernetes-deployment/dockerfiles/kuttl/README.md
19+
#
20+
21+
# input variables
22+
variable KUBECTL_SHA_AMD64 {}
23+
variable KUBECTL_BIN_AMD64 {}
24+
variable KUBECTL_SHA_ARM64 {}
25+
variable KUBECTL_BIN_ARM64 {}
26+
variable KUTTL_CHECKSUMS {}
27+
variable KUTTL_BIN_AMD64 {}
28+
variable KUTTL_BIN_ARM64 {}
29+
variable KUSTOMIZE_CHECKSUMS {}
30+
variable KUSTOMIZE_BIN_AMD64_TGZ {}
31+
variable KUSTOMIZE_BIN_ARM64_TGZ {}
32+
variable AWS_CLI_PUBLIC_KEY {}
33+
variable AWS_CLI_SOURCES_TGZ {}
34+
variable AWS_CLI_SOURCES_TGZ_SIG {}
35+
36+
# output variables
37+
variable USER {}
38+
variable IMAGE_TAG {
39+
default = "latest"
40+
}
41+
variable IMAGE_NAME {
42+
default = "${USER}/hbase/operator-tools/kuttl"
43+
}
44+
45+
group default {
46+
targets = [ "kuttl" ]
47+
}
48+
49+
target kuttl {
50+
dockerfile = "hbase-kubernetes-deployment/dockerfiles/kuttl/Dockerfile"
51+
args = {
52+
KUBECTL_SHA_AMD64 = KUBECTL_SHA_AMD64
53+
KUBECTL_BIN_AMD64 = KUBECTL_BIN_AMD64
54+
KUBECTL_SHA_ARM64 = KUBECTL_SHA_ARM64
55+
KUBECTL_BIN_ARM64 = KUBECTL_BIN_ARM64
56+
KUTTL_CHECKSUMS = KUTTL_CHECKSUMS
57+
KUTTL_BIN_AMD64 = KUTTL_BIN_AMD64
58+
KUTTL_BIN_ARM64 = KUTTL_BIN_ARM64
59+
KUSTOMIZE_CHECKSUMS = KUSTOMIZE_CHECKSUMS
60+
KUSTOMIZE_BIN_AMD64_TGZ = KUSTOMIZE_BIN_AMD64_TGZ
61+
KUSTOMIZE_BIN_ARM64_TGZ = KUSTOMIZE_BIN_ARM64_TGZ
62+
AWS_CLI_PUBLIC_KEY = AWS_CLI_PUBLIC_KEY
63+
AWS_CLI_SOURCES_TGZ = AWS_CLI_SOURCES_TGZ
64+
AWS_CLI_SOURCES_TGZ_SIG = AWS_CLI_SOURCES_TGZ_SIG
65+
}
66+
target = "final"
67+
platforms = [
68+
"linux/amd64",
69+
"linux/arm64"
70+
]
71+
tags = [ "${IMAGE_NAME}:${IMAGE_TAG}" ]
72+
}

0 commit comments

Comments
 (0)