Skip to content

Commit

Permalink
fix: S3 URLs (#1373) (#1374)
Browse files Browse the repository at this point in the history
Close #1373
  • Loading branch information
Markus Müller authored and develar committed Mar 16, 2017
1 parent bbdc29a commit ac75e8c
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ Amazon S3 options. `https` must be used, so, if you use direct Amazon S3 endpoin
| --- | --- | --- |
| **bucket**| <code>string</code> | <a name="S3Options-bucket"></a>The bucket name. |
| path = <code>&quot;/&quot;</code>| <code>string</code> \| <code>null</code> | <a name="S3Options-path"></a>The directory path. |
| region| <code>string</code> \| <code>null</code> | <a name="S3Options-region"></a>The region. Is determined and set automatically when publishing. |
| channel = <code>&quot;latest&quot;</code>| <code>string</code> \| <code>null</code> | <a name="S3Options-channel"></a>The channel. |
| acl = <code>public-read</code>| <code>"private"</code> \| <code>"public-read"</code> \| <code>null</code> | <a name="S3Options-acl"></a>The ACL. |
| 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. |
Expand Down
18 changes: 17 additions & 1 deletion packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,11 @@ export interface S3Options extends PublishConfiguration {
*/
readonly path?: string | null

/**
* The region. Is determined and set automatically when publishing.
*/
readonly region?: string | null

/**
* The channel.
* @default latest
Expand All @@ -115,7 +120,18 @@ export interface S3Options extends PublishConfiguration {
}

export function s3Url(options: S3Options) {
let url = `https://${options.bucket}.s3.amazonaws.com`
let url: string
if (options.bucket.indexOf(".") === -1) {
url = `https://${options.bucket}.s3.amazonaws.com`
} else {
if (!options.region) throw new Error("Bucket name includes a dot, but S3 region is missing")

// Special case, see http://docs.aws.amazon.com/AmazonS3/latest/dev/UsingBucket.html#access-bucket-intro
url = (options.region === "us-east-1")
? `https://s3.amazonaws.com/${options.bucket}`
: `https://s3-${options.region}.amazonaws.com/${options.bucket}`
}

if (options.path != null) {
url += `/${options.path}`
}
Expand Down
9 changes: 5 additions & 4 deletions packages/electron-builder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,34 +44,35 @@
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"dependencies": {
"7zip-bin": "^2.0.4",
"ajv": "^5.0.4-beta.0",
"ajv-keywords": "^2.0.1-beta.1",
"7zip-bin": "^2.0.4",
"aws-sdk": "^2.28.0",
"bluebird-lst": "^1.0.1",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
"cuint": "^0.2.2",
"electron-builder-core": "0.0.0-semantic-release",
"electron-builder-http": "0.0.0-semantic-release",
"electron-builder-util": "0.0.0-semantic-release",
"electron-publish": "0.0.0-semantic-release",
"electron-download-tf": "4.0.0",
"electron-macos-sign": "~1.6.0",
"electron-publish": "0.0.0-semantic-release",
"fs-extra-p": "^4.0.2",
"hosted-git-info": "^2.2.0",
"is-ci": "^1.0.10",
"isbinaryfile": "^3.0.2",
"js-yaml": "^3.8.2",
"minimatch": "^3.0.3",
"node-forge": "^0.7.0",
"normalize-package-data": "^2.3.6",
"parse-color": "^1.0.0",
"plist": "^2.0.1",
"sanitize-filename": "^1.6.1",
"semver": "^5.3.0",
"update-notifier": "^2.1.0",
"uuid-1345": "^0.99.6",
"yargs": "^7.0.2",
"node-forge": "^0.7.0"
"yargs": "^7.0.2"
},
"typings": "./out/electron-builder.d.ts",
"publishConfig": {
Expand Down
8 changes: 8 additions & 0 deletions packages/electron-builder/src/publish/PublishManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import isCi from "is-ci"
import { safeDump } from "js-yaml"
import * as path from "path"
import * as url from "url"
import { S3 } from "aws-sdk"
import { PlatformSpecificBuildOptions } from "../metadata"
import { Packager } from "../packager"
import { ArtifactCreated, BuildInfo } from "../packagerApi"
Expand Down Expand Up @@ -89,6 +90,13 @@ export class PublishManager implements PublishContext {
}
}

if (publishConfig.provider === "s3" && (<S3Options>publishConfig).bucket.indexOf(".") !== -1) {
// On dotted bucket names, we need to use a path-based endpoint URL. Path-based endpoint URLs need to include the region.
const s3 = new S3({signatureVersion: "v4"})
const region = (await s3.getBucketLocation({ Bucket: (<S3Options>publishConfig).bucket }).promise()).LocationConstraint
publishConfig = Object.assign(publishConfig, {region: region})
}

await writeFile(path.join(packager.getResourcesDir(event.appOutDir), "app-update.yml"), safeDump(publishConfig))
})

Expand Down

0 comments on commit ac75e8c

Please sign in to comment.