dynamic node remote container
Build and Push Docker Images / build-and-push (push) Failing after 2m33s

This commit is contained in:
2024-10-21 18:50:53 +02:00
parent af7bfb2727
commit 8051126279
3 changed files with 81 additions and 31 deletions
+15 -5
View File
@@ -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"]
+53 -13
View File
@@ -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,8 +62,6 @@ 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
@@ -73,6 +70,7 @@ if [ ! -d "/workspace/.git" ]; then
" >> /root/.ssh/config
# Clone the repository if it doesn't exist
if [ ! -d "/workspace/.git" ]; then
git clone "$REPO_URL" /workspace
fi
@@ -84,15 +82,32 @@ fi
# Change to the repository directory
cd /workspace
# Install dependencies
# 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
# 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 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"
+1 -1
View File
@@ -1 +1 @@
2.1
3.0