Skip to content

Automatic updates not working when using Cloudflare R2 #544

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
justRau opened this issue Apr 7, 2025 · 1 comment
Open

Automatic updates not working when using Cloudflare R2 #544

justRau opened this issue Apr 7, 2025 · 1 comment
Labels
bug Something isn't working

Comments

@justRau
Copy link
Contributor

justRau commented Apr 7, 2025

What were you trying to do?

Use Cloudflare R2 as NativePHP updates provider.

What happened?

After publishing a new version, no popup or notice appear when restarting the app.

How to reproduce the bug

Cloudflare R2 is an S3-compatible object storage. When using it as a NativePHP updates provider, I set env vars to something like this:

AWS_ACCESS_KEY_ID=[R2 API token access key]
AWS_SECRET_ACCESS_KEY=[R2 API token secret access key]
AWS_DEFAULT_REGION=EEUR
AWS_BUCKET=bucket-name
AWS_URL=https://r2-updates.example-domain.com
AWS_ENDPOINT=https://[long-random-string-from-R2].r2.cloudflarestorage.com
AWS_USE_PATH_STYLE_ENDPOINT=false
AWS_S3_TOKEN_VALUE=[R2 API token value]

Note, AWS_URL value is actually a custom subdomain pointing to the R2 bucket. The only current reliable way to make R2 bucket publicly available is to point a custom (sub)domain.

At this point, building and uploading to R2 works.
What is not working – automatic updates. Or, rather, checks if an update is available.

Got some debugging info this way:

  • I've cloned nativephp/electron and configured local path as Composer repository.
  • In electron-plugin/dist/index.js changed some code to:
    startAutoUpdater(config) {
        const fs = require('fs');
        const path = require('path');
        const customLogger = {
            info: (message) => {
                fs.appendFileSync('/tmp/ivsa-electron-logs.log', `[INFO] ${new Date().toISOString()} - ${message}\n`);
                console.info(message); // Optional: keep console logging too
            },
            warn: (message) => {
                fs.appendFileSync('/tmp/ivsa-electron-logs.log', `[WARN] ${new Date().toISOString()} - ${message}\n`);
                console.warn(message);
            },
            error: (message) => {
                fs.appendFileSync('/tmp/ivsa-electron-logs.log', `[ERROR] ${new Date().toISOString()} - ${message}\n`);
                console.error(message);
            }
        };

        customLogger.info("Starting auto updater");
        customLogger.warn("Starting auto updater");
        customLogger.error("Starting auto updater");

        var _a;
        if (((_a = config === null || config === void 0 ? void 0 : config.updater) === null || _a === void 0 ? void 0 : _a.enabled) === true) {
            customLogger.info("Checking for updates");
            autoUpdater.logger = customLogger;
            autoUpdater.checkForUpdatesAndNotify();
            customLogger.info("Updates checked");
        }
    }
  • Bundled and ran the app.
  • Got log messages:
[INFO] 2025-04-07T14:38:45.343Z - Starting auto updater
[WARN] 2025-04-07T14:38:45.345Z - Starting auto updater
[ERROR] 2025-04-07T14:38:45.345Z - Starting auto updater
[INFO] 2025-04-07T14:38:45.345Z - Checking for updates
[INFO] 2025-04-07T14:38:45.345Z - Checking for update
[INFO] 2025-04-07T14:38:45.345Z - Updates checked
[ERROR] 2025-04-07T14:38:45.823Z - Error: HttpError: 400 Bad Request
"method: GET url: https://[xxxxxx].r2.cloudflarestorage.com/ivsa-updates/latest-mac.yml?noCache=1io8b10jd\n\n          Data:\n          <?xml version=\"1.0\" encoding=\"UTF-8\"?><Error><Code>InvalidArgument</Code><Message>Authorization</Message></Error>\n          "
Headers: {
  "cf-ray": "92ca4540bc0f0ef7-VNO",
  "connection": "keep-alive",
  "content-length": "113",
  "content-type": "application/xml",
  "date": "Mon, 07 Apr 2025 14:38:45 GMT",
  "server": "cloudflare",
  "vary": "Accept-Encoding"
}
    at createHttpError (/Applications/Ivsa.app/Contents/Resources/app.asar/node_modules/builder-util-runtime/out/httpExecutor.js:21:12)
    at IncomingMessage.<anonymous> (/Applications/Ivsa.app/Contents/Resources/app.asar/node_modules/builder-util-runtime/out/httpExecutor.js:152:28)
    at IncomingMessage.emit (node:events:518:28)
    at endReadableNT (node:internal/streams/readable:1698:12)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)

The problem is that https://[xxxxxx].r2.cloudflarestorage.com/ivsa-updates/latest-mac.yml is not the right path to load the latest-mac.yml file. But https://r2-updates.example-domain.com/latest-mac.yml is.
In order to form that URL, AWS_ENDPOINT must be changed to https://r2-updates.example-domain.com, but then bundled app upload to R2 fails with error, R2 response's status code 401.

Package Versions

{
    "installed": [
        {
            "name": "nativephp/electron",
            "direct-dependency": true,
            "homepage": "https://github.com/nativephp/electron",
            "source": null,
            "version": "1.0.0-beta.8",
            "description": "Electron wrapper for the NativePHP framework.",
            "abandoned": false
        },
        {
            "name": "nativephp/laravel",
            "direct-dependency": false,
            "homepage": "https://github.com/nativephp/laravel",
            "source": "https://github.com/NativePHP/laravel/tree/1.0.0-beta.4",
            "version": "1.0.0-beta.4",
            "description": "Laravel wrapper for the NativePHP framework.",
            "abandoned": false
        },
        {
            "name": "nativephp/php-bin",
            "direct-dependency": false,
            "homepage": "https://nativephp.com",
            "source": "https://github.com/NativePHP/php-bin/tree/0.6.1",
            "version": "0.6.1",
            "description": "PHP binaries used by the NativePHP framework",
            "abandoned": false
        }
    ]
}

PHP Version

8.3.16

Laravel Version

12.7.2

Node Version

22.14.0

Which operating systems have you seen this occur on?

macOS

OS version

macOS 15.3.1

Notes

No response

@justRau justRau added the bug Something isn't working label Apr 7, 2025
@justRau
Copy link
Contributor Author

justRau commented Apr 9, 2025

Forgot to mention: looks like one of the solutions could be using different AWS_ENDPOINT values during build-time and run-time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant