ff-stream-web

git clone git://archive.git.mtrnord.blog/MTRNord/ff-stream-web.git
Log | Files | Refs | README | LICENSE

commit b8bb6367b7b24c9e79ee893a5eccce3734b6641f
parent 26668a7f685fdae17f8a95663b99b66ac260e8c2
Author: Konstantin Tarkus <hello@tarkus.me>
Date:   Sun, 20 Sep 2015 09:16:11 +0300

Update the deployment script

...with a basic Git-based deployment flow

Diffstat:
Mpackage.json | 2+-
Mtools/deploy.js | 64+++++++++++++++++++++++++++++++++++++++-------------------------
Atools/lib/fetch.js | 14++++++++++++++
3 files changed, 54 insertions(+), 26 deletions(-)

diff --git a/package.json b/package.json @@ -37,7 +37,7 @@ "eslint-loader": "^1.0.0", "eslint-plugin-react": "^3.4.2", "gaze": "^0.5.1", - "git-push": "^0.1.1", + "git-repository": "^0.1.1", "glob": "^5.0.14", "jest-cli": "^0.5.7", "mkdirp": "^0.5.1", diff --git a/tools/deploy.js b/tools/deploy.js @@ -7,34 +7,48 @@ * LICENSE.txt file in the root directory of this source tree. */ -import push from 'git-push'; +import GitRepo from 'git-repository'; +import fetch from './lib/fetch'; + +// TODO: Update deployment URL +// For more information visit http://gitolite.com/deploy.html +const getRemote = (slot) => ({ + name: slot ? slot : 'production', + url: `https://example${slot ? '-' + slot : ''}.scm.azurewebsites.net:443/example.git`, + website: `http://example${slot ? '-' + slot : ''}.azurewebsites.net`, +}); /** * Deploy the contents of the `/build` folder to a remote - * server via Git. Example: `npm run deploy -- staging` + * server via Git. Example: `npm run deploy -- production` */ -export default () => new Promise((resolve, reject) => { - let remote; - - if (process.argv.includes('production')) { - remote = { - name: 'production', - url: 'https://example.scm.azurewebsites.net/example.git', - branch: 'master', - }; - } else if (process.argv.includes('staging')) { - remote = { - name: 'staging', - url: 'https://example-staging.scm.azurewebsites.net/example.git', - branch: 'master', - }; - } else { - remote = { - name: 'test', - url: 'https://example-test.scm.azurewebsites.net/example.git', - branch: 'master', - }; +export default async () => { + // By default deploy to the staging deployment slot + const remote = getRemote(process.argv.includes('production') ? null : 'staging'); + + // Initialize a new Git repository inside the `/build` folder + // if it doesn't exist yet + const repo = await GitRepo.open('build', { init: true }); + await repo.setRemote(remote.name, remote.url); + + // Fetch the remote repository if it exists + if ((await repo.hasRef(remote.url, 'master'))) { + await repo.fetch(remote.name); + await repo.reset(`${remote.name}/master`, { hard: true }); + await repo.clean({ force: true }); } - push('./build', remote, err => err ? reject(err) : resolve()); -}); + // Build the project in RELEASE mode which + // generates optimized and minimized bundles + process.argv.push('release'); + await require('./build')(); + + // Push the contents of the build folder to the remote server via Git + await repo.add('--all .'); + await repo.commit('Update'); + await repo.push(remote.name, 'master'); + + // Check if the site was successfully deployed + const response = await fetch(remote.website); + console.log(`${remote.website} -> ${response.statusCode}`); +}; diff --git a/tools/lib/fetch.js b/tools/lib/fetch.js @@ -0,0 +1,14 @@ +/** + * React Starter Kit (http://www.reactstarterkit.com/) + * + * Copyright © 2014-2015 Kriasoft, LLC. All rights reserved. + * + * This source code is licensed under the MIT license found in the + * LICENSE.txt file in the root directory of this source tree. + */ + +import http from 'http'; + +export default async (url) => new Promise((resolve, reject) => + http.get(url, res => resolve(res)).on('error', err => reject(err)) +);