From 9881e7eb7d8bf2d41ba1db3bba6b4e4797d0a654 Mon Sep 17 00:00:00 2001 From: Bram Kelchtermans Date: Wed, 11 Dec 2024 11:32:24 +0100 Subject: [PATCH] teleport optional --- Dockers/remote-node-container/Dockerfile | 10 +++- Dockers/remote-node-container/entrypoint.sh | 51 ++++++++++----------- Dockers/remote-node-container/version | 2 +- 3 files changed, 34 insertions(+), 29 deletions(-) diff --git a/Dockers/remote-node-container/Dockerfile b/Dockers/remote-node-container/Dockerfile index e44c686..452980b 100644 --- a/Dockers/remote-node-container/Dockerfile +++ b/Dockers/remote-node-container/Dockerfile @@ -8,7 +8,15 @@ WORKDIR /workspace RUN npm install -g pm2 # Install git, openssh-client, openssh-server, and other necessary packages -RUN apt-get update && apt-get install -y git openssh-client openssh-server software-properties-common sudo +RUN apt-get update && apt-get install -y \ + git \ + openssh-client \ + openssh-server \ + software-properties-common \ + sudo \ + curl \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* # Install additional package managers RUN npm install -g pnpm diff --git a/Dockers/remote-node-container/entrypoint.sh b/Dockers/remote-node-container/entrypoint.sh index 90a36c1..56edfcd 100644 --- a/Dockers/remote-node-container/entrypoint.sh +++ b/Dockers/remote-node-container/entrypoint.sh @@ -39,21 +39,34 @@ fi # Set default package manager if not provided PACKAGE_MANAGER=${PACKAGE_MANAGER:-npm} -# If no teleport edition is given, fallback to oss -TELEPORT_EDITION=${TELEPORT_EDITION:-oss} +# Optional Teleport setup +if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ] && [ -n "$TELEPORT_TOKEN" ]; then + echo "Teleport configuration detected. Setting up Teleport..." -# 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://goteleport.com/static/install.sh | bash -s "${TELEPORT_VERSION}" "${TELEPORT_EDITION}" + # Set default edition if not provided + TELEPORT_EDITION=${TELEPORT_EDITION:-oss} - # If teleport token is set and there is no teleport.yaml file, create one - if [ -n "$TELEPORT_TOKEN" ] && [ ! -f /etc/teleport.yaml ]; then - teleport configure --roles=node --token="$TELEPORT_TOKEN" --proxy="$TELEPORT_URL" --no-acme -o file - echo "Created teleport configuration file" + # Only install Teleport if it's not already installed + if ! command -v teleport &> /dev/null; then + echo "Installing Teleport version $TELEPORT_VERSION, edition $TELEPORT_EDITION..." + curl https://goteleport.com/static/install.sh | bash -s "${TELEPORT_VERSION}" "${TELEPORT_EDITION}" fi + + # Create teleport configuration + teleport configure --roles=node --token="$TELEPORT_TOKEN" --proxy="$TELEPORT_URL" --no-acme -o file + echo "Created teleport configuration file" + + # Get the hostname of the machine + HOSTNAME=$(hostname) + + # Update nodename in teleport config + sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" /etc/teleport.yaml + + # Start Teleport in the background + echo "Starting Teleport service..." + nohup teleport start & else - echo "Warning: TELEPORT_VERSION and TELEPORT_URL environment variables are not set. Skipping Teleport installation." + echo "Skipping Teleport setup - credentials not provided" fi # Ensure the SSH key has the correct permissions @@ -114,22 +127,6 @@ fi git config --global user.name "$GIT_USER" git config --global user.email "$GIT_EMAIL" -# Get the hostname of the machine -HOSTNAME=$(hostname) - -# File path -CONFIG_FILE="/etc/teleport.yaml" - -# Edit the teleport.yaml file to update the nodename if the file exists -if [ -f "$CONFIG_FILE" ]; then - sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE" - - # Start Teleport in the background - nohup teleport start & -else - echo "Warning: Teleport configuration file not found. Skipping Teleport start." -fi - # Start SSH server service ssh start diff --git a/Dockers/remote-node-container/version b/Dockers/remote-node-container/version index f398a20..06a4457 100644 --- a/Dockers/remote-node-container/version +++ b/Dockers/remote-node-container/version @@ -1 +1 @@ -3.0 \ No newline at end of file +3.1 \ No newline at end of file