From 8fa6d134ad3576d1b055d56f0e6a411b6720fafd Mon Sep 17 00:00:00 2001 From: Andreas Dueren Date: Mon, 16 Jun 2025 11:44:45 -0600 Subject: [PATCH] Fix config generation loop and add gosu dependency --- Dockerfile.cloudron | 5 +++-- start.sh | 41 ++++++++++++++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 3 deletions(-) diff --git a/Dockerfile.cloudron b/Dockerfile.cloudron index 5f1cf2a..e954338 100644 --- a/Dockerfile.cloudron +++ b/Dockerfile.cloudron @@ -11,6 +11,7 @@ RUN apt-get update && apt-get install -y \ git \ build-essential \ libolm-dev \ + gosu \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* @@ -36,8 +37,8 @@ COPY start.sh /app/pkg/ VOLUME /app/data ENV UID=1337 GID=1337 -# Add health check endpoint +# Add health check endpoint - check if the appservice port is responding HEALTHCHECK --interval=60s --timeout=10s --start-period=30s --retries=3 \ - CMD curl -f http://localhost:29318/health || exit 1 + CMD nc -z localhost 29318 || exit 1 CMD ["/app/pkg/start.sh"] \ No newline at end of file diff --git a/start.sh b/start.sh index b9ec379..da55702 100755 --- a/start.sh +++ b/start.sh @@ -24,7 +24,46 @@ BACKUP_PATH="/app/data/config.yaml.bak" if [ ! -f "$CONFIG_PATH" ]; then echo "=> Generating example configuration" # Generate config as root first, then fix permissions - /app/pkg/mautrix-whatsapp -g -c "$CONFIG_PATH" -r "$REGISTRATION_PATH" + /app/pkg/mautrix-whatsapp -g -c "$CONFIG_PATH" -r "$REGISTRATION_PATH" || { + echo "=> Config generation failed, creating minimal config" + cat > "$CONFIG_PATH" << 'EOF' +homeserver: + address: https://matrix.example.com + domain: example.com + +appservice: + address: https://example.com + hostname: 0.0.0.0 + port: 29318 + database: + type: postgres + uri: postgres://user:pass@localhost/db + +bridge: + username_template: whatsapp_{{.}} + displayname_template: "{{if .BusinessName}}{{.BusinessName}}{{else}}{{.PushName}}{{end}} (WA)" + +logging: + handlers: + file: + filename: /app/data/logs/mautrix-whatsapp.log +EOF + cat > "$REGISTRATION_PATH" << 'EOF' +id: whatsapp +url: https://example.com +as_token: generated_token +hs_token: generated_token +rate_limited: false +sender_localpart: whatsappbot +namespaces: + users: + - exclusive: true + regex: '@whatsapp_.*:.*' + aliases: + - exclusive: true + regex: '#whatsapp_.*:.*' +EOF + } # Configure for Cloudron environment if [ -n "${CLOUDRON_POSTGRESQL_URL:-}" ]; then