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

Jetmon: Dockerize app #8

Merged
merged 8 commits into from
Nov 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 4 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@

build/
node_modules/
node_modules/
.DS_Store
lib/jetmon.node
.env
3 changes: 3 additions & 0 deletions config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
config.json
db-config.conf

14 changes: 4 additions & 10 deletions config/config.json → config/config-sample.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"BUCKET_NO_MIN" : 0,
"BUCKET_NO_MAX" : 512,
"BATCH_SIZE" : 32,
"AUTH_TOKEN" : "<some token auth string>",
"AUTH_TOKEN" : "<AUTH_TOKEN>",

"VERIFLIER_BATCH_SIZE" : 200,
"SQL_UPDATE_BATCH" : 1,
Expand All @@ -24,15 +24,9 @@
"VERIFIERS": [
{
"name" : "Veriflier 1",
"host" : "<ip / host name>",
"port" : "7801",
"auth_token" : "<some token auth string>"
},
{
"name" : "Veriflier 2",
"host" : "<ip / host name>",
"port" : "7801",
"auth_token" : "<some token auth string>"
"host" : "veriflier",
"port" : "<VERIFLIER_PORT>",
"auth_token" : "<VERIFLIER_AUTH_TOKEN>"
}
]
}
6 changes: 6 additions & 0 deletions config/db-config-sample.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
$db_servers = array(
'misc' => array(
array( 'jetmon', 0, 1, 'mysqldb:<MYSQLDB_PORT>', 'mysqldb:<MYSQLDB_PORT>', '<MYSQLDB_DATABASE>', '<MYSQLDB_USER>', '<MYSQLDB_ROOT_PASSWORD>', null, null, 30 ),
array( 'jetmon', 1, 0, 'mysqldb:<MYSQLDB_PORT>', 'mysqldb:<MYSQLDB_PORT>', '<MYSQLDB_DATABASE>', '<MYSQLDB_USER>', '<MYSQLDB_ROOT_PASSWORD>', null, null, 30 ),
)
);
13 changes: 0 additions & 13 deletions config/db-config.conf

This file was deleted.

5 changes: 5 additions & 0 deletions docker/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@

build/
node_modules/
.DS_Store
.env
14 changes: 14 additions & 0 deletions docker/.env-sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
MYSQLDB_USER=root
MYSQLDB_ROOT_PASSWORD=123456
MYSQLDB_DATABASE=jetmon_db
MYSQLDB_LOCAL_PORT=3307
MYSQLDB_DOCKER_PORT=3306

JETMON_LOCAL_PORT=7800
JETMON_DOCKER_PORT=7800

WPCOM_JETMON_AUTH_TOKEN=change_me

VERIFLIER_LOCAL_PORT=7801
VERIFLIER_DOCKER_PORT=7801
VERIFLIER_AUTH_TOKEN=veriflier_1_auth_token
16 changes: 16 additions & 0 deletions docker/Dockerfile_jetmon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:16

WORKDIR /jetmon

# RUN apk add --no-cache python3 make g++

RUN npm config set unsafe-perm true
RUN npm install -g node-gyp

# Get the dependencies loaded first - this makes rebuilds faster
COPY package.json .
RUN npm install

COPY . .

CMD [ "bash", "docker/run-jetmon.sh" ]
30 changes: 30 additions & 0 deletions docker/Dockerfile_veriflier
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
FROM ubuntu:18.04
# Sourced from https://github.com/MatiMoreyra/qt5-docker/blob/master/Dockerfile

# Install dependencies.
RUN apt-get update && DEBIAN_FRONTEND=noninteractive apt-get install -y \
git \
build-essential \
cmake \
qt5-default \
libfontconfig1 \
mesa-common-dev \
libglu1-mesa-dev \
libgtest-dev

# Build GTest
RUN cd /usr/src/gtest/ && \
cmake -DBUILD_SHARED_LIBS=ON && \
make && \
cp -a include/gtest /usr/include && \
cp -a libgtest_main.so libgtest.so /usr/lib/

