Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Azure Deployment Failed | The resource operation completed with terminal provisioning state 'Failed'. #361

Open
ajayak opened this issue Mar 9, 2018 · 7 comments

Comments

@ajayak
Copy link

ajayak commented Mar 9, 2018

The Azure deployment fails on/after Setting up Source Control step.

Error Message:

The resource operation completed with terminal provisioning state 'Failed'.

Can be replicated in both stable and latest build.

@BerendWouters
Copy link

I've encountered the same issue.

Command: bash scripts/azuredeploy.sh
Invalid start-up command "chmod +x bin/slackin && ./bin/slackin" in package.json. Please use the format "node <script relative path>".
Looking for app.js/server.js under site root.
Missing server.js/app.js files, web.config is not generated
Node.js versions available on the platform are: 0.6.20, 0.8.2, 0.8.19, 0.8.26, 0.8.27, 0.8.28, 0.10.5, 0.10.18, 0.10.21, 0.10.24, 0.10.26, 0.10.28, 0.10.29, 0.10.31, 0.10.32, 0.10.40, 0.12.0, 0.12.2, 0.12.3, 0.12.6, 4.0.0, 4.1.0, 4.1.2, 4.2.1, 4.2.2, 4.2.3, 4.2.4, 4.3.0, 4.3.2, 4.4.0, 4.4.1, 4.4.6, 4.4.7, 4.5.0, 4.6.0, 4.6.1, 4.8.4, 5.0.0, 5.1.1, 5.3.0, 5.4.0, 5.5.0, 5.6.0, 5.7.0, 5.7.1, 5.8.0, 5.9.1, 6.0.0, 6.1.0, 6.2.2, 6.3.0, 6.5.0, 6.6.0, 6.7.0, 6.9.0, 6.9.1, 6.9.2, 6.9.4, 6.9.5, 6.10.0, 6.10.3, 6.11.1, 6.11.2, 6.11.5, 6.12.2, 6.12.3, 7.0.0, 7.1.0, 7.2.0, 7.3.0, 7.4.0, 7.5.0, 7.6.0, 7.7.0, 7.7.4, 7.10.0, 7.10.1, 8.0.0, 8.1.4, 8.4.0, 8.5.0, 8.7.0, 8.8.0, 8.8.1, 8.9.0, 8.9.3, 8.9.4, 8.10.0, 8.11.1.
Selected node.js version 6.11.1. Use package.json file to choose a different version.
Unable to locate npm version 3.3.12
An error has occurred during web site deployment.
select node version failed
Invalid start-up command "chmod +x bin/slackin && ./bin/slackin" in package.json. Please use the format "node <script relative path>".\r\nMissing server.js/app.js files, web.config is not generated\r\nUnable to locate npm version 3.3.12\r\nD:\Program Files (x86)\SiteExtensions\Kudu\72.10416.3366\bin\Scripts\starter.cmd bash scripts/azuredeploy.sh

@peetinc
Copy link

peetinc commented May 7, 2018

Same issue.

I don't know if this is any more help, but the error occurs in the "Write Sourcecontrols" step.

Peet

@ajayak
Copy link
Author

ajayak commented May 7, 2018

Hi @peetinc and @BerendWouters,

I faced the same issue. Instead of creating the app online, I would recommend you to download the app. Manually do all the steps and then publish the app.

Also make sure to do this fix: #366 so everything works as expected :)

@peetinc
Copy link

peetinc commented May 7, 2018

@ajayak Thanks you so much for the tip. I'm sorry to say this but I don't really know where to begin with what you're describing. I'm not asking for a step-by-step, but anything you could do to point me in the right direction would be great. I wish Git still had DM's I'd ask you off this thread.

Thanks.Peet

@ajayak
Copy link
Author

ajayak commented May 8, 2018

Hi @peetinc,

Follow these steps:

  1. Clone the Slackin repository
  2. Replace lib>index.js file with this:
// es6 runtime requirements
import 'babel-polyfill'

// their code
import express from 'express'
import sockets from 'socket.io'
import { json } from 'body-parser'
import { Server as http } from 'http'
import remail from 'email-regex'
import dom from 'vd'
import cors from 'cors'
import request from 'superagent';

// our code
import Slack from './slack'
import invite from './slack-invite'
import badge from './badge'
import splash from './splash'
import iframe from './iframe'
import log from './log'

