lets give it a shot
Build and Push Docker Images / build-and-push (push) Successful in 24s

This commit is contained in:
2025-10-22 22:42:07 +02:00
parent 4aeae654a8
commit 50ab2576b9
+29 -23
View File
@@ -40,23 +40,25 @@ fi
PACKAGE_MANAGER=${PACKAGE_MANAGER:-npm} PACKAGE_MANAGER=${PACKAGE_MANAGER:-npm}
add_teleport_labels() { add_teleport_labels() {
if [ -n "$TELEPORT_LABELS" ]; then # Default config path if not provided
echo "Adding Teleport labels from TELEPORT_LABELS environment variable..." CONFIG_FILE=${CONFIG_FILE:-/etc/teleport.yaml}
# Check if ssh_service section exists if [ -z "$TELEPORT_LABELS" ]; then
if ! grep -q "ssh_service:" "$CONFIG_FILE"; then echo "No TELEPORT_LABELS environment variable set, skipping label configuration"
echo "Error: ssh_service section not found in teleport.yaml" return 0
fi
if [ ! -f "$CONFIG_FILE" ]; then
echo "Error: Teleport config not found at $CONFIG_FILE"
return 1 return 1
fi fi
# Create a backup echo "Adding Teleport labels from TELEPORT_LABELS environment variable..."
cp "$CONFIG_FILE" "$CONFIG_FILE.backup"
# Build the new ssh_service section # Build the new ssh_service section (we'll either replace or append this)
NEW_SSH_SECTION="ssh_service:" NEW_SSH_SECTION="ssh_service:"
NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" labels:" NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" labels:"
# Parse TELEPORT_LABELS and add each label
IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS" IFS=',' read -ra LABELS <<< "$TELEPORT_LABELS"
for label in "${LABELS[@]}"; do for label in "${LABELS[@]}"; do
# Trim whitespace # Trim whitespace
@@ -80,13 +82,18 @@ add_teleport_labels() {
NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" enabled: \"yes\"" NEW_SSH_SECTION="$NEW_SSH_SECTION"$'\n'" enabled: \"yes\""
# Replace the ssh_service section # Create a backup
cp "$CONFIG_FILE" "$CONFIG_FILE.backup"
# If ssh_service exists, replace it. Otherwise, append to the end.
if grep -qE '^[[:space:]]*ssh_service:' "$CONFIG_FILE"; then
echo "Found existing ssh_service section, replacing it with new labels..."
awk -v new_section="$NEW_SSH_SECTION" ' awk -v new_section="$NEW_SSH_SECTION" '
BEGIN { BEGIN {
in_ssh_service = 0 in_ssh_service = 0
section_replaced = 0 section_replaced = 0
} }
/^ssh_service:/ { /^[[:space:]]*ssh_service:/ {
in_ssh_service = 1 in_ssh_service = 1
if (!section_replaced) { if (!section_replaced) {
print new_section print new_section
@@ -94,27 +101,26 @@ add_teleport_labels() {
} }
next next
} }
in_ssh_service && /^[a-zA-Z_][a-zA-Z0-9_]*:/ { in_ssh_service && /^[[:space:]]*[a-zA-Z_][a-zA-Z0-9_]*:/ {
in_ssh_service = 0 in_ssh_service = 0
} }
in_ssh_service { in_ssh_service {
next next
} }
{ { print $0 }
print $0 ' "$CONFIG_FILE" > "$CONFIG_FILE.tmp" && mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
} echo "Teleport labels updated successfully"
' "$CONFIG_FILE" > "$CONFIG_FILE.tmp"
# Replace the original file
mv "$CONFIG_FILE.tmp" "$CONFIG_FILE"
echo "Teleport labels added successfully"
else else
echo "No TELEPORT_LABELS environment variable set, skipping label configuration" echo "ssh_service section not found; appending to bottom of $CONFIG_FILE..."
# Ensure file ends with a newline before appending
tail -c1 "$CONFIG_FILE" | read -r _ || echo >> "$CONFIG_FILE"
printf "%s\n" "$NEW_SSH_SECTION" >> "$CONFIG_FILE"
echo "Teleport ssh_service section appended successfully"
fi fi
} }
# Optional Teleport setup # Optional Teleport setup
if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ] && [ -n "$TELEPORT_TOKEN" ]; then if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ] && [ -n "$TELEPORT_TOKEN" ]; then
echo "Teleport configuration detected. Setting up Teleport..." echo "Teleport configuration detected. Setting up Teleport..."
@@ -139,9 +145,9 @@ if [ -n "$TELEPORT_VERSION" ] && [ -n "$TELEPORT_URL" ] && [ -n "$TELEPORT_TOKEN
# Get the hostname of the machine # Get the hostname of the machine
HOSTNAME=$(hostname) HOSTNAME=$(hostname)
add_teleport_labels
# Update nodename in teleport config # Update nodename in teleport config
sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" /etc/teleport.yaml sed -i "s/^ nodename:.*/ nodename: $HOSTNAME/" /etc/teleport.yaml
add_teleport_labels
# Start Teleport in the background # Start Teleport in the background
echo "Starting Teleport service..." echo "Starting Teleport service..."