How to Containerize MessageBird WhatsApp Campaign Builder (HSM API)

MessageBird WhatsApp Campaign Builder

HSM API is a WhatsApp campaign builder that uses the MessageBird Conversations API to broadcast messages.

  • Download the campaign builder from https://github.com/jakartabird/mb-campaign-builder
  • Clone the repository

$ git clone https://github.com/jakartabird/mb-campaign-builder

  • Change directory to the mb-campaign-builder
  • Edit the index.js file if necessary, e.g. concurrency
  • Make sure the uploads folder is there, and remove all the files inside the folder, e.g. leftover CSV files, .DS_Store, etc.
  • Edit the package.json and change the Multer version to 1.4.4-lts.1 which is the version that is not affected by CVE-2022-24434

{
"name": "hsm-api",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"start": "nodemon index.js",
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Alvin",
"license": "ISC",
"dependencies": {
"axios": "^0.24.0",
"bluebird": "^3.7.2",
"express": "^4.17.1",
"fast-csv": "^4.3.6",
"mongodb": "^4.2.1",
"multer": "^1.4.4-lts.1",
"nodemon": "^2.0.15"
}
}

  • Edit the Dockerfile to include the step to start the campaign builder and capture the output to the file

FROM node:18-alpine
WORKDIR /usr/app
COPY package.json .
RUN npm install
COPY . .
CMD sh -c "npm start | tee campaign-builder.out 2>&1"

  • Create a .dockerignore to prevent your local modules and debug logs from being copied onto your Docker image and possibly overwriting modules installed within your image

node_modules
npm-debug.log

  • Build your image

$ sudo docker build . -t tehhanlin/campaign-builder

Sending build context to Docker daemon 284.2kB
Step 1/7 : FROM node:18-alpine
---> 16b18c065537
Step 2/7 : WORKDIR /usr/app
---> Using cache
---> a81e9a5e4b53
Step 3/7 : COPY package.json .
---> Using cache
---> 33901db25f88
Step 4/7 : RUN npm install
---> Running in 1a4817b4c2e2

added 142 packages, and audited 143 packages in 11s

14 packages are looking for funding
run `npm fund` for details

found 0 vulnerabilities
npm notice
npm notice New minor version of npm available! 8.15.0 -> 8.16.0
npm notice Changelog: <https://github.com/npm/cli/releases/tag/v8.16.0>
npm notice Run `npm install -g [email protected]` to update!
npm notice
Removing intermediate container 1a4817b4c2e2
---> 169c1e2aa6a2
Step 5/7 : COPY . .
---> 5f8a5883be54
Step 6/7 : EXPOSE 5000
---> Running in 176d55025bc0
Removing intermediate container 176d55025bc0
---> 92f3db1e3f93
Step 7/7 : CMD [ "npm", "start" ]
---> Running in af22afee1f29
Removing intermediate container af22afee1f29
---> b03bef5ff02c
Successfully built b03bef5ff02c
Successfully tagged tehhanlin/campaign-builder:latest

  • Run the image and make sure it’s running properly before pushing it to the Docker Hub

$ sudo docker run -p 5000:5000 -d tehhanlin/campaign-builder
7154cb6fa006c2bea496316881e1166aa90ed34866cb7f0b241327ff12cf63ee


$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
7154cb6fa006 tehhanlin/campaign-builder "docker-entrypoint.s…" 33 seconds ago Up 32 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp zealous_swartz

  • Login to the Docker Hub

$ sudo docker login

$ sudo docker tag tehhanlin/campaign-builder:latest tehhanlin/campaign-builder:latest

  • Push the image

$ sudo docker push tehhanlin/campaign-builder:latest
The push refers to repository [docker.io/tehhanlin/campaign-builder]
afbea12bb3a4: Pushed
5c13f69c024e: Pushed
b0ae6cca8984: Pushed
17bc9e7f5694: Pushed
09b7383bea96: Mounted from library/node
c96589692e22: Mounted from library/node
9bea69db587d: Mounted from library/node
ec34fcc1d526: Mounted from library/node
x86_64: digest: sha256:5d42c8a1e7da0179336f785df444555abc1b738def1d2872f21d5cae6590fa67 size: 1993

  • To pull and run the Docker image from other machine

$ sudo docker pull tehhanlin/campaign-builder
Using default tag: latest
latest: Pulling from tehhanlin/campaign-builder
530afca65e2e: Pull complete
5c829f39f5e8: Pull complete
b9d3bddc94b3: Pull complete
f8fce1b8a0b8: Pull complete
f042f05b6b1f: Pull complete
da4f38f68e99: Pull complete
6f7b5f0af3d6: Pull complete
befa41721e97: Pull complete
Digest: sha256:6d76ca874d5a220314e6ce709b7add7f4ab492adf30c1fada2a729f169bbcaa3
Status: Downloaded newer image for tehhanlin/campaign-builder:latest
docker.io/tehhanlin/campaign-builder:latest

$ sudo docker run -d -p 5000:5000 tehhanlin/campaign-builder

$ sudo docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
d07c4f243aca tehhanlin/campaign-builder "docker-entrypoint.s…" 24 seconds ago Up 23 seconds 0.0.0.0:5000->5000/tcp, :::5000->5000/tcp goofy_knuth

  • To run the image with directory mapping so we can read the log files from the host, use the -v parameter

$ sudo docker run -v $(pwd):/var/log -p 5000:5000 -d tehhanlin/campaign-builder

My Docker page for Campaign Builder – https://hub.docker.com/repository/docker/tehhanlin/campaign-builder

Thank you.

About the Author

Leave a Reply

Your email address will not be published. Required fields are marked *

You may also like these