Skip to content

Commit

Permalink
Adding better logs and update now.
Browse files Browse the repository at this point in the history
  • Loading branch information
arunoda committed Sep 7, 2017
1 parent 43627bb commit d5554a9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
17 changes: 11 additions & 6 deletions deploy-server/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,13 @@ const { resolve } = require('path')
const fs = require('mz/fs')
const GitHubApi = require('github')
const jwt = require('jsonwebtoken')
const logger = console

const { ZEIT_TOKEN, GH_KEY } = process.env

module.exports = async (pullRequestId, tarballName) => {
// Extract the static ap
// Extract the static app
logger.log(`${pullRequestId}=> moving the tarball`)
await fs.mkdir(`/tmp/${tarballName}`)
await fs.rename(
`/tmp/${tarballName}.tar.gz`,
Expand All @@ -18,15 +20,16 @@ module.exports = async (pullRequestId, tarballName) => {
cwd: `/tmp/${tarballName}`
}

logger.log(`${pullRequestId}=> extracting the tarball`)
await exec('tar xzf app.tar.gz', execOptions)

// Deploy it to now
const nowPath = resolve(__dirname, 'node_modules/.bin/now')
await exec(`${nowPath} switch zeit -t ${ZEIT_TOKEN}`, execOptions)
const nowApp = await exec(
`${nowPath} -n zeit-docs -t ${ZEIT_TOKEN} out`,
execOptions
)

logger.log(`${pullRequestId}=> deploy the app`)
const nowApp = await exec(`${nowPath} -p -n zeit-docs -t ${ZEIT_TOKEN}`, {
cwd: `${execOptions.cwd}/out`
})

const deployUrl = nowApp.stdout

Expand All @@ -42,13 +45,15 @@ module.exports = async (pullRequestId, tarballName) => {
})

const key = Buffer.from(GH_KEY, 'base64').toString('utf8')
logger.log(`${pullRequestId}=> get the github token`)
const token = await getToken(github, key, 3412, 36421)

github.authenticate({
type: 'token',
token
})

logger.log(`${pullRequestId}=> create the deploy comment`)
await github.issues.createComment({
owner: 'zeit',
repo: 'docs',
Expand Down
2 changes: 1 addition & 1 deletion deploy-server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
},
"devDependencies": {
"github": "^9.2.0",
"now": "^7.1.1"
"now": "^8.1.0"
}
}
1 change: 1 addition & 0 deletions deploy-server/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ app.post('/deploy/:pullRequestId', (req, res) => {
res.send('SUCCESS')
})
.catch(error => {
logger.error(error.stack)
return res.status(500).send(error)
})
})
Expand Down
6 changes: 3 additions & 3 deletions deploy-server/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -372,9 +372,9 @@ netrc@^0.1.4:
version "0.1.4"
resolved "https://registry.yarnpkg.com/netrc/-/netrc-0.1.4.tgz#6be94fcaca8d77ade0a9670dc460914c94472444"

now@^7.1.1:
version "7.4.0"
resolved "https://registry.yarnpkg.com/now/-/now-7.4.0.tgz#2da0d236fd6d6d9277e9c5cf4ba87ea455788627"
now@^8.1.0:
version "8.1.0"
resolved "https://registry.yarnpkg.com/now/-/now-8.1.0.tgz#c947b48652c27b9cf888958f07244e8595e09767"

object-assign@^4.0.1:
version "4.1.1"
Expand Down

0 comments on commit d5554a9

Please sign in to comment.