Skip to content

Commit ac75e8c

Browse files
Markus Müllerdevelar
authored andcommitted
fix: S3 URLs (#1373) (#1374)
Close #1373
1 parent bbdc29a commit ac75e8c

File tree

4 files changed

+31
-5
lines changed

4 files changed

+31
-5
lines changed

docs/Publishing Artifacts.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ Amazon S3 options. `https` must be used, so, if you use direct Amazon S3 endpoin
171171
| --- | --- | --- |
172172
| **bucket**| <code>string</code> | <a name="S3Options-bucket"></a>The bucket name. |
173173
| path = <code>&quot;/&quot;</code>| <code>string</code> \| <code>null</code> | <a name="S3Options-path"></a>The directory path. |
174+
| region| <code>string</code> \| <code>null</code> | <a name="S3Options-region"></a>The region. Is determined and set automatically when publishing. |
174175
| channel = <code>&quot;latest&quot;</code>| <code>string</code> \| <code>null</code> | <a name="S3Options-channel"></a>The channel. |
175176
| acl = <code>public-read</code>| <code>"private"</code> \| <code>"public-read"</code> \| <code>null</code> | <a name="S3Options-acl"></a>The ACL. |
176177
| storageClass = <code>STANDARD</code>| <code>"STANDARD"</code> \| <code>"REDUCED_REDUNDANCY"</code> \| <code>"STANDARD_IA"</code> \| <code>null</code> | <a name="S3Options-storageClass"></a>The type of storage to use for the object. |

packages/electron-builder-http/src/publishOptions.ts

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ export interface S3Options extends PublishConfiguration {
9595
*/
9696
readonly path?: string | null
9797

98+
/**
99+
* The region. Is determined and set automatically when publishing.
100+
*/
101+
readonly region?: string | null
102+
98103
/**
99104
* The channel.
100105
* @default latest
@@ -115,7 +120,18 @@ export interface S3Options extends PublishConfiguration {
115120
}
116121

117122
export function s3Url(options: S3Options) {
118-
let url = `https://${options.bucket}.s3.amazonaws.com`
123+
let url: string
124+
if (options.bucket.indexOf(".") === -1) {
125+
url = `https://${options.bucket}.s3.amazonaws.com`
126+
} else {
127+
if (!options.region) throw new Error("Bucket name includes a dot, but S3 region is missing")
128+
129+
// Special case, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
130+
url = (options.region === "us-east-1")
131+
? `https://s3.amazonaws.com/${options.bucket}`
132+
: `https://s3-${options.region}.amazonaws.com/${options.bucket}`
133+
}
134+
119135
if (options.path != null) {
120136
url += `/${options.path}`
121137
}

packages/electron-builder/package.json

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,34 +44,35 @@
4444
"bugs": "https://github.com/electron-userland/electron-builder/issues",
4545
"homepage": "https://github.com/electron-userland/electron-builder",
4646
"dependencies": {
47+
"7zip-bin": "^2.0.4",
4748
"ajv": "^5.0.4-beta.0",
4849
"ajv-keywords": "^2.0.1-beta.1",
49-
"7zip-bin": "^2.0.4",
50+
"aws-sdk": "^2.28.0",
5051
"bluebird-lst": "^1.0.1",
5152
"chalk": "^1.1.3",
5253
"chromium-pickle-js": "^0.2.0",
5354
"cuint": "^0.2.2",
5455
"electron-builder-core": "0.0.0-semantic-release",
5556
"electron-builder-http": "0.0.0-semantic-release",
5657
"electron-builder-util": "0.0.0-semantic-release",
57-
"electron-publish": "0.0.0-semantic-release",
5858
"electron-download-tf": "4.0.0",
5959
"electron-macos-sign": "~1.6.0",
60+
"electron-publish": "0.0.0-semantic-release",
6061
"fs-extra-p": "^4.0.2",
6162
"hosted-git-info": "^2.2.0",
6263
"is-ci": "^1.0.10",
6364
"isbinaryfile": "^3.0.2",
6465
"js-yaml": "^3.8.2",
6566
"minimatch": "^3.0.3",
67+
"node-forge": "^0.7.0",
6668
"normalize-package-data": "^2.3.6",
6769
"parse-color": "^1.0.0",
6870
"plist": "^2.0.1",
6971
"sanitize-filename": "^1.6.1",
7072
"semver": "^5.3.0",
7173
"update-notifier": "^2.1.0",
7274
"uuid-1345": "^0.99.6",
73-
"yargs": "^7.0.2",
74-
"node-forge": "^0.7.0"
75+
"yargs": "^7.0.2"
7576
},
7677
"typings": "./out/electron-builder.d.ts",
7778
"publishConfig": {

packages/electron-builder/src/publish/PublishManager.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import isCi from "is-ci"
1515
import { safeDump } from "js-yaml"
1616
import * as path from "path"
1717
import * as url from "url"
18+
import { S3 } from "aws-sdk"
1819
import { PlatformSpecificBuildOptions } from "../metadata"
1920
import { Packager } from "../packager"
2021
import { ArtifactCreated, BuildInfo } from "../packagerApi"
@@ -89,6 +90,13 @@ export class PublishManager implements PublishContext {
8990
}
9091
}
9192

93+
if (publishConfig.provider === "s3" && (<S3Options>publishConfig).bucket.indexOf(".") !== -1) {
94+
// On dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region.
95+
const s3 = new S3({signatureVersion: "v4"})
96+
const region = (await s3.getBucketLocation({ Bucket: (<S3Options>publishConfig).bucket }).promise()).LocationConstraint
97+
publishConfig = Object.assign(publishConfig, {region: region})
98+
}
99+
92100
await writeFile(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), safeDump(publishConfig))
93101
})
94102

0 commit comments

Comments
 (0)