Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e69fce6

Browse files
committed
Adding kubedock and podman wrapper entrypoint logic
1 parent 5d223b9 commit e69fce6

File tree

5 files changed

+133
-51
lines changed

5 files changed

+133
-51
lines changed

Containerfile

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,23 @@ ARG USER_HOME_DIR="/home/user"
55
ARG WORK_DIR="/projects"
66
ARG INSTALL_PACKAGES="procps-ng openssl git tar gzip zip xz unzip which shadow-utils bash zsh vi wget jq podman buildah skopeo podman-docker glibc-devel zlib-devel gcc libffi-devel libstdc++-devel gcc-c++ glibc-langpack-en ca-certificates python3-pip python3-devel fuse-overlayfs util-linux vim-minimal vim-enhanced"
77

8-
ENV HOME=${USER_HOME_DIR}
9-
ENV BUILDAH_ISOLATION=chroot
8+
ENV HOME=${USER_HOME_DIR} \
9+
KUBECONFIG=/home/user/.kube/config \
10+
BUILDAH_ISOLATION=chroot
1011

11-
COPY --chown=0:0 entrypoint.sh /
12-
COPY --chown=0:0 podman-wrapper.sh /usr/bin/
12+
COPY --chown=0:0 tools/entrypoint.sh /
13+
COPY --chown=0:0 tools/podman-wrapper.sh /usr/bin/
14+
COPY --chown=0:0 tools/kubedock /usr/bin
1315

14-
RUN microdnf --disableplugin=subscription-manager install -y ${INSTALL_PACKAGES}; \
16+
RUN microdnf install -y ${INSTALL_PACKAGES}; \
1517
microdnf update -y ; \
1618
microdnf clean all ; \
1719
mkdir -p /usr/local/bin ; \
1820
mkdir -p ${WORK_DIR} ; \
1921
pip3 install -U podman-compose ; \
2022
pip3 install -U cekit ; \
2123
mkdir -p /home/user/.local/share ; \
24+
mkdir -p /home/user/.local/bin ; \
2225
chgrp -R 0 /home ; \
2326
chmod -R g=u /home ${WORK_DIR} ; \
2427
chmod +x /entrypoint.sh ; \
@@ -40,6 +43,13 @@ RUN microdnf --disableplugin=subscription-manager install -y ${INSTALL_PACKAGES}
4043
ENV DOTNET_RPM_VERSION=9.0
4144
RUN dnf install -y dotnet-hostfxr-${DOTNET_RPM_VERSION} dotnet-runtime-${DOTNET_RPM_VERSION} dotnet-sdk-${DOTNET_RPM_VERSION}
4245

46+
# Install oc cli
47+
ENV OC_VERSION=openshift-client-linux-4.17.22
48+
49+
RUN wget https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable-4.17/${OC_VERSION}.tar.gz && \
50+
gzip -dvf ${OC_VERSION}.tar.gz && tar -xvf ${OC_VERSION}.tar && \
51+
chmod 755 oc && mv oc /usr/bin/ && /bin/rm -rf ${OC_VERSION}.tar kubectl README.md
52+
4353
# Install Python
4454
# https://catalog.redhat.com/software/containers/devspaces/udi-rhel9/673f8460bbf0c33aca0fe316?container-tabs=dockerfile
4555
ENV PYTHON_VERSION="3.13"
@@ -91,5 +101,5 @@ RUN dnf -y -q install --setopt=tsflags=nodocs \
91101
USER 1001
92102

93103
WORKDIR ${WORK_DIR}
94-
ENTRYPOINT ["/usr/libexec/podman/catatonit","--","/entrypoint.sh"]
104+
ENTRYPOINT [ "/entrypoint.sh" ]
95105
CMD [ "tail", "-f", "/dev/null" ]

entrypoint.sh

Lines changed: 0 additions & 45 deletions
This file was deleted.

tools/entrypoint.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/bin/sh
2+
#
3+
# Copyright (c) 2019-2024 Red Hat, Inc.
4+
# This program and the accompanying materials are made
5+
# available under the terms of the Eclipse Public License 2.0
6+
# which is available at https://www.eclipse.org/legal/epl-2.0/
7+
#
8+
# SPDX-License-Identifier: EPL-2.0
9+
#
10+
# Contributors:
11+
# Red Hat, Inc. - initial API and implementation
12+
#
13+
14+
# Create Home directory
15+
if [ ! -d "${HOME}" ]
16+
then
17+
mkdir -p "${HOME}"
18+
fi
19+
20+
#############################################################################
21+
# Grant access to projects volume in case of non root user with sudo rights
22+
#############################################################################
23+
if [ "$(id -u)" -ne 0 ] && command -v sudo >/dev/null 2>&1 && sudo -n true > /dev/null 2>&1; then
24+
sudo chown "${USER_ID}:${GROUP_ID}" /projects
25+
fi
26+
27+
if [ -f "${HOME}"/.venv/bin/activate ]; then
28+
source "${HOME}"/.venv/bin/activate
29+
fi
30+
31+
#############################################################################
32+
# If KUBEDOCK_ENABLED="true" then link podman to /usr/bin/podman-wrapper.sh
33+
# else link podman to /usr/bin/podman.orig
34+
#############################################################################
35+
if [[ "${KUBEDOCK_ENABLED:-false}" == "true" ]]; then
36+
echo
37+
echo "Kubedock is enabled (env variable KUBEDOCK_ENABLED is set to true)."
38+
39+
SECONDS=0
40+
KUBEDOCK_TIMEOUT=${KUBEDOCK_TIMEOUT:-10}
41+
until [ -f $KUBECONFIG ]; do
42+
if (( SECONDS > KUBEDOCK_TIMEOUT )); then
43+
break
44+
fi
45+
echo "Kubeconfig doesn't exist yet. Waiting..."
46+
sleep 1
47+
done
48+
49+
if [ -f $KUBECONFIG ]; then
50+
echo "Kubeconfig found."
51+
52+
KUBEDOCK_PARAMS=${KUBEDOCK_PARAMS:-"--reverse-proxy --kubeconfig $KUBECONFIG"}
53+
54+
echo "Starting kubedock with params \"${KUBEDOCK_PARAMS}\"..."
55+
56+
kubedock server ${KUBEDOCK_PARAMS} > /tmp/kubedock.log 2>&1 &
57+
58+
echo "Done."
59+
60+
echo "Replacing podman with podman-wrapper.sh..."
61+
62+
ln -f -s /usr/bin/podman-wrapper.sh /home/user/.local/bin/podman
63+
64+
export TESTCONTAINERS_RYUK_DISABLED="true"
65+
export TESTCONTAINERS_CHECKS_DISABLE="true"
66+
67+
echo "Done."
68+
echo
69+
else
70+
echo "Could not find Kubeconfig at $KUBECONFIG"
71+
echo "Giving up..."
72+
fi
73+
else
74+
echo
75+
echo "Kubedock is disabled. It can be enabled with the env variable \"KUBEDOCK_ENABLED=true\""
76+
echo "set in the workspace Devfile or in a Kubernetes ConfigMap in the developer namespace."
77+
echo
78+
ln -f -s /usr/bin/podman.orig /home/user/.local/bin/podman
79+
fi
80+
81+
# Configure Podman builds to use vfs or fuse-overlayfs
82+
if [ ! -d "${HOME}/.config/containers" ]; then
83+
mkdir -p ${HOME}/.config/containers
84+
if [ -c "/dev/fuse" ] && [ -f "/usr/bin/fuse-overlayfs" ]; then
85+
(echo '[storage]';echo 'driver = "overlay"';echo '[storage.options.overlay]';echo 'mount_program = "/usr/bin/fuse-overlayfs"') > ${HOME}/.config/containers/storage.conf
86+
else
87+
(echo '[storage]';echo 'driver = "vfs"') > "${HOME}"/.config/containers/storage.conf
88+
fi
89+
fi
90+
91+
# Create User ID
92+
if ! whoami &> /dev/null
93+
then
94+
if [ -w /etc/passwd ]
95+
then
96+
echo "${USER_NAME:-user}:x:$(id -u):0:${USER_NAME:-user} user:${HOME}:/bin/bash" >> /etc/passwd
97+
echo "${USER_NAME:-user}:x:$(id -u):" >> /etc/group
98+
fi
99+
fi
100+
101+
# Create subuid/gid entries for the user
102+
USER=$(whoami)
103+
START_ID=$(( $(id -u)+1 ))
104+
echo "${USER}:${START_ID}:2147483646" > /etc/subuid
105+
echo "${USER}:${START_ID}:2147483646" > /etc/subgid
106+
107+
# Configure Z shell
108+
if [ ! -f ${HOME}/.zshrc ]
109+
then
110+
(echo "HISTFILE=${HOME}/.zsh_history"; echo "HISTSIZE=1000"; echo "SAVEHIST=1000") > ${HOME}/.zshrc
111+
(echo "if [ -f ${PROJECT_SOURCE}/workspace.rc ]"; echo "then"; echo " . ${PROJECT_SOURCE}/workspace.rc"; echo "fi") >> ${HOME}/.zshrc
112+
fi
113+
114+
# Login to the local image registry
115+
podman login -u $(oc whoami) -p $(oc whoami -t) image-registry.openshift-image-registry.svc:5000
116+
117+
exec "$@"

tools/kubedock

61.9 MB
Binary file not shown.
File renamed without changes.

0 commit comments

Comments
 (0)