diff --git a/Dockers/remote-node-container/Dockerfile b/Dockers/remote-node-container/Dockerfile index 159c1e5..9ad4019 100644 --- a/Dockers/remote-node-container/Dockerfile +++ b/Dockers/remote-node-container/Dockerfile @@ -7,12 +7,22 @@ WORKDIR /workspace # Install PM2 globally RUN npm install -g pm2 -# Install git, openssh-client, and openssh-server -RUN apt-get update && apt-get install -y git openssh-client software-properties-common sudo +# 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 git clone https://gitea.bramkelchtermans.be/Bram/linux-presets.git && cd linux-presets && chmod +x setup.sh && ./setup.sh --terminal-icon 󰎙 -RUN rm -rf linux-presets +# Install additional package managers +RUN npm install -g yarn pnpm +RUN curl -fsSL https://bun.sh/install | bash +# Clone and setup linux-presets +RUN git clone https://gitea.bramkelchtermans.be/Bram/linux-presets.git && \ + cd linux-presets && \ + chmod +x setup.sh && \ + ./setup.sh --terminal-icon 󰎙 && \ + cd .. && \ + rm -rf linux-presets + +# Add root to sudo group RUN usermod -aG sudo root # Create a directory for the SSH keys @@ -23,7 +33,7 @@ COPY entrypoint.sh /usr/local/bin/entrypoint.sh RUN chmod +x /usr/local/bin/entrypoint.sh # Expose ports -EXPOSE 3000 +EXPOSE 3000 22 # Set the entrypoint ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] diff --git a/Dockers/remote-node-container/entrypoint.sh b/Dockers/remote-node-container/entrypoint.sh index 855437b..90a36c1 100644 --- a/Dockers/remote-node-container/entrypoint.sh +++ b/Dockers/remote-node-container/entrypoint.sh @@ -36,15 +36,15 @@ if [ -z "$GIT_EMAIL" ]; then exit 1 fi +# Set default package manager if not provided +PACKAGE_MANAGER=${PACKAGE_MANAGER:-npm} + # If no teleport edition is given, fallback to oss -if [ -z "$TELEPORT_EDITION" ]; then - TELEPORT_EDITION="oss" -fi +TELEPORT_EDITION=${TELEPORT_EDITION:-oss} # 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..." - echo "Executing: curl https://goteleport.com/static/install.sh | bash -s $TELEPORT_VERSION $TELEPORT_EDITION" curl https://goteleport.com/static/install.sh | bash -s "${TELEPORT_VERSION}" "${TELEPORT_EDITION}" # If teleport token is set and there is no teleport.yaml file, create one @@ -53,8 +53,7 @@ if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ]; then echo "Created teleport configuration file" fi else - echo "Error: TELEPORT_VERSION and TELEPORT_URL environment variables must be set." - exit 1 + echo "Warning: TELEPORT_VERSION and TELEPORT_URL environment variables are not set. Skipping Teleport installation." fi # Ensure the SSH key has the correct permissions @@ -63,36 +62,52 @@ chmod 600 /root/.ssh/id_rsa # Extract the domain from the REPO_URL DOMAIN=$(extract_domain "$REPO_URL") -# Check if the repository directory already exists -if [ ! -d "/workspace/.git" ]; then - # Add the SSH configuration for the domain - echo "Host $DOMAIN - HostName $DOMAIN - IdentityFile /root/.ssh/id_rsa - StrictHostKeyChecking no - " >>/root/.ssh/config +# Add the SSH configuration for the domain +echo "Host $DOMAIN + HostName $DOMAIN + IdentityFile /root/.ssh/id_rsa + StrictHostKeyChecking no +" >> /root/.ssh/config - # Clone the repository if it doesn't exist +# Clone the repository if it doesn't exist +if [ ! -d "/workspace/.git" ]; then git clone "$REPO_URL" /workspace fi # Add the public SSH key to authorized_keys if [ -f /root/.ssh/hostkey.pub ]; then - cat /root/.ssh/hostkey.pub >>/root/.ssh/authorized_keys + cat /root/.ssh/hostkey.pub >> /root/.ssh/authorized_keys fi # Change to the repository directory cd /workspace -# Install dependencies -npm install +# Install dependencies using the specified package manager +case $PACKAGE_MANAGER in + npm) + npm install + ;; + yarn) + yarn install + ;; + pnpm) + pnpm install + ;; + bun) + bun install + ;; + *) + echo "Error: Unsupported package manager: $PACKAGE_MANAGER" + exit 1 + ;; +esac # Copy the environment file to the repository's environments directory if [ -f /environment/.env ]; then mkdir -p /workspace/environments cp /environment/.env /workspace/.env else - echo "Error: Environment file not found at /environment/.env" + echo "Warning: Environment file not found at /environment/.env" fi # Set the git user and email @@ -105,11 +120,36 @@ HOSTNAME=$(hostname) # 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 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 & + # Start Teleport in the background + nohup teleport start & +else + echo "Warning: Teleport configuration file not found. Skipping Teleport start." +fi -# Start the application with pm2 -exec pm2-runtime "npm run dev" +# Start SSH server +service ssh start + +# Determine the run command +if [ -z "$RUN_COMMAND" ]; then + # If RUN_COMMAND is not set, try to find a suitable command from package.json + if [ -f "package.json" ]; then + if grep -q '"dev"' package.json; then + RUN_COMMAND="dev" + elif grep -q '"start"' package.json; then + RUN_COMMAND="start" + else + echo "Error: Could not determine a suitable run command from package.json" + exit 1 + fi + else + echo "Error: package.json not found and RUN_COMMAND not set" + exit 1 + fi +fi + +# Start the application with pm2 using the specified package manager and run command +exec pm2-runtime "$PACKAGE_MANAGER run $RUN_COMMAND" diff --git a/Dockers/remote-node-container/version b/Dockers/remote-node-container/version index 42f7d23..f398a20 100644 --- a/Dockers/remote-node-container/version +++ b/Dockers/remote-node-container/version @@ -1 +1 @@ -2.1 \ No newline at end of file +3.0 \ No newline at end of file