Skip to content

Commit 4e71af3

Browse files
committed
remove recursive chmod/chown in final image
1 parent b96184f commit 4e71af3

File tree

1 file changed

+23
-18
lines changed

1 file changed

+23
-18
lines changed

opa/Dockerfile

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ cd ./opa-bundle-builder
2929
. "$HOME/.cargo/env"
3030
rustup toolchain install
3131
cargo --quiet build --release
32+
# set correct groups
33+
chmod -R g=u /opa-bundle-builder/target/release/
3234
EOF
3335

3436
FROM stackable/image/stackable-base AS multilog-builder
@@ -58,12 +60,15 @@ RUN patch < /daemontools/conf-cc.patch && \
5860

5961
WORKDIR /daemontools/admin/daemontools-${DAEMONTOOLS_VERSION}
6062

61-
RUN package/install
63+
RUN package/install && \
64+
# set correct groups
65+
chmod g=u /daemontools/admin/daemontools/command/multilog
6266

6367
FROM stackable/image/stackable-base AS opa-builder
6468

6569
ARG PRODUCT
6670
ARG RELEASE
71+
ARG STACKABLE_USER_UID
6772
ARG TARGETARCH
6873
ARG TARGETOS
6974

@@ -81,11 +86,15 @@ RUN microdnf update && \
8186
tar && \
8287
microdnf clean all
8388

89+
COPY --chown=${STACKABLE_USER_UID}:0 opa/stackable/bin /stackable/opa/bin
90+
91+
RUN <<EOF
8492
# We use version 1.7.0, since a newer version of cyclonedx-gomod is not compatible with the version of Golang (>= 1.23.1)
85-
RUN go install github.com/CycloneDX/cyclonedx-gomod/cmd/[email protected]
86-
RUN curl "https://repo.stackable.tech/repository/packages/opa/opa_${PRODUCT}.tar.gz" -o opa.tar.gz && \
87-
tar -zxvf opa.tar.gz && \
88-
mv "opa-${PRODUCT}" opa
93+
go install github.com/CycloneDX/cyclonedx-gomod/cmd/[email protected]
94+
curl "https://repo.stackable.tech/repository/packages/opa/opa_${PRODUCT}.tar.gz" -o opa.tar.gz
95+
tar -zxvf opa.tar.gz
96+
mv "opa-${PRODUCT}" opa
97+
EOF
8998

9099
WORKDIR /opa
91100

@@ -97,7 +106,12 @@ git config user.name "Fake commiter"
97106
git commit --allow-empty --message "Fake commit, so that we can create a tag"
98107
git tag "v${PRODUCT}"
99108
go build -o opa -buildmode=exe
100-
~/go/bin/cyclonedx-gomod app -json -output-version 1.5 -output "opa_${PRODUCT}.cdx.json" -packages -files
109+
# move artifact to /stackable/*/ to copy in final image
110+
~/go/bin/cyclonedx-gomod app -json -output-version 1.5 -output /stackable/opa/"opa_${PRODUCT}.cdx.json" -packages -files
111+
# move artifact to /stackable/* to copy in final image
112+
mv /opa/opa /stackable/opa/
113+
# set correct groups
114+
chmod -R g=u /stackable/opa
101115
EOF
102116

103117
FROM stackable/image/vector
@@ -114,32 +128,23 @@ LABEL name="Open Policy Agent" \
114128
summary="The Stackable image for Open Policy Agent (OPA)." \
115129
description="This image is deployed by the Stackable Operator for OPA."
116130

117-
COPY opa/licenses /licenses
131+
COPY --chown=${STACKABLE_USER_UID}:0 opa/licenses /licenses
118132

119-
COPY --from=opa-builder --chown=${STACKABLE_USER_UID}:0 /opa/opa /stackable/opa/opa
120-
COPY --from=opa-builder --chown=${STACKABLE_USER_UID}:0 /opa/opa_${PRODUCT}.cdx.json /stackable/opa/
133+
COPY --from=opa-builder --chown=${STACKABLE_USER_UID}:0 /stackable/opa /stackable/opa
121134
COPY --from=opa-bundle-builder --chown=${STACKABLE_USER_UID}:0 /opa-bundle-builder/target/release/stackable-opa-bundle-builder /stackable/opa-bundle-builder
122135
COPY --from=multilog-builder --chown=${STACKABLE_USER_UID}:0 /daemontools/admin/daemontools/command/multilog /stackable/multilog
123136

124-
COPY --chown=${STACKABLE_USER_UID}:0 opa/stackable/bin /stackable/opa/bin
125-
126137
RUN <<EOF
127138
microdnf update
128-
129139
# jq: Required for filtering logs
130140
microdnf install \
131141
jq
132142
microdnf clean all
133143
rm -rf /var/cache/yum
134-
135-
# All files and folders owned by root group to support running as arbitrary users.
136-
# This is best practice as all container users will belong to the root group (0).
137-
chown -R ${STACKABLE_USER_UID}:0 /stackable
138-
chmod -R g=u /stackable
139144
EOF
140145

141146
# ----------------------------------------
142-
# Attention: We are changing the group of all files in /stackable directly above
147+
# Attention:
143148
# If you do any file based actions (copying / creating etc.) below this comment you
144149
# absolutely need to make sure that the correct permissions are applied!
145150
# chown ${STACKABLE_USER_UID}:0

0 commit comments

Comments
 (0)