Skip to content

Commit a894f24

Browse files
authored
Fix: druid reduce image size (#1039)
* remove recursive chmod/chown from final image * fixes & cleanup * adapted changelog * fix group assigment * use check permissions script * add note
1 parent 47d35ce commit a894f24

File tree

2 files changed

+34
-14
lines changed

2 files changed

+34
-14
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ All notable changes to this project will be documented in this file.
1010
`check-permissions-ownership.sh` provided in stackable-base image ([#1029]).
1111
- hbase: check for correct permissions and ownerships in /stackable folder via
1212
`check-permissions-ownership.sh` provided in stackable-base image ([#1028]).
13+
- druid: check for correct permissions and ownerships in /stackable folder via
14+
`check-permissions-ownership.sh` provided in stackable-base image ([#1039]).
1315
- spark-connect-client: A new image for Spark connect tests and demos ([#1034])
1416
- nifi: check for correct permissions and ownerships in /stackable folder via
1517
`check-permissions-ownership.sh` provided in stackable-base image ([#1027]).
@@ -27,6 +29,7 @@ All notable changes to this project will be documented in this file.
2729

2830
- hadoop: reduce docker image size by removing the recursive chown/chmods in the final image ([#1029]).
2931
- hbase: reduce docker image size by removing the recursive chown/chmods in the final image ([#1028]).
32+
- druid: reduce docker image size by removing the recursive chown/chmods in the final image ([#1039]).
3033
- nifi: reduce docker image size by removing the recursive chown/chmods in the final image ([#1027]).
3134
- opa: reduce docker image size by removing the recursive chown/chmods in the final image ([#1038]).
3235
- spark-k8s: reduce docker image size by removing the recursive chown/chmods in the final image ([#1042]).
@@ -39,6 +42,7 @@ All notable changes to this project will be documented in this file.
3942
[#1029]: https://github.com/stackabletech/docker-images/pull/1029
4043
[#1034]: https://github.com/stackabletech/docker-images/pull/1034
4144
[#1038]: https://github.com/stackabletech/docker-images/pull/1038
45+
[#1039]: https://github.com/stackabletech/docker-images/pull/1039
4246
[#1042]: https://github.com/stackabletech/docker-images/pull/1042
4347
[#1044]: https://github.com/stackabletech/docker-images/pull/1044
4448
[#1050]: https://github.com/stackabletech/docker-images/pull/1050

druid/Dockerfile

Lines changed: 30 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ microdnf update
2525
#
2626
# patch: Required for the apply-patches.sh script
2727
microdnf install \
28-
python-pyyaml \
29-
patch
28+
python-pyyaml \
29+
patch
3030

3131
microdnf clean all
3232
rm -rf /var/cache/yum
@@ -47,9 +47,9 @@ COPY --chown=stackable:0 druid/stackable/patches/${PRODUCT} /stackable/apache-dr
4747
# are still working in the cache directory.
4848

4949
RUN --mount=type=cache,id=maven-${PRODUCT},uid=${STACKABLE_USER_UID},target=/stackable/.m2/repository \
50-
--mount=type=cache,id=npm-${PRODUCT},uid=${STACKABLE_USER_UID},target=/stackable/.npm \
51-
--mount=type=cache,id=cache-${PRODUCT},uid=${STACKABLE_USER_UID},target=/stackable/.cache \
52-
<<EOF
50+
--mount=type=cache,id=npm-${PRODUCT},uid=${STACKABLE_USER_UID},target=/stackable/.npm \
51+
--mount=type=cache,id=cache-${PRODUCT},uid=${STACKABLE_USER_UID},target=/stackable/.cache \
52+
<<EOF
5353
curl "https://repo.stackable.tech/repository/packages/druid/apache-druid-${PRODUCT}-src.tar.gz" | tar -xzC .
5454
cd apache-druid-${PRODUCT}-src
5555
./patches/apply_patches.sh ${PRODUCT}
@@ -74,6 +74,9 @@ fi
7474

7575
# Install OPA authorizer extension.
7676
curl "https://repo.stackable.tech/repository/packages/druid/druid-opa-authorizer-${AUTHORIZER}.tar.gz" | tar -xzC /stackable/apache-druid-${PRODUCT}/extensions
77+
78+
# change groups
79+
chmod -R g=u /stackable
7780
EOF
7881

7982
FROM stackable/image/java-base AS final
@@ -106,32 +109,45 @@ LABEL io.k8s.display-name="${NAME}"
106109

107110

108111
COPY --chown=${STACKABLE_USER_UID}:0 --from=druid-builder /stackable/apache-druid-${PRODUCT} /stackable/apache-druid-${PRODUCT}
112+
109113
COPY --chown=${STACKABLE_USER_UID}:0 druid/stackable/bin /stackable/bin
110114
COPY --chown=${STACKABLE_USER_UID}:0 druid/licenses /licenses
111115

112116
RUN <<EOF
113117
microdnf update
114118
microdnf clean all
115119
rpm -qa --qf "%{NAME}-%{VERSION}-%{RELEASE}\n" | sort > /stackable/package_manifest.txt
120+
chown ${STACKABLE_USER_UID}:0 /stackable/package_manifest.txt
121+
chmod g=u /stackable/package_manifest.txt
116122
rm -rf /var/cache/yum
117123

118-
ln -s /stackable/apache-druid-${PRODUCT} /stackable/druid
124+
ln -sf /stackable/apache-druid-${PRODUCT} /stackable/druid
125+
chown -h ${STACKABLE_USER_UID}:0 stackable/druid
119126

120127
# Force to overwrite the existing 'run-druid'
121128
ln -sf /stackable/bin/run-druid /stackable/druid/bin/run-druid
129+
chown -h ${STACKABLE_USER_UID}:0 /stackable/druid/bin/run-druid
122130

123-
# All files and folders owned by root group to support running as arbitrary users.
124-
# This is best practice as all container users will belong to the root group (0).
125-
chown -R ${STACKABLE_USER_UID}:0 /stackable
126-
chmod -R g=u /stackable
131+
# fix missing permissions
132+
chmod -R g=u /stackable/bin
133+
chmod g=u /stackable/apache-druid-${PRODUCT}
127134
EOF
128135

129136
# ----------------------------------------
130-
# Attention: We are changing the group of all files in /stackable directly above
131-
# If you do any file based actions (copying / creating etc.) below this comment you
132-
# absolutely need to make sure that the correct permissions are applied!
133-
# chown ${STACKABLE_USER_UID}:0
137+
# Checks
138+
# This section is to run final checks to ensure the created final images
139+
# adhere to several minimal requirements like:
140+
# - check file permissions and ownerships
141+
# ----------------------------------------
142+
143+
# Check that permissions and ownership in /stackable are set correctly
144+
# This will fail and stop the build if any mismatches are found.
145+
RUN <<EOF
146+
/bin/check-permissions-ownership.sh /stackable ${STACKABLE_USER_UID} 0
147+
EOF
148+
134149
# ----------------------------------------
150+
# Attention: Do not perform any file based actions (copying/creating etc.) below this comment because the permissions would not be checked.
135151

136152
USER ${STACKABLE_USER_UID}
137153
ENV PATH="${PATH}":/stackable/druid/bin

0 commit comments

Comments
 (0)