Skip to content

Commit db5cf72

Browse files
committed
working around INFRA-24621
1 parent da79d43 commit db5cf72

File tree

5 files changed

+89
-6
lines changed

5 files changed

+89
-6
lines changed

dev-support/jenkins/Jenkinsfile

+30-1
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,34 @@ pipeline {
4949
YETUS_DRIVER = "${WORKDIR}/${YETUS_DRIVER_REL}"
5050
YETUSDIR = "${WORKDIR}/${YETUS_REL}"
5151
PLUGINS = 'all'
52+
// workaround for INFRA-24621
53+
NON_ROOT_AS_JENKINS = 'true'
54+
NON_ROOT_USER = """${sh(
55+
returnStdout: true,
56+
script: '''#!/usr/bin/env bash
57+
set -e
58+
59+
if [ "${DEBUG}" = 'true' ] ; then
60+
set -x
61+
fi
62+
63+
whoami
64+
'''
65+
)}
66+
""".trim()
67+
NON_ROOT_UID = """${sh(
68+
returnStdout: true,
69+
script: '''#!/usr/bin/env bash
70+
set -e
71+
72+
if [ "${DEBUG}" = 'true' ] ; then
73+
set -x
74+
fi
75+
76+
echo "${UID}"
77+
'''
78+
)}
79+
""".trim()
5280
}
5381

5482
parameters {
@@ -78,6 +106,7 @@ pipeline {
78106
usernameVariable: 'GITHUB_USER'
79107
)]) {
80108
sh label: 'test-patch', script: '''#!/bin/bash -e
109+
docker container run --rm --user=0 --mount type=bind,source=${SOURCEDIR},target=/sourcedir --workdir /sourcedir alpine:latest rm -rfv hbase-kubernetes-deployment/hbase-kubernetes-kustomize/target
81110
printenv 2>&1 | sort
82111
echo "[INFO] Launching Yetus via ${YETUS_DRIVER}"
83112
"${YETUS_DRIVER}"
@@ -138,4 +167,4 @@ pipeline {
138167
}
139168
}
140169
}
141-
}
170+
}

hbase-kubernetes-deployment/hbase-kubernetes-testing-image/pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@
6262
<argument>-c</argument>
6363
<argument>
6464
2>&amp;1 \
65-
docker buildx bake \
65+
src/build/shell/exec_docker_buildx_bake.sh \
6666
--print \
6767
--file src/main/docker/docker-bake.hcl \
6868
--file src/main/docker/docker-bake.override.hcl
@@ -83,7 +83,7 @@
8383
<argument>-c</argument>
8484
<argument>
8585
2>&amp;1 \
86-
docker buildx bake \
86+
src/build/shell/exec_docker_buildx_bake.sh \
8787
--progress plain \
8888
--pull \
8989
--load \
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env bash
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+
# A work-around for INFRA-24621 establishing container user name and id in the jenkins environment.
20+
# When `NON_ROOT_AS_JENKINS=true`, injects the values of `NON_ROOT_USER` and `NON_ROOT_UID` into
21+
# the bake environment.
22+
23+
set -e
24+
set -o pipefail
25+
set -x
26+
27+
declare NON_ROOT_AS_JENKINS
28+
declare NON_ROOT_USER
29+
declare NON_ROOT_UID
30+
declare -a bake_args=( "$@" )
31+
32+
NON_ROOT_AS_JENKINS="${NON_ROOT_AS_JENKINS:-false}"
33+
34+
if [ "${NON_ROOT_AS_JENKINS}" = 'true' ] ; then
35+
bake_args+=( "--set=*.args.NON_ROOT_USER=${NON_ROOT_USER}" )
36+
bake_args+=( "--set=*.args.NON_ROOT_USER_ID=${NON_ROOT_UID}" )
37+
fi
38+
39+
docker buildx bake "${bake_args[@]}"

hbase-kubernetes-deployment/hbase-kubernetes-testing-image/src/main/docker/Dockerfile

+6-3
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,9 @@ RUN tar xzf "/tmp/${KUSTOMIZE_BIN_TGZ}" \
129129
FROM ${IMG_BASE}:${IMG_BASE_TAG} as final
130130
ARG IMG_BASE
131131
ARG IMG_BASE_TAG
132+
ARG NON_ROOT_USER
133+
ARG NON_ROOT_USER_ID
134+
ARG NON_ROOT_USER_HOME
132135

133136
COPY --from=yq /usr/bin/yq /usr/bin/yq
134137
COPY --from=kubectl /tmp/kubectl /usr/local/bin/
@@ -137,9 +140,9 @@ COPY --from=kustomize /tmp/kustomize /usr/local/bin/
137140
COPY src/main/docker/entrypoint.sh /bin/
138141

139142
# nonroot user as defined in https://github.com/GoogleContainerTools/distroless
140-
ENV NON_ROOT_USER=nonroot
141-
ENV NON_ROOT_USER_ID=65532
142-
ENV NON_ROOT_USER_HOME=/home/nonroot
143+
ENV NON_ROOT_USER="${NON_ROOT_USER}"
144+
ENV NON_ROOT_USER_ID="${NON_ROOT_USER_ID}"
145+
ENV NON_ROOT_USER_HOME="${NON_ROOT_USER_HOME}"
143146

144147
# hadolint ignore=DL3018
145148
RUN apk add --update --no-cache \

hbase-kubernetes-deployment/hbase-kubernetes-testing-image/src/main/docker/docker-bake.hcl

+12
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ variable KUSTOMIZE_BIN_ARM64_TGZ_URL {}
4141
variable KUSTOMIZE_BIN_ARM64_TGZ {}
4242

4343
# output variables
44+
variable NON_ROOT_USER {
45+
default = "nonroot"
46+
}
47+
variable NON_ROOT_USER_ID {
48+
default = "65532"
49+
}
50+
variable NON_ROOT_USER_HOME {
51+
default = "/home/${NON_ROOT_USER}"
52+
}
4453
variable USER {
4554
default = "apache"
4655
}
@@ -78,6 +87,9 @@ target kuttl {
7887
KUSTOMIZE_BIN_AMD64_TGZ = KUSTOMIZE_BIN_AMD64_TGZ
7988
KUSTOMIZE_BIN_ARM64_TGZ_URL = KUSTOMIZE_BIN_ARM64_TGZ_URL
8089
KUSTOMIZE_BIN_ARM64_TGZ = KUSTOMIZE_BIN_ARM64_TGZ
90+
NON_ROOT_USER = NON_ROOT_USER
91+
NON_ROOT_USER_ID = NON_ROOT_USER_ID
92+
NON_ROOT_USER_HOME = NON_ROOT_USER_HOME
8193
}
8294
target = "final"
8395
platforms = [

0 commit comments

Comments
 (0)