diff --git a/devspaces-udi/Dockerfile b/devspaces-udi/Dockerfile index 16aecfd2c0..047ae64a27 100644 --- a/devspaces-udi/Dockerfile +++ b/devspaces-udi/Dockerfile @@ -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 && \ @@ -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 @@ -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 @@ -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 diff --git a/devspaces-udi/container.yaml b/devspaces-udi/container.yaml index e48b2c1551..ccaec5030d 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..a4f8aecbd2 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.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 "$@" 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