Skip to content

Commit b42e4e3

Browse files
committed
build: add missing scripts
nonroot is not a user in these images, set up the user Signed-off-by: bpratt <[email protected]>
1 parent af53f45 commit b42e4e3

File tree

4 files changed

+41
-17
lines changed

4 files changed

+41
-17
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
*.dll
66
*.so
77
*.dylib
8-
bin
98

109
.envrc
1110

build/Dockerfile

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
FROM quay.io/redhat-services-prod/openshift/boilerplate:image-v6.0.1 AS builder
22

33
WORKDIR /workspace
4-
# Copy the Go Modules manifests
54
COPY go.mod go.mod
65
COPY go.sum go.sum
7-
# cache deps before building and copying source so that we don't need to re-download as much
8-
# and so that source changes don't invalidate our downloaded layer
96
RUN go mod download
107

11-
# Copy the go source
12-
COPY *.go .
13-
COPY controllers/ controllers/
14-
COPY api/ api/
8+
COPY . .
9+
RUN make go-build
1510

16-
# Build
17-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=amd64 GO111MODULE=on go build -mod=mod -a -o manager main.go
18-
19-
# Use distroless as minimal base image to package the manager binary
20-
# Refer to https://github.com/GoogleContainerTools/distroless for more details
2111
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.10-1130
22-
WORKDIR /
23-
COPY --from=builder /workspace/manager .
24-
USER nonroot:nonroot
12+
ENV OPERATOR=/usr/local/bin/must-gather-operator \
13+
USER_UID=1001 \
14+
USER_NAME=osd-example-operator
15+
16+
COPY --from=builder /workspace/build/_output/bin/* /usr/local/bin/
17+
18+
COPY build/bin /usr/local/bin
19+
RUN /usr/local/bin/user_setup
20+
21+
ENTRYPOINT ["/usr/local/bin/entrypoint"]
22+
23+
USER ${USER_UID}
2524

26-
ENTRYPOINT ["/manager"]
25+
LABEL io.openshift.managed.name="osd-example-operator" \
26+
io.openshift.managed.description="OSD Example Operator"

build/bin/entrypoint

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/sh -e
2+
3+
# This is documented here:
4+
# https://docs.openshift.com/container-platform/4.10/openshift_images/create-images.html#images-create-guide-openshift_create-images
5+
6+
if ! whoami &>/dev/null; then
7+
if [ -w /etc/passwd ]; then
8+
echo "${USER_NAME:-osd-example-operator}:x:$(id -u):$(id -g):${USER_NAME:-osd-example-operator} user:${HOME}:/sbin/nologin" >> /etc/passwd
9+
fi
10+
fi
11+
12+
exec ${OPERATOR} $@

build/bin/user_setup

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/sh
2+
set -x
3+
4+
# ensure $HOME exists and is accessible by group 0 (we don't know what the runtime UID will be)
5+
mkdir -p ${HOME}
6+
chown ${USER_UID}:0 ${HOME}
7+
chmod ug+rwx ${HOME}
8+
9+
# runtime user will need to be able to self-insert in /etc/passwd
10+
chmod g+rw /etc/passwd
11+
12+
# no need for this script to remain in the image after running
13+
rm $0

0 commit comments

Comments
 (0)