export default function slackin ({
  token,
  interval = 5000, // jshint ignore:line
  org,
  gcaptcha_secret,
  gcaptcha_sitekey,
  css,
  coc,
  cors: useCors = false,
  path='/',
  channels,
  emails,
  silent = false // jshint ignore:line,
}){
  // must haves
  if (!token) throw new Error('Must provide a `token`.')
  if (!org) throw new Error('Must provide an `org`.')
  if (!gcaptcha_secret) throw new Error('Must provide a `gcaptcha_secret`.')
  if (!gcaptcha_sitekey) throw new Error('Must provide an `gcaptcha_sitekey`.')

  if (channels) {
    // convert to an array
    channels = channels.split(',').map((channel) => {
      // sanitize channel name
      if ('#' === channel[0]) return channel.substr(1)
      return channel
    })
  }

  if (emails) {
    // convert to an array
    emails = emails.split(',')
  }

  // setup app
  let app = express()
  let srv = http(app)
  srv.app = app

  let assets = __dirname + '/assets'

  // fetch data
  let slack = new Slack({ token, interval, org })

  slack.setMaxListeners(Infinity)

  // capture stats
  log(slack, silent)

  // middleware for waiting for slack
  app.use((req, res, next) => {
    if (slack.ready) return next()
    slack.once('ready', next)
  })

  if (useCors) {
    app.options('*', cors())
    app.use(cors())
  }

  // splash page
  app.get('/', (req, res) => {
    let { name, logo } = slack.org
    let { active, total } = slack.users
    if (!name) return res.send(404)
    let page = dom('html',
      dom('head',
        dom('title',
          'Join ', name, ' on Slack!'
        ),
        dom("script src=https://www.google.com/recaptcha/api.js"),
        dom('meta name=viewport content="width=device-width,initial-scale=1.0,minimum-scale=1.0,user-scalable=no"'),
        dom('link rel="shortcut icon" href=https://slack.global.ssl.fastly.net/272a/img/icons/favicon-32.png'),
        css && dom('link rel=stylesheet', { href: css })
      ),
      splash({ coc, path, css, name, org, logo, channels, active, total, gcaptcha_sitekey})
    )
    res.type('html')
    res.send(page.toHTML())
  })

  app.get('/data', (req, res) => {
    let { name, logo } = slack.org
    let { active, total } = slack.users
    res.send({
      name,
      org,
      coc,
      logo,
      channels,
      active,
      total
    })
  })

  // static files
  app.use('/assets', express.static(assets))

  // invite endpoint
  app.post('/invite', json(), (req, res, next) => {
    global['chanId'] = null;
    if (channels) {
      let channel = req.body.channel
      if (!channels.includes(channel)) {
        return res
        .status(400)
        .json({ msg: 'Not a permitted channel' })
      }
      global['chanId'] = slack.getChannelId(channel)
      if (!global['chanId']) {
        return res
        .status(400)
        .json({ msg: `Channel not found "${channel}"` })
      }
    }

    let email = req.body.email
    let captcha_response = req.body['g-recaptcha-response'];

    if (!email) {
      return res
      .status(400)
      .json({ msg: 'No email provided' })
    }

    if(captcha_response == undefined || !captcha_response.length){
      return res
      .status(400)
      .send({ msg: 'Invalid captcha' });
    }

    if (!remail().test(email)) {
      return res
      .status(400)
      .json({ msg: 'Invalid email' })
    }

    // Restricting email invites?
    if (emails && emails.indexOf(email) === -1) {
      return res
      .status(400)
      .json({ msg: 'Your email is not on the accepted email list' })
    }

    if (coc && '1' != req.body.coc) {
      return res
      .status(400)
      .json({ msg: 'Agreement to CoC is mandatory' })
    }

    /////////////////////////////////////////////////////////////////////////


    const captcha_data = {
      secret: gcaptcha_secret,
      response: captcha_response,
      remoteip: req.connection.remoteAddress
    }


    const captcha_callback = (err, resp) => {

      if (err) {
        return res
        .status(400)
        .send({ msg: err });

      }else{

        if(resp.body.success){
          let chanId = slack.channel ? slack.channel.id : global['chanId'];
          invite({ token, org, email, channel: chanId }, err => {
            if (err) {
              if (err.message === `Sending you to Slack...`) {
                return res
                .status(303)
                .json({ msg: err.message, redirectUrl: `https://${org}.slack.com` })
              }

              return res
              .status(400)
              .json({ msg: err.message })
            }

            res
            .status(200)
            .json({ msg: 'WOOT. Check your email!' })
          });

        }else{

          if (err) {
            return res
            .status(400)
            .send({ msg: "Captcha check failed" });
          }
        }

      }

    }


    request.post('https://www.google.com/recaptcha/api/siteverify')
    .type('form')
    .send(captcha_data)
    .end(captcha_callback);


  })

  // iframe
  app.get('/iframe', (req, res) => {
    let large = 'large' in req.query
    let { active, total } = slack.users
    res.type('html')
    res.send(iframe({ path, active, total, large }).toHTML())
  })

  app.get('/iframe/dialog', (req, res) => {
    let large = 'large' in req.query
    let { name } = slack.org
    let { active, total } = slack.users
    if (!name) return res.send(404)
    let page = dom('html',
      dom("script src=https://www.google.com/recaptcha/api.js"),
      splash({ coc, path, name, org, channels, active, total, large, iframe: true, gcaptcha_sitekey })
    )
    res.type('html')
    res.send(page.toHTML())
  })

  app.get('/.well-known/acme-challenge/:id', (req, res) => {
    res.send(process.env.LETSENCRYPT_CHALLENGE)
  })

  // badge js
  app.use('/slackin.js', express.static(assets + '/badge.js'))

  // badge rendering
  app.get('/badge.svg', (req, res) => {
    res.type('svg')
    res.set('Cache-Control', 'max-age=0, no-cache')
    res.set('Pragma', 'no-cache')
    res.send(badge(slack.users).toHTML())
  })

  // realtime
  sockets(srv).on('connection', socket => {
    socket.emit('data', slack.users)
    let change = (key, val) => socket.emit(key, val)
    slack.on('change', change)
    socket.on('disconnect', () => {
      slack.removeListener('change', change)
    })
  })

  return srv
}
  1. Deploy to Azure node app service. In application settings of the app service, set these environment variables:
    GOOGLE_CAPTCHA_SECRET, GOOGLE_CAPTCHA_SITEKEY, PORT, SLACK_API_TOKEN, SLACK_CHANNELS and SLACK_SUBDOMAIN

@BerendWouters
Copy link

Thanks! It worked after adding the Google Captcha parameters, but I had to remove the PORT parameter for Azure.

@KrzysztofMadejski
Copy link

Seems like duplicate of #355

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants