Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add kubedock in UDI #499

Draft
wants to merge 9 commits into
base: devspaces-3.8-rhel-8
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 21 additions & 1 deletion devspaces-udi/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,23 @@ RUN \
# build gopls application with dependencies resolved by Cachito (which are also resolved for 'tools' dependency)
source $REMOTE_SOURCES_DIR/gopls/cachito.env && \
GO111MODULE=on go build -o gopls && \
./gopls version
./gopls version && \
# END Gopls

# BEGIN Kubedock
mkdir /home/user/go/bin -p && \
cd $REMOTE_SOURCES_DIR/kubedock/app && \
# build kubedock application with dependencies resolved by Cachito
source $REMOTE_SOURCES_DIR/kubedock/cachito.env && \
LDFLAGS="-X github.com/joyrex2001/kubedock/internal/config.Date=`date -u +%Y%m%d-%H%M%S` \
-X github.com/joyrex2001/kubedock/internal/config.Build=9d21955b52e4905d916d24e724dcad195aef3515 \
-X github.com/joyrex2001/kubedock/internal/config.Version=0.11.0 \
-X github.com/joyrex2001/kubedock/internal/config.Image=joyrex2001/kubedock:0.11.0" && \
CGO_ENABLED=0 go build -ldflags "${LDFLAGS}" -o kubedock && \
chmod +x ./kubedock && \
./kubedock version
# END Kubedock

# CRW-3193 disable until we have a camel-k sample again
# BEGIN Kamel
# cd $REMOTE_SOURCES_DIR/camelk/app && \
Expand Down Expand Up @@ -93,6 +107,7 @@ ADD etc/storage.conf $HOME/.config/containers/storage.conf
ADD etc/entrypoint.sh /entrypoint.sh
COPY $REMOTE_SOURCES $REMOTE_SOURCES_DIR
COPY etc/docker.sh /usr/local/bin/docker
COPY etc/podman-wrapper.sh /usr/bin/

# NOTE: uncomment for local build. Must also set full registry path in FROM to registry.redhat.io or registry.access.redhat.com
# enable rhel 8 content sets (from Brew) to resolve buildah
Expand Down Expand Up @@ -174,6 +189,9 @@ RUN \
# TODO switch this to fuse in OCP 4.12?
mkdir -p "${HOME}"/.config/containers && \
(echo '[storage]';echo 'driver = "vfs"') > "${HOME}"/.config/containers/storage.conf && \
## Rootless podman install #6: rename podman to allow the execution of 'podman run' using
## kubedock but 'podman build' using podman.orig
mv /usr/bin/podman /usr/bin/podman.orig && \
# set up go/bin folder
mkdir /home/user/go/bin -p

Expand Down Expand Up @@ -310,6 +328,8 @@ xdebug.log=\${HOME}/xdebug.log" >> /etc/php.ini && \

# see container.yaml
COPY --from=go-builder $REMOTE_SOURCES_DIR/gopls/app/gopls/gopls $HOME/go/bin/gopls
COPY --from=go-builder $REMOTE_SOURCES_DIR/kubedock/app/kubedock $HOME/go/bin/kubedock


########################################################################
# Cleanup and Summaries
Expand Down
8 changes: 8 additions & 0 deletions devspaces-udi/container.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,11 @@ remote_sources:
# pkg_managers:
# - gomod
# packages: {"gomod": [ "path": "." ]}

# https://github.com/joyrex2001/kubedock/releases/tag/0.11.0 => https://github.com/joyrex2001/kubedock/commit/9d21955b52e4905d916d24e724dcad195aef3515
- name: kubedock
remote_source:
repo: https://github.com/joyrex2001/kubedock
ref: 9d21955b52e4905d916d24e724dcad195aef3515
pkg_managers:
- gomod
48 changes: 47 additions & 1 deletion devspaces-udi/etc/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ fi
# Setup $PS1 for a consistent and reasonable prompt
#############################################################################
if [ -w "${HOME}" ] && [ ! -f "${HOME}"/.bashrc ]; then
echo "PS1='[\u@\h \W]\$ '" > "${HOME}"/.bashrc
echo "PS1='[\u@\h \W]\$ '" >> "${HOME}"/.bashrc
fi

#############################################################################
Expand All @@ -70,4 +70,50 @@ if [[ ! -z "${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}" ]]; then
${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}
fi

#############################################################################
# If KUBEDOCK_ENABLED="true" then link podman to /usr/bin/podman-wrapper.sh
# else link podman to /usr/bin/podman.orig
#############################################################################
if [[ "${KUBEDOCK_ENABLED:-false}" == "true" ]]; then
echo
echo "Kubedock is enabled (env variable KUBEDOCK_ENABLED is set to true)."

SECONDS=0
until [ -f /home/user/.kube/config ]; do
if (( SECONDS > 10 )); then
echo "Giving up..."
exit 1
fi
echo "Kubeconfig doesn't exist yet. Waiting..."
sleep 1
done
echo "Kubeconfig found."

KUBEDOCK_PARAMS=${KUBEDOCK_PARAMS:-"--reverse-proxy"}

echo "Starting kubedock with params \"${KUBEDOCK_PARAMS}\"..."

kubedock server "${KUBEDOCK_PARAMS}" > /tmp/kubedock.log 2>&1 &

echo "Done."

echo "Replacing podman with podman-wrapper.sh..."

mkdir -p /home/user/.local/bin/
ln -f -s /usr/bin/podman-wrapper.sh /home/user/.local/bin/podman

export TESTCONTAINERS_RYUK_DISABLED="true"
export TESTCONTAINERS_CHECKS_DISABLE="true"

echo "Done."
echo
else
echo
echo "Kubedock is disabled. It can be enabled with the env variable \"KUBEDOCK_ENABLED=true\""
echo "set in the workspace Devfile or in a Kubernetes ConfigMap in the developer namespace."
echo
mkdir -p /home/user/.local/bin/
ln -f -s /usr/bin/podman.orig /home/user/.local/bin/podman
fi

exec "$@"
38 changes: 38 additions & 0 deletions devspaces-udi/etc/podman-wrapper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash
set -euo pipefail

ORIGINAL_PODMAN_PATH=${ORIGINAL_PODMAN_PATH:-"/usr/bin/podman.orig"}
KUBEDOCK_SUPPORTED_COMMANDS=${KUBEDOCK_SUPPORTED_COMMANDS:-"run ps exec cp logs inspect kill rm wait stop start"}

PODMAN_ARGS=( "$@" )

TRUE=0
FALSE=1

exec_original_podman() {
exec ${ORIGINAL_PODMAN_PATH} "${PODMAN_ARGS[@]}"
}

exec_kubedock_podman() {
exec env CONTAINER_HOST=tcp://127.0.0.1:2475 "${ORIGINAL_PODMAN_PATH}" "${PODMAN_ARGS[@]}"
}

podman_command() {
echo "${PODMAN_ARGS[0]}"
}

command_is_supported_by_kubedock() {
CMD=$(podman_command)
for SUPPORTED_CMD in $KUBEDOCK_SUPPORTED_COMMANDS; do
if [ "$SUPPORTED_CMD" = "$CMD" ]; then
return $TRUE
fi
done
return ${FALSE}
}

if command_is_supported_by_kubedock; then
exec_kubedock_podman
else
exec_original_podman
fi