# Cleanup
RUN rm -rf /var/lib/apt/lists/*


WORKDIR /opt

COPY . .

CMD [ "bash", "docker/run-veriflier.sh" ]
54 changes: 54 additions & 0 deletions docker/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
version: '3.8'

services:
mysqldb:
image: mysql:5.7
restart: unless-stopped
env_file:
- .env
environment:
- MYSQL_ROOT_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- MYSQL_DATABASE=$MYSQLDB_DATABASE
ports:
- $MYSQLDB_LOCAL_PORT:$MYSQLDB_DOCKER_PORT
volumes:
- db:/var/lib/mysql
jetmon:
hostname: docker.jetmon.dev.com
build:
context: ../
dockerfile: docker/Dockerfile_jetmon
env_file:
- .env
volumes:
- ../:/jetmon
# Don't sync the node_modules directory back to the client.
- "/jetmon/node_modules"
environment:
- DB_HOST=mysqldb
- DB_USER=$MYSQLDB_USER
- DB_PASSWORD=$MYSQLDB_ROOT_PASSWORD
- DB_NAME=$MYSQLDB_DATABASE
- DB_PORT=$MYSQLDB_DOCKER_PORT
- VERIFLIER_AUTH_TOKEN=$VERIFLIER_AUTH_TOKEN
- VERIFLIER_PORT=$VERIFLIER_DOCKER_PORT
- WPCOM_JETMON_AUTH_TOKEN=$WPCOM_JETMON_AUTH_TOKEN
ports:
- $JETMON_LOCAL_PORT:$JETMON_DOCKER_PORT
depends_on:
- mysqldb
veriflier:
build:
context: ../
dockerfile: docker/Dockerfile_veriflier
volumes:
- ../:/opt
ports:
- $VERIFLIER_LOCAL_PORT:$VERIFLIER_DOCKER_PORT
environment:
- VERIFLIER_AUTH_TOKEN=$VERIFLIER_AUTH_TOKEN
- VERIFLIER_PORT=$VERIFLIER_DOCKER_PORT
- JETMON_PORT=$JETMON_DOCKER_PORT

volumes:
db:
18 changes: 18 additions & 0 deletions docker/run-jetmon.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env bash
cd /jetmon

mkdir -p logs
touch logs/jetmon.log logs/status-change.log

mkdir -p stats
touch stats/sitespersec stats/sitesqueue stats/totals

mkdir -p certs
if [ ! -f certs/jetmon.key ] && [ ! -f certs/jetmon.crt ]; then
openssl req -newkey rsa:2048 -nodes -keyout certs/jetmon.key -x509 -days 365 -out certs/jetmon.crt -subj "/C=US/ST=California/L=San Francisco/O=Automattic Inc./CN=jetmon"
fi

sed -e "s/<AUTH_TOKEN>/${WPCOM_JETMON_AUTH_TOKEN}/g" -e "s/<VERIFLIER_PORT>/${VERIFLIER_PORT}/g" -e "s/<VERIFLIER_AUTH_TOKEN>/${VERIFLIER_AUTH_TOKEN}/g" config/config-sample.json > config/config.json
sed -e "s/<MYSQLDB_USER>/${MYSQLDB_USER}/g" -e "s/<MYSQLDB_ROOT_PASSWORD>/${MYSQLDB_ROOT_PASSWORD}/g" -e "s/<MYSQLDB_PORT>/${MYSQLDB_DOCKER_PORT}/g" -e "s/<MYSQLDB_DATABASE>/${MYSQLDB_DATABASE}/g" config/db-config-sample.conf > config/db-config.conf

exec npm run rebuild-run
15 changes: 15 additions & 0 deletions docker/run-veriflier.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

cd /opt/veriflier

qmake
make

mkdir -p certs
if [ ! -f certs/veriflier.key ] && [ ! -f certs/veriflier.crt ]; then
openssl req -newkey rsa:2048 -nodes -keyout certs/veriflier.key -x509 -days 365 -out certs/veriflier.crt -subj "/C=US/ST=California/L=San Francisco/O=Automattic Inc./CN=jetmon"
fi

sed -e "s/<JETMON_PORT>/${JETMON_PORT}/g" -e "s/<VERIFLIER_PORT>/${VERIFLIER_PORT}/g" -e "s/<VERIFLIER_AUTH_TOKEN>/${VERIFLIER_AUTH_TOKEN}/g" config/veriflier-sample.json > config/veriflier.json

exec ./veriflier start
4 changes: 4 additions & 0 deletions logs/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
12 changes: 12 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"name": "jetmon",
"version": "0.0.1",
"description": "Parallel HTTP health monitoring using HEAD requests for large scale website monitoring.",
"scripts": {
"rebuild-run": "node-gyp rebuild && cp build/Release/jetmon.node lib && node lib/jetmon.js"
},
"dependencies": {
"log4js": "0.6.38",
"mysql": "2.11.1"
}
}
4 changes: 4 additions & 0 deletions stats/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Ignore everything in this directory
*
# Except this file
!.gitignore
6 changes: 6 additions & 0 deletions veriflier/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
*.o
*.cpp
*.h
.qmake.stash
Makefile
veriflier
2 changes: 2 additions & 0 deletions veriflier/config/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
veriflier.json

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"veriflier_name" : "Veriflier 1",
"auth_token" : "<some token auth string>",
"auth_token" : "<VERIFLIER_AUTH_TOKEN>",

"thread_pool_max" : 4,
"max_pending_conns" : 256,
Expand All @@ -11,8 +11,8 @@
"net_comms_timeout" : 30000,
"debug" : true,

"listen_port" : 7801,
"jetmon_server_port" : 7800,
"listen_port" : "<VERIFLIER_PORT>",
"jetmon_server_port" : "<JETMON_PORT>",

"privatekey_file" : "./certs/veriflier.key",
"privatecert_file" : "./certs/veriflier.crt",
Expand Down