Skip to content

Commit

Permalink
feat: S3 AWS Publishing
Browse files Browse the repository at this point in the history
Enable publishing to a S3 AWS bucket.
Remove `isAuthTokenSet` and let each Publisher check the auth tokens.
For `auto-update` just use the `GenericProvider`.
  • Loading branch information
Anmo authored and develar committed Feb 5, 2017
1 parent ab41fcf commit fd4fc0f
Show file tree
Hide file tree
Showing 39 changed files with 460 additions and 203 deletions.
2 changes: 2 additions & 0 deletions .idea/electron-builder.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ FROM buildpack-deps:yakkety-curl

# python for node-gyp

ENV XZ_VERSION 5.2.2
ENV XZ_VERSION 5.2.3

# we don't use our bundled 7za because it is better to build for specific platform - not generic
ENV USE_SYSTEM_7ZA true
Expand All @@ -19,7 +19,7 @@ ENV DEBUG_COLORS true
ENV FORCE_COLOR true
ENV DEBIAN_FRONTEND noninteractive

RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv dist yarn && apt-get update -y && apt-get upgrade -y && \
RUN curl -L https://yarnpkg.com/latest.tar.gz | tar xvz && mv dist /yarn && apt-get update -y && apt-get upgrade -y && \
apt-get install --no-install-recommends -y xvfb git snapcraft qtbase5-dev xorriso bsdtar build-essential autoconf libssl-dev icnsutils libopenjp2-7 graphicsmagick gcc-multilib g++-multilib libgnome-keyring-dev lzip rpm yasm python libcurl3 && \
curl -O http://mirrors.kernel.org/ubuntu/pool/universe/libi/libicns/libicns1_0.8.1-3.1_amd64.deb && dpkg --install libicns1_0.8.1-3.1_amd64.deb && unlink libicns1_0.8.1-3.1_amd64.deb && \
wget -q -O - https://dl-ssl.google.com/linux/linux_signing_key.pub | apt-key add - && echo "deb http://dl.google.com/linux/chrome/deb/ stable main" > /etc/apt/sources.list.d/google.list && \
Expand Down
24 changes: 19 additions & 5 deletions docs/Publishing Artifacts.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ Travis and AppVeyor support publishing artifacts. But it requires additional con

`electron-builder` allows you to just add `GH_TOKEN` environment variable and that's all.

