the-real-deployinator
Version:
Deployinator for deployinate
65 lines (53 loc) • 2.07 kB
text/coffeescript
_ = require 'lodash'
colors = require 'colors'
request = require 'request'
commander = require 'commander'
debug = require('debug')('deployinator:deploy')
class DeployinatorDeploy
parseOptions: =>
commander
.usage '[options] <project-name> <tag>'
.option '-h, --host <https://deployinate.octoblu.com>',
'URI where deployinate-service is running (env: DEPLOYINATE_HOST)'
.option '-u, --user <octoblu>', 'Docker image user'
.parse process.argv
= commander.host ? process.env.DEPLOYINATE_HOST || 'https://deployinate.octoblu.com'
= commander.user ? 'octoblu'
= _.first commander.args
= commander.args[1]
= process.env.DEPLOYINATOR_UUID
= process.env.DEPLOYINATOR_TOKEN
run: =>
()
return new Error('Missing DEPLOYINATOR_UUID in environment') unless ?
return new Error('Missing DEPLOYINATOR_TOKEN in environment') unless ?
return new Error('Missing DEPLOYINATOR_HOST in environment') unless ?
return commander.outputHelp() unless ? && ?
()
deploy: =>
console.log ""
console.log "=>",
console.log ""
options =
uri: "/deployments"
baseUrl:
auth: {, }
json:
repository: "#{@dockerUser}/#{@projectName}"
docker_url: "quay.io/#{@dockerUser}/#{@projectName}"
updated_tags: []
debug 'request.post', options
request.post options, (error, response, body) =>
return error if error?
if response.statusCode >= 400
return new Error("[#{response.statusCode}] Deploy failed: #{JSON.stringify body}")
debug 'response', body
console.log 'Deployed', colors.yellow
console.log ""
die: (error) =>
if 'Error' == typeof error
console.error colors.red error.message
else
console.error colors.red arguments...
process.exit 1
new DeployinatorDeploy().run()