From 7fa33aced75ccb34fdba6b0559d6eedb0f7cd854 Mon Sep 17 00:00:00 2001 From: Bram Kelchtermans Date: Mon, 19 Aug 2024 16:22:50 +0200 Subject: [PATCH] dynamic teleport injection for react dev container --- Dockers/remote-react-container/Dockerfile | 10 ----- Dockers/remote-react-container/entrypoint.sh | 42 ++++++++++++++------ 2 files changed, 30 insertions(+), 22 deletions(-) diff --git a/Dockers/remote-react-container/Dockerfile b/Dockers/remote-react-container/Dockerfile index 16580db..2217c8d 100644 --- a/Dockers/remote-react-container/Dockerfile +++ b/Dockers/remote-react-container/Dockerfile @@ -16,19 +16,9 @@ RUN rm -rf linux-presets RUN usermod -aG sudo root -# SHELL [ "fish", "--command" ] -# RUN chsh -s /usr/bin/fish -# ENV SHELL /usr/bin/fish -# ENV LANG=C.UTF-8 LANGUAGE=C.UTF-8 LC_ALL=C.UTF-8 - # Create a directory for the SSH keys RUN mkdir -p /root/.ssh -COPY install-node.sh /workspace/install-node.sh -RUN chmod +x /workspace/install-node.sh -RUN /workspace/install-node.sh -RUN rm /workspace/install-node.sh - # Copy the entrypoint script into the container COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh diff --git a/Dockers/remote-react-container/entrypoint.sh b/Dockers/remote-react-container/entrypoint.sh index c616fcc..96e73f6 100644 --- a/Dockers/remote-react-container/entrypoint.sh +++ b/Dockers/remote-react-container/entrypoint.sh @@ -7,22 +7,22 @@ if [ -z "$REPO_URL" ]; then exit 1 fi -# Check if the SSH key exists -if [ ! -f /root/.ssh/id_rsa ]; then - echo "Error: SSH private key not found at /root/.ssh/id_rsa" - exit 1 -fi - -if [ -z $GIT_USER ]; then +if [ -z "$GIT_USER" ]; then echo "Error: GIT_USER environment variable must be set." exit 1 fi -if [ -z $GIT_EMAIL ]; then +if [ -z "$GIT_EMAIL" ]; then echo "Error: GIT_EMAIL environment variable must be set." exit 1 fi +# Check if the SSH key exists +if [ ! -f /root/.ssh/id_rsa ]; then + echo "Error: SSH private key not found at /root/.ssh/id_rsa" + exit 1 +fi + # Ensure the SSH key has the correct permissions chmod 600 /root/.ssh/id_rsa @@ -46,6 +46,19 @@ if [ -f /root/.ssh/hostkey.pub ]; then cat /root/.ssh/hostkey.pub >>/root/.ssh/authorized_keys fi +# If no teleport edition is given, fallback to oss +if [ -z "$TELEPORT_EDITION" ]; then + TELEPORT_EDITION="oss" +fi + +# Install Teleport if the environment variables are set +if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ]; then + echo "Installing Teleport version $TELEPORT_VERSION, edition $TELEPORT_EDITION..." + curl https://${TELEPORT_URL}/install-v${TELEPORT_VERSION}.sh | bash -s ${TELEPORT_VERSION} ${TELEPORT_EDITION} +else + echo "Error: TELEPORT_VERSION and TELEPORT_EDITION environment variables must be set." +fi + # Change to the repository directory cd /workspace @@ -66,11 +79,16 @@ git config --global user.email $GIT_EMAIL # Get the hostname of the machine HOSTNAME=$(hostname) -# File path -CONFIG_FILE="/etc/teleport.yaml" +# # File path +# CONFIG_FILE="/etc/teleport.yaml" -# Edit the teleport.yaml file to update the nodename -sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE" +# # Edit the teleport.yaml file to update the nodename +# sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE" + +## If teleport token is set, join the server +if [ -n "$TELEPORT_TOKEN" ]; then + teleport configure --roles=node --token=$TELEPORT_TOKEN --proxy=$TELEPORT_URL -o file +fi nohup teleport start & # Start the application with pm2