Currently, [GitHub Releases](https://help.github.com/articles/about-releases/) and [Bintray](https://bintray.com) are supported.
Currently, [GitHub Releases](https://help.github.com/articles/about-releases/), [Bintray](https://bintray.com) and [S3](https://aws.amazon.com/s3/) are supported.

## CLI Flags
```
Publishing:
--publish, -p [choices: "onTag", "onTagOrDraft", "always", "never"]
--draft Create a draft (unpublished) releas [boolean]
--draft Create a draft (unpublished) release [boolean]
--prerelease Identify the release as a prerelease [boolean]
```
CLI `--publish` option values:
Expand Down Expand Up @@ -44,9 +44,9 @@ But please consider using automatic rules instead of explicitly specifying `publ
"release": "build"
```
and if you run `npm run release`, a release will be drafted (if doesn't already exist) and artifacts published.

## GitHub Repository and Bintray Package

Detected automatically using:
* [repository](https://docs.npmjs.com/files/package.json#repository) in the application or development `package.json`,
* if not set, env `TRAVIS_REPO_SLUG` or `APPVEYOR_ACCOUNT_NAME`/`APPVEYOR_PROJECT_NAME` or `CIRCLE_PROJECT_USERNAME`/`CIRCLE_PROJECT_REPONAME`,
Expand All @@ -67,6 +67,7 @@ But please consider using automatic rules instead of explicitly specifying `publ
* [publish Bintray](#BintrayOptions)
* [publish Generic (any https server)](#GenericServerOptions)
* [publish GitHub](#GithubOptions)
* [publish S3](#S3Options)

<a name="PublishConfiguration"></a>
### `publish`
Expand All @@ -75,14 +76,15 @@ Can be specified in the [build](https://github.com/electron-userland/electron-bu

If `GH_TOKEN` is set — defaults to `[{provider: "github"}]`.
If `BT_TOKEN` is set and `GH_TOKEN` is not set — defaults to `[{provider: "bintray"}]`.
If `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are set and neither `GH_TOKEN` and `BT_TOKEN` are set — defaults to `[{provider: "s3"}]`.

Array of option objects. Order is important — first item will be used as a default auto-update server on Windows (NSIS).

Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, format `https://s3.amazonaws.com/bucket_name` [must be used](http://stackoverflow.com/a/11203685/1910191). And do not forget to make files/directories public.

| Name | Description
| --- | ---
| **provider** | <a name="PublishConfiguration-provider"></a>The provider, one of `github`, `bintray`, `generic`.
| **provider** | <a name="PublishConfiguration-provider"></a>The provider, one of `github`, `s3`, `bintray`, `generic`.
| owner | <a name="PublishConfiguration-owner"></a>The owner.

<a name="BintrayOptions"></a>
Expand All @@ -107,4 +109,16 @@ Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, f
| repo | <a name="GithubOptions-repo"></a>The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository).
| vPrefixedTagName | <a name="GithubOptions-vPrefixedTagName"></a>Whether to use `v`-prefixed tag name. Defaults to `true`.

<a name="S3Options"></a>
### `publish` S3

[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).

| Name | Description
| --- | ---
| bucket | <a name="S3Options-bucket"></a>The bucket name.
| channel | <a name="S3Options-channel"></a>The channel. Defaults to `latest`.
| acl | <a name="S3Options-acl"></a>The ACL. Defaults to `public-read`.
| storageClass | <a name="S3Options-storageClass"></a>The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`.

<!-- end of generated block -->
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"private": true,
"license": "MIT",
"scripts": {
"compile": "ts-babel packages/electron-builder-http packages/electron-builder-core packages/electron-builder-util packages/electron-builder packages/electron-builder-squirrel-windows packages/electron-updater test",
"compile": "ts-babel packages/electron-builder-http packages/electron-builder-core packages/electron-builder-util packages/electron-builder-publisher packages/electron-builder packages/electron-builder-squirrel-windows packages/electron-updater packages/electron-publisher-s3 test",
"lint": "node test/out/helpers/lint.js",
"pretest": "node ./test/vendor/yarn.js compile && node ./test/vendor/yarn.js lint && node ./test/vendor/yarn.js check-deps",
"check-deps": "node ./test/out/helpers/checkDeps.js",
Expand All @@ -25,6 +25,7 @@
"7zip-bin": "^2.0.4",
"archiver": "^1.3.0",
"asar-electron-builder": "^0.13.5",
"aws-sdk": "^2.9.0",
"bluebird-lst-c": "^1.0.6",
"chalk": "^1.1.3",
"chromium-pickle-js": "^0.2.0",
Expand Down Expand Up @@ -72,7 +73,7 @@
"jest-environment-node-debug": "^0.0.2",
"path-sort": "^0.1.0",
"source-map-support": "^0.4.11",
"ts-babel": "^1.3.5",
"ts-babel": "^1.3.6",
"tslint": "^4.4.2",
"typescript": "^2.2.0",
"whitespace": "^2.1.0"
Expand Down
2 changes: 1 addition & 1 deletion packages/electron-builder-http/src/httpExecutor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export class HttpExecutorHolder {

get httpExecutor(): HttpExecutor<any, any> {
if (this._httpExecutor == null) {
this._httpExecutor = new (require("electron-builder/out/util/nodeHttpExecutor").NodeHttpExecutor)()
this._httpExecutor = new (require("electron-builder-util/out/nodeHttpExecutor").NodeHttpExecutor)()
}
return this._httpExecutor
}
Expand Down
48 changes: 39 additions & 9 deletions packages/electron-builder-http/src/publishOptions.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export type PublishProvider = "github" | "bintray" | "generic"
export type PublishProvider = "github" | "bintray" | "s3" | "generic"

export type Publish = string | Array<string> | PublishConfiguration | GithubOptions | BintrayOptions | GenericServerOptions | Array<PublishConfiguration> | Array<GithubOptions> | Array<GenericServerOptions> | Array<BintrayOptions> | null
export type Publish = string | Array<string> | PublishConfiguration | GithubOptions | S3Options | BintrayOptions | GenericServerOptions | Array<PublishConfiguration> | Array<GithubOptions> | Array<S3Options> | Array<GenericServerOptions> | Array<BintrayOptions> | null

/*
### `publish`
Expand All @@ -9,23 +9,24 @@ Can be specified in the [build](https://github.com/electron-userland/electron-bu
If `GH_TOKEN` is set — defaults to `[{provider: "github"}]`.
If `BT_TOKEN` is set and `GH_TOKEN` is not set — defaults to `[{provider: "bintray"}]`.
If `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY` are set and neither `GH_TOKEN` and `BT_TOKEN` are set — defaults to `[{provider: "s3"}]`.
Array of option objects. Order is important — first item will be used as a default auto-update server on Windows (NSIS).
Amazon S3 — `https` must be used, so, if you use direct Amazon S3 endpoints, format `https://s3.amazonaws.com/bucket_name` [must be used](http://stackoverflow.com/a/11203685/1910191). And do not forget to make files/directories public.
*/
export interface PublishConfiguration {
/*
The provider, one of `github`, `bintray`, `generic`.
The provider, one of `github`, `s3`, `bintray`, `generic`.
*/
provider: PublishProvider

/*
The owner.
*/
owner?: string
owner?: string | null

token?: string
token?: string | null
}

/*
Expand All @@ -43,6 +44,35 @@ export interface GenericServerOptions extends PublishConfiguration {
channel?: string | null
}

/*
### `publish` S3
[Getting your credentials](http://docs.aws.amazon.com/sdk-for-javascript/v2/developer-guide/getting-your-credentials.html).
*/
export interface S3Options extends PublishConfiguration {
/*
The bucket name.
*/
bucket?: string

/**
The channel. Defaults to `latest`.
*/
channel?: string | null

/**
The ACL. Defaults to `public-read`.
*/
acl?: "private" | "public-read" | null

/*
The type of storage to use for the object. One of `STANDARD`, `REDUCED_REDUNDANCY`, `STANDARD_IA`. Defaults to `STANDARD`.
*/
storageClass?: "STANDARD" | "REDUCED_REDUNDANCY" | "STANDARD_IA" | null

secret?: string | null
}

export interface VersionInfo {
readonly version: string
}
Expand All @@ -64,7 +94,7 @@ export interface GithubOptions extends PublishConfiguration {
/*
The repository name. [Detected automatically](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts#github-repository).
*/
repo?: string
repo?: string | null

/*
Whether to use `v`-prefixed tag name. Defaults to `true`.
Expand All @@ -79,15 +109,15 @@ export interface BintrayOptions extends PublishConfiguration {
/*
The Bintray package name.
*/
package?: string
package?: string | null

/*
The Bintray repository name. Defaults to `generic`.
*/
repo?: string
repo?: string | null

/*
The Bintray user account. Used in cases where the owner is an organization.
*/
user?: string
user?: string | null
}
5 changes: 1 addition & 4 deletions packages/electron-builder-http/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@
"src/**/*.ts"
],
"files": [
"../../node_modules/@types/node/index.d.ts",
"../../node_modules/fs-extra-p/index.d.ts",
"../../typings/debug.d.ts",
"../../node_modules/@types/js-yaml/index.d.ts"
"../../typings/debug.d.ts"
]
}
22 changes: 22 additions & 0 deletions packages/electron-builder-publisher/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"name": "electron-builder-publisher",
"version": "0.0.0-semantic-release",
"main": "out/publisher.js",
"author": "Vladimir Krivosheev",
"license": "MIT",
"repository": "electron-userland/electron-builder",
"bugs": "https://github.com/electron-userland/electron-builder/issues",
"homepage": "https://github.com/electron-userland/electron-builder",
"files": [
"out"
],
"dependencies": {
"fs-extra-p": "^3.1.0",
"progress": "^1.1.8",
"mime": "^1.3.4",
"bluebird-lst-c": "^1.0.6",
"electron-builder-http": "~0.0.0-semantic-release",
"electron-builder-util": "~0.0.0-semantic-release"
},
"typings": "./out/electron-builder-publisher.d.ts"
}
5 changes: 5 additions & 0 deletions packages/electron-builder-publisher/readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# electron-publisher-s3

Part of [electron-builder](https://github.com/electron-userland/electron-builder).

See the [Publishing Artifacts.](https://github.com/electron-userland/electron-builder/wiki/Publishing-Artifacts) section of the [Wiki](https://github.com/electron-userland/electron-builder/wiki) for more information.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import { Publisher, PublishOptions } from "./publisher"
import BluebirdPromise from "bluebird-lst-c"
import { log } from "electron-builder-util/out/log"
import { debug, isEmptyOrSpaces } from "electron-builder-util"
import { configureRequestOptions, HttpError } from "electron-builder-http"
import { BintrayClient, Version } from "electron-builder-http/out/bintray"
import { BintrayOptions } from "electron-builder-http/out/publishOptions"
import { debug, isEmptyOrSpaces } from "electron-builder-util"
import { log } from "electron-builder-util/out/log"
import { httpExecutor } from "electron-builder-util/out/nodeHttpExecutor"
import { ClientRequest } from "http"
import { NodeHttpExecutor } from "../util/nodeHttpExecutor"
import { HttpError, configureRequestOptions } from "electron-builder-http"
import { Publisher, PublishOptions } from "./publisher"

export class BintrayPublisher extends Publisher {
private _versionPromise: BluebirdPromise<Version>
private readonly httpExecutor: NodeHttpExecutor = new NodeHttpExecutor()

private readonly client: BintrayClient

Expand Down Expand Up @@ -58,7 +57,7 @@ export class BintrayPublisher extends Publisher {
let badGatewayCount = 0
for (let i = 0; i < 3; i++) {
try {
return await this.httpExecutor.doApiRequest<any>(configureRequestOptions({
return await httpExecutor.doApiRequest<any>(configureRequestOptions({
hostname: "api.bintray.com",
path: `/content/${this.client.owner}/${this.client.repo}/${this.client.packageName}/${version.name}/${fileName}`,
method: "PUT",
Expand Down
Loading

0 comments on commit fd4fc0f

Please sign in to comment.