textbelt icon indicating copy to clipboard operation
textbelt copied to clipboard

Docker and Vagrant images for textbelt (for self hosting)

Open daluu opened this issue 9 years ago • 6 comments

I took a shot at creating a docker image for textbelt so others could easily deploy it for self hosting without having to figure out and go through the steps needed to set everything up.

The image spec under development can be found here: https://github.com/daluu/textbelt/blob/master/Dockerfile

Once fully validated, I can file a PR and we could also push out a compiled image to the Docker hub.

At the moment, the image builds fine. But it seems there are problems getting textbelt to work (to elaborate in follow up comments).

Anyone with Docker and/or textbelt self hosting configuration expertise are welcome to chime in and patch up the image spec to get it working ;-)

Also, perhaps alternatively, we should consider a vagrant spec to create a similar image (virtual machine, but not docker-based). But I know vagrant less than I do docker.

daluu avatar Sep 18 '16 07:09 daluu

Issues encountered thus far below. In an interactive debug session.

I start up the docker container, going into the shell, with ports mapped (to my local host 8080 for container image's 9090) for testing the server component.

docker run --rm -it -p 8080:9090 typpo/textbelt bash

go into node interpreter shell

root@db04efec830f:/opt/textbelt# node

Try loading textbelt module per README

> var text = require('textbelt');
Error: Cannot find module 'textbelt'
    at Function.Module._resolveFilename (module.js:325:15)
    at Function.Module._load (module.js:276:25)
    at Module.require (module.js:353:17)
    at require (internal/module.js:12:17)
    at repl:1:12
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)

seems can't find module, maybe docker node path reference not set up right, or I started node shell in wrong root path. But this works though:

> var text = require('./index.js');
undefined
> text
{ send: [Function: sendText], debug: [Function: debug] }

now test send message

> text.send('5551234567', 'A sample text message!', undefined, function(err) { if (err) { console.log(err); } });
TypeError: Cannot read property 'map' of undefined
    at Object.sendText [as send] (/opt/textbelt/lib/text.js:62:30)
    at repl:1:6
    at REPLServer.defaultEval (repl.js:262:27)
    at bound (domain.js:287:14)
    at REPLServer.runBound [as eval] (domain.js:300:12)
    at REPLServer.<anonymous> (repl.js:431:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
    at REPLServer.Interface._onLine (readline.js:212:10)
    at REPLServer.Interface._line (readline.js:551:8)

some exception, so can't send message. Don't know enough about details at the moment. To look into further later.

Let's try the server component:

root@db04efec830f:/opt/textbelt# node server/app.js 
{ [Error: ENOENT: no such file or directory, open '/opt/textbelt/server/torlist']
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: '/opt/textbelt/server/torlist' }
Listening on 9090
txting phone 5551234567 : I sent this message for free with textbelt.com
I sent this message for free with textbelt.com
postdrop: warning: unable to look up public/pickup: No such file or directory

server starts up ok. And can HTTP POST to it per external request done separately (below). But looks like internally it fails lookup to complete sending the message :(

curl -X POST http://localhost:8080/text -d number=5551234567 -d "message=I sent this message for free with textbelt.com"
{
  "success": true
}

NOTE: number listed in snippets above is not the actual number I used to test textbelt.

Other items of concern:

  • I defined everything for redis, but not auto-start yet. It doesn't auto start when container is started (whether running textbelt module, textbelt server, or just bash prompt into container). One still has to start the service from the container first before using textbelt (server), although one could wrap a script to do it. To start redis service: /etc/init.d/redis_6379 start.
  • No nginx setup yet, not a priority at the moment I'd think
  • mutt installed but I haven't verified if it's fully working or not

daluu avatar Sep 18 '16 07:09 daluu

One other thing I forgot to mention, originally based the docker image to use node.js 0.12 with the same install process. For 0.12, for some reason "npm" was not found after install, so could not do npm install.

Since node 0.12 is deprecated, I switched to node 4 instead of trying to figure out and fix the npm issue. Node 4 install worked right off the bat for npm. So for anyone using another node version, there could be problems building the image, or not.

daluu avatar Sep 18 '16 07:09 daluu

I added a vagrant config as well, although I haven't really worked with vagrant myself. Based off default template a colleague supplied to me.

daluu avatar Sep 28 '16 06:09 daluu

FYI, there appears to be a docker image available publicly on docker hub but w/o any details on how to use it, a Github repo to work off of, nor contact info to the author/maintainer. But something to R&D for anyone interested. On initial evaluation, seems harder to use than my image definition, I couldn't even get anything to run. Starting container just gives you a shell with no node & npm installed but just the textbelt repo files.

https://hub.docker.com/r/cyna/textbelt/

daluu avatar Mar 17 '18 20:03 daluu

Fixed warning/error for the server instance when sending text message through it, for Docker. For server usage, must start redis 1st (until we can fix it in image to auto-start) then start server.

For command script usage, due to PR https://github.com/typpo/textbelt/pull/57, have to invoke differently like one of these ways:

text.send('5551234567', "test message", 'att', undefined, function(err) { if (err) { console.log(err); } });

text.send('5551234567', "test message", undefined, undefined, function(err) { if (err) { console.log(err); } });

where 1st parameter after text message is carrier name in the carrier list mapping, leave undefined if not specifying, and following parameter is the region (which defaults to "US" if not specified/undefined).

Still no idea how to "require" textbelt module by name rather than "./index.js" though.

And last still don't know how to get the mail routing to have the service actually send out the message, get "success" now but don't receive any message.

daluu avatar Mar 18 '18 00:03 daluu

Well, aside from using it like a module, the server side setup is about done for docker image to build and use. But it doesn't seem to really work for me (the built image), and haven't had time to investigate in depth the details of the message to email process.

But if anyone likes to try, feel free to. Build the image with docker via docker build -t typpo/textbelt . from the clone of github repo. Then run image like docker run --rm -it -p 9090:9090 typpo/textbelt bash to give you bash shell to start up the services (redis & textbelt) or to use it like a module. You can change the image tagging to be something other than typpo/textbelt. Note that the Dockerfile is still in my fork's master branch: https://github.com/daluu/textbelt. Just copy over the Dockerfile to typpo's original repo and build (since I don't sync my fork to latest code often).

Be interested to know if things work for others. If anything not working, it's probably the mutt/sendmail configuration needs to be tweaked from default, as the textbelt side of things looks ok.

daluu avatar Mar 20 '18 05:03 daluu