From e29eca0bc5f8c940af8633a0f7715201e0b385c5 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Tue, 1 Aug 2023 13:56:37 +0000 Subject: [PATCH 1/8] Add kubedock in UDI --- devspaces-udi/Dockerfile | 16 ++++++++++ devspaces-udi/container.yaml | 8 +++++ devspaces-udi/etc/entrypoint.sh | 48 ++++++++++++++++++++++++++++- devspaces-udi/etc/podman-wrapper.sh | 38 +++++++++++++++++++++++ 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 devspaces-udi/etc/podman-wrapper.sh diff --git a/devspaces-udi/Dockerfile b/devspaces-udi/Dockerfile index 5b813fa9b5..da63079cd4 100644 --- a/devspaces-udi/Dockerfile +++ b/devspaces-udi/Dockerfile @@ -33,6 +33,16 @@ RUN \ ./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 && \ + make build && \ + 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 && \ @@ -93,6 +103,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/podman.wrapper # 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 @@ -174,6 +185,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 @@ -310,6 +324,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 diff --git a/devspaces-udi/container.yaml b/devspaces-udi/container.yaml index 338a717653..051ed8efce 100644 --- a/devspaces-udi/container.yaml +++ b/devspaces-udi/container.yaml @@ -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 diff --git a/devspaces-udi/etc/entrypoint.sh b/devspaces-udi/etc/entrypoint.sh index 662657bfaa..85e12d0ef0 100755 --- a/devspaces-udi/etc/entrypoint.sh +++ b/devspaces-udi/etc/entrypoint.sh @@ -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 ############################################################################# @@ -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 +# 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..." + + mkdir -p /home/user/.local/bin/ + ln -f -s /usr/bin/podman.wrapper /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 "$@" diff --git a/devspaces-udi/etc/podman-wrapper.sh b/devspaces-udi/etc/podman-wrapper.sh new file mode 100644 index 0000000000..601fb53258 --- /dev/null +++ b/devspaces-udi/etc/podman-wrapper.sh @@ -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 From b9bd2e9fabf0afed8dcea567cb32730edd100db4 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Wed, 2 Aug 2023 14:57:21 +0200 Subject: [PATCH 2/8] Use bash double squared bracket in if condition Co-authored-by: Nick Boldt --- devspaces-udi/etc/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-udi/etc/entrypoint.sh b/devspaces-udi/etc/entrypoint.sh index 85e12d0ef0..255ac3485f 100755 --- a/devspaces-udi/etc/entrypoint.sh +++ b/devspaces-udi/etc/entrypoint.sh @@ -74,7 +74,7 @@ fi # If KUBEDOCK_ENABLED="true" then link podman to /usr/bin/podman.wrapper # else link podman to /usr/bin/podman.orig ############################################################################# -if [ "${KUBEDOCK_ENABLED:-false}" = "true" ]; then +if [[ "${KUBEDOCK_ENABLED:-false}" == "true" ]]; then echo echo "Kubedock is enabled (env variable KUBEDOCK_ENABLED is set to true)." From f7dbf3db40e746b76a6b51d5e1618b51ff23d738 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Wed, 2 Aug 2023 14:58:39 +0200 Subject: [PATCH 3/8] Update devspaces-udi/Dockerfile Co-authored-by: Nick Boldt --- devspaces-udi/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-udi/Dockerfile b/devspaces-udi/Dockerfile index da63079cd4..15bad75a0f 100644 --- a/devspaces-udi/Dockerfile +++ b/devspaces-udi/Dockerfile @@ -103,7 +103,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/podman.wrapper +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 From ce1032378d5b58c1b72f138130c1a6fa8e1284c2 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Wed, 2 Aug 2023 14:58:55 +0200 Subject: [PATCH 4/8] Update devspaces-udi/etc/entrypoint.sh Co-authored-by: Nick Boldt --- devspaces-udi/etc/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-udi/etc/entrypoint.sh b/devspaces-udi/etc/entrypoint.sh index 255ac3485f..427b2ac7f6 100755 --- a/devspaces-udi/etc/entrypoint.sh +++ b/devspaces-udi/etc/entrypoint.sh @@ -97,7 +97,7 @@ if [[ "${KUBEDOCK_ENABLED:-false}" == "true" ]]; then echo "Done." - echo "Replacing podman with podman-wrapper..." + echo "Replacing podman with podman-wrapper.sh..." mkdir -p /home/user/.local/bin/ ln -f -s /usr/bin/podman.wrapper /home/user/.local/bin/podman From ef8102e07960513d170e3d0fea0afc9e68682c17 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Wed, 2 Aug 2023 14:59:08 +0200 Subject: [PATCH 5/8] Update devspaces-udi/etc/entrypoint.sh Co-authored-by: Nick Boldt --- devspaces-udi/etc/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-udi/etc/entrypoint.sh b/devspaces-udi/etc/entrypoint.sh index 427b2ac7f6..53d700e21c 100755 --- a/devspaces-udi/etc/entrypoint.sh +++ b/devspaces-udi/etc/entrypoint.sh @@ -100,7 +100,7 @@ if [[ "${KUBEDOCK_ENABLED:-false}" == "true" ]]; then echo "Replacing podman with podman-wrapper.sh..." mkdir -p /home/user/.local/bin/ - ln -f -s /usr/bin/podman.wrapper /home/user/.local/bin/podman + ln -f -s /usr/bin/podman-wrapper.sh /home/user/.local/bin/podman export TESTCONTAINERS_RYUK_DISABLED="true" export TESTCONTAINERS_CHECKS_DISABLE="true" From ee7f50b243d22211ef051614164f4158eee97d04 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Wed, 2 Aug 2023 14:59:17 +0200 Subject: [PATCH 6/8] Update devspaces-udi/etc/entrypoint.sh Co-authored-by: Nick Boldt --- devspaces-udi/etc/entrypoint.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-udi/etc/entrypoint.sh b/devspaces-udi/etc/entrypoint.sh index 53d700e21c..a4f8aecbd2 100755 --- a/devspaces-udi/etc/entrypoint.sh +++ b/devspaces-udi/etc/entrypoint.sh @@ -71,7 +71,7 @@ if [[ ! -z "${PLUGIN_REMOTE_ENDPOINT_EXECUTABLE}" ]]; then fi ############################################################################# -# If KUBEDOCK_ENABLED="true" then link podman to /usr/bin/podman.wrapper +# 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 From 47e8758f9fd327ae126826a5d0970c26f1022524 Mon Sep 17 00:00:00 2001 From: Mario Loriedo Date: Fri, 4 Aug 2023 18:50:33 +0200 Subject: [PATCH 7/8] Fixes to kubedock build Signed-off-by: Mario Loriedo --- devspaces-udi/Dockerfile | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/devspaces-udi/Dockerfile b/devspaces-udi/Dockerfile index 15bad75a0f..2dc8890dc1 100644 --- a/devspaces-udi/Dockerfile +++ b/devspaces-udi/Dockerfile @@ -30,7 +30,7 @@ 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 @@ -38,7 +38,11 @@ RUN \ cd $REMOTE_SOURCES_DIR/kubedock/app && \ # build kubedock application with dependencies resolved by Cachito source $REMOTE_SOURCES_DIR/kubedock/cachito.env && \ - make build && \ + 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 @@ -51,7 +55,7 @@ RUN \ # ./kamel version && \ # END Kamel -# https://registry.access.redhat.com/ubi8-minimal +# https://registry.access.redhat.com/ubi8-minimal FROM ubi8-minimal:8.8-1014 USER root From 4ffe10a0695dad146739a9112d948aa890ccdafe Mon Sep 17 00:00:00 2001 From: Samantha Dawley Date: Fri, 4 Aug 2023 15:19:17 -0400 Subject: [PATCH 8/8] Add missing && \ Found another syntax error when testing in brew. --- devspaces-udi/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devspaces-udi/Dockerfile b/devspaces-udi/Dockerfile index 2dc8890dc1..c46d9893ce 100644 --- a/devspaces-udi/Dockerfile +++ b/devspaces-udi/Dockerfile @@ -191,7 +191,7 @@ RUN \ (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 + mv /usr/bin/podman /usr/bin/podman.orig && \ # set up go/bin folder mkdir /home/user/go/bin -p