How to set a AWS S3 bucket feed url to Electron autoUpdater

Viewed 1403

I can able to publish electron application to AWS S3 bucket. but how to get updates from a electron app published S3 bucket using electron autoUpdater?

2 Answers

For folks using Squirrel (i.e. with electron-forge), there are some key settings to go serverless. Example is with DO Spaces, but same should apply to any s3 compatible bucket storage.

The forge config is as follows:

    ...
    makers: [
        {
            name: '@electron-forge/maker-squirrel',
            config: {
                setupExe: 'Setup.exe',  // Fixed path for latest setup exe
                remoteReleases: 'https://<bucket>.<region>.digitaloceanspaces.com/<folder>'
            },
        }
    ],
    make_targets: {
        win32: ['squirrel'],
    },
    publishers: [
        {
            name: '@electron-forge/publisher-s3',
            config: {
                bucket: '<bucket>',
                endpoint: 'https://<region>.digitaloceanspaces.com',
                folder: '<folder>',  // IMPORTANT: always use the same folder
                region: '<region>',
                public: true  // Necessary for serverless
            }
        }
    ],
    ...

Then we simply point the auto-updater at the bucket:

autoUpdater.setFeedURL('https://<bucket>.<region>.digitaloceanspaces.com/<folder>')

The reason this works is because Squirrel itself can even work with a static filesystem or server, all the logic is baked into Update.exe itself. It simply looks at the RELEASES file at the feed url and determines if it needs to update with the listed nuget packages.

Essentially, the variable folder URL is what prevents this from working out-of-the-box with autoUpdater.setFeedUrl(), you want all the files (setup.exe, RELEASES, and nuget for each version) in the same folder for the same platform/architecture.

Note: be careful if you use a CDN! If RELEASES gets cached then the app won't update until it gets the new version.

By default all files are positioned at the following key:

${config.folder || appVersion}/${artifactName}

Configuration options are documented in PublisherS3Config

{
  name: '@electron-forge/publisher-s3',
  config: {
    bucket: 'my-bucket',
    public: true
  }
}
Related