-
Notifications
You must be signed in to change notification settings - Fork 71
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
63 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
ARG TARGETARCH=${TARGETARCH} | ||
|
||
FROM calico/bpftool:v5.3-${TARGETARCH} as bpftool | ||
|
||
FROM registry.access.redhat.com/ubi8/ubi:latest | ||
|
@@ -115,6 +116,12 @@ ENV GOPATH /go | |
ENV PATH $GOPATH/bin:$PATH | ||
RUN mkdir -p "$GOPATH/src" "$GOPATH/bin" && chmod -R 1777 "$GOPATH" | ||
|
||
# su-exec is used by the entrypoint script to execute the user's command with the right UID/GID. | ||
RUN set -eux; \ | ||
curl -sfL https://raw.githubusercontent.com/ncopa/su-exec/master/su-exec.c -o /tmp/su-exec.c; \ | ||
gcc -Wall -O2 /tmp/su-exec.c -o /usr/bin/su-exec; \ | ||
rm -f /tmp/su-exec.c | ||
|
||
# Install Go utilities | ||
|
||
# coltroller-gen is used for generating CRD files. | ||
|
@@ -173,7 +180,6 @@ RUN go install github.com/onsi/ginkgo/v2/[email protected] && mv /go/bin/ginkgo /go | |
|
||
# Ensure that everything under the GOPATH is writable by everyone | ||
RUN chmod -R 777 $GOPATH | ||
ENV HOME $GOPATH | ||
|
||
# Disable ssh host key checking | ||
RUN echo $'Host *\n StrictHostKeyChecking no' >> /etc/ssh/ssh_config.d/10-stricthostkey.conf | ||
|
@@ -190,4 +196,5 @@ RUN set -eux; \ | |
rm -fr /build; \ | ||
fi | ||
|
||
WORKDIR $GOPATH | ||
COPY entrypoint.sh /usr/local/bin/entrypoint.sh | ||
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/bash | ||
|
||
# Add local user | ||
# Either use the LOCAL_USER_ID if passed in at runtime or fallback | ||
|
||
USER_ID=${LOCAL_USER_ID:-9001} | ||
|
||
if [ "${RUN_AS_ROOT}" = "true" ]; then | ||
exec "$@" | ||
fi | ||
|
||
echo "Starting with UID : $USER_ID" 1>&2 | ||
# Do not create mail box. | ||
/bin/sed -i 's/^CREATE_MAIL_SPOOL=yes/CREATE_MAIL_SPOOL=no/' /etc/default/useradd | ||
# Don't pass "-m" to useradd if the home directory already exists (which can occur if it was volume mounted in) otherwise it will fail. | ||
if [[ ! -d "/home/user" ]]; then | ||
/usr/sbin/useradd -m -U -s /bin/bash -u "$USER_ID" user | ||
else | ||
/usr/sbin/useradd -U -s /bin/bash -u "$USER_ID" user | ||
fi | ||
|
||
export HOME=/home/user | ||
|
||
if [ -n "$EXTRA_GROUP_ID" ]; then | ||
echo "Adding user to additional GID : $EXTRA_GROUP_ID" 1>&2 | ||
# Adding the group can fail if it already exists. | ||
if addgroup --gid "$EXTRA_GROUP_ID" group; then | ||
adduser user group | ||
else | ||
echo "Adding user to existing group instead" 1>&2 | ||
adduser user "$(getent group "$EXTRA_GROUP_ID" | cut -d: -f1)" | ||
fi | ||
fi | ||
|
||
exec /usr/bin/su-exec user "$@" |