Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
63 changes: 12 additions & 51 deletions scripts/container-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ declare helper_scripts=(
abort_config=false
litestream_enabled=true
https_enabled=true
caddy_config_file=""

# Caddyfile block placeholders
ACME_EAB_BLOCK=""
Expand Down Expand Up @@ -195,42 +196,6 @@ check_headscale_environment_vars() {
check_env_var_or_set_default "EPHEMERAL_NODE_INACTIVITY_TIMEOUT" "${headscale_ephemeral_node_inactivity_timeout_default}" "^[0-9]+[smhd]([0-9]+[smhd])*$" "Invalid 'EPHEMERAL_NODE_INACTIVITY_TIMEOUT'. Must be a valid duration (e.g., '30m', '1h', '90s')."
}

#######################################
# Create our Headscale configuration file
#######################################
create_headscale_config() {
# Ensure all template variables are exported for envsubst
local template_vars=(
"ACME_EAB_BLOCK"
"CLOUDFLARE_ACME_BLOCK"
"SECURITY_HEADERS_BLOCK"
"PUBLIC_SERVER_URL"
"PUBLIC_LISTEN_PORT"
"HEADSCALE_DNS_BASE_DOMAIN"
"HEADSCALE_OVERRIDE_LOCAL_DNS"
"MAGIC_DNS"
"IP_PREFIXES"
"IP_ALLOCATION"
"HEADSCALE_EXTRA_RECORDS_PATH"
)
for var in "${template_vars[@]}"; do
export "${var}=${!var}"
done

create_config_from_template "${headscale_config}" "Headscale configuration file"
}

#######################################
# Create our Caddyfile
#######################################
create_caddyfile() {
if ${https_enabled}; then
create_config_from_template "${caddyfile_https}" "Caddy HTTPS configuration file"
else
create_config_from_template "${caddyfile_cleartext}" "Caddy HTTP configuration file"
fi
}

#######################################
# Validate ZeroSSL EAB credentials if provided and modify Caddyfile as needed
#######################################
Expand Down Expand Up @@ -353,6 +318,9 @@ check_caddy_environment_variables() {

if env_var_is_defined "CADDY_FRONTEND" && [[ "${CADDY_FRONTEND}" = "DISABLE_HTTPS" ]]; then
https_enabled=false
caddy_config_file="${caddyfile_cleartext}"
else
caddy_config_file="${caddyfile_https}"
return
fi

Expand Down Expand Up @@ -392,8 +360,8 @@ reuse_or_create_noise_private_key() {
fi

if env_var_is_defined "HEADSCALE_NOISE_PRIVATE_KEY"; then
printf '%s' "${HEADSCALE_NOISE_PRIVATE_KEY}" > "${key_path}"
chmod 600 "${key_path}"
printf '%s' "${HEADSCALE_NOISE_PRIVATE_KEY}" > "${key_path}"
chmod 600 "${key_path}"
else
log_info "Generating new Noise private key - existing clients will need to re-authenticate"
fi
Expand Down Expand Up @@ -425,9 +393,9 @@ check_config_files() {
export "${var}=${!var}"
done

create_headscale_config
create_config_from_template "${headscale_config}" "Headscale configuration file"

create_caddyfile
create_config_from_template "${caddy_config_file}" "Caddy configuration file"

reuse_or_create_noise_private_key
}
Expand Down Expand Up @@ -496,17 +464,10 @@ display_configuration_summary() {
start_caddy_service() {
log_info "Starting Caddy using our environment variables."

if ${https_enabled}; then
caddy start --config "${caddyfile_https}" || {
log_error "Failed to start Caddy with HTTPS config"
return
}
else
caddy start --config "${caddyfile_cleartext}" || {
log_error "Failed to start Caddy with cleartext config"
return
}
fi
caddy start --config "${caddy_config_file}" || {
log_error "Failed to start Caddy"
return
Comment on lines +467 to +469
Copy link

Copilot AI Feb 24, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new log message on Caddy startup failure is less actionable than before (it no longer indicates which config file/mode was used). Consider including ${caddy_config_file} (and/or whether HTTPS is enabled) in the error to make container logs easier to troubleshoot.

Copilot uses AI. Check for mistakes.
}

# Verify Caddy is actually running
sleep 2
Expand Down
Loading