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 # Install PM2 globally
RUN npm install -g pm2 RUN npm install -g pm2
# Install git, openssh-client, and openssh-server # Install git, openssh-client, openssh-server, and other necessary packages
RUN apt-get update && apt-get install -y git openssh-client software-properties-common sudo 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 󰎙 # Install additional package managers
RUN rm -rf linux-presets 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 RUN usermod -aG sudo root
# Create a directory for the SSH keys # 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 RUN chmod +x /usr/local/bin/entrypoint.sh
# Expose ports # Expose ports
EXPOSE 3000 EXPOSE 3000 22
# Set the entrypoint # Set the entrypoint
ENTRYPOINT ["/usr/local/bin/entrypoint.sh"] ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]
+65 -25
View File
@@ -36,15 +36,15 @@ if [ -z "$GIT_EMAIL" ]; then
exit 1 exit 1
fi fi
# Set default package manager if not provided
PACKAGE_MANAGER=${PACKAGE_MANAGER:-npm}
# If no teleport edition is given, fallback to oss # If no teleport edition is given, fallback to oss
if [ -z "$TELEPORT_EDITION" ]; then TELEPORT_EDITION=${TELEPORT_EDITION:-oss}
TELEPORT_EDITION="oss"
fi
# Install Teleport if the environment variables are set # Install Teleport if the environment variables are set
if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ]; then if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ]; then
echo "Installing Teleport version $TELEPORT_VERSION, edition $TELEPORT_EDITION..." 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}" 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 # 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" echo "Created teleport configuration file"
fi fi
else else
echo "Error: TELEPORT_VERSION and TELEPORT_URL environment variables must be set." echo "Warning: TELEPORT_VERSION and TELEPORT_URL environment variables are not set. Skipping Teleport installation."
exit 1
fi fi
# Ensure the SSH key has the correct permissions # 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 # Extract the domain from the REPO_URL
DOMAIN=$(extract_domain "$REPO_URL") DOMAIN=$(extract_domain "$REPO_URL")
# Check if the repository directory already exists # Add the SSH configuration for the domain
if [ ! -d "/workspace/.git" ]; then echo "Host $DOMAIN
# Add the SSH configuration for the domain HostName $DOMAIN
echo "Host $DOMAIN IdentityFile /root/.ssh/id_rsa
HostName $DOMAIN StrictHostKeyChecking no
IdentityFile /root/.ssh/id_rsa " >> /root/.ssh/config
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 git clone "$REPO_URL" /workspace
fi fi
# Add the public SSH key to authorized_keys # Add the public SSH key to authorized_keys
if [ -f /root/.ssh/hostkey.pub ]; then 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 fi
# Change to the repository directory # Change to the repository directory
cd /workspace cd /workspace
# Install dependencies # Install dependencies using the specified package manager
npm install 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 # Copy the environment file to the repository's environments directory
if [ -f /environment/.env ]; then if [ -f /environment/.env ]; then
mkdir -p /workspace/environments mkdir -p /workspace/environments
cp /environment/.env /workspace/.env cp /environment/.env /workspace/.env
else else
echo "Error: Environment file not found at /environment/.env" echo "Warning: Environment file not found at /environment/.env"
fi fi
# Set the git user and email # Set the git user and email
@@ -105,11 +120,36 @@ HOSTNAME=$(hostname)
# File path # File path
CONFIG_FILE="/etc/teleport.yaml" 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
sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE" if [ -f "$CONFIG_FILE" ]; then
sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" "$CONFIG_FILE"
# Start Teleport in the background # Start Teleport in the background
nohup teleport start & nohup teleport start &
else
echo "Warning: Teleport configuration file not found. Skipping Teleport start."
fi
# Start the application with pm2 # Start SSH server
exec pm2-runtime "npm run dev" 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