Skip to content

Commit f492566

Browse files
committed
Nodebeats v2 commit docker container implementation and bug fixes
1 parent 6a4108b commit f492566

35 files changed

+11152
-0
lines changed

.docker/config/redis.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
requirepass redis#password123

.docker/env/app.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
NODE_ENV=development

.docker/env/mongo.env

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
MONGODB_ROOT_USERNAME=dbNodebeatsUserAdmin
2+
MONGODB_ROOT_PASSWORD=nodebeats#UserAdmin
3+
MONGODB_ROOT_ROLE=root
4+
5+
MONGODB_USERNAME=nodebeatsuser
6+
MONGODB_PASSWORD=pwd#user123
7+
MONGODB_DBNAME=prj_nodebeats
8+
MONGODB_ROLE=readWrite

.docker/mongo.development.dockerfile

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
FROM mongo:latest
2+
3+
MAINTAINER Nodebeats([email protected])
4+
5+
ENV MONGO_DATA_DIR=/data/db \
6+
RESTORE_DIR=/data/backups \
7+
MONGO_LOG_DIR=/var/log/mongodb
8+
9+
RUN apt-get update && apt-get install -y cron netcat-traditional netcat-openbsd && \
10+
mkdir -p $MONGO_DATA_DIR && \
11+
mkdir -p $RESTORE_DIR && \
12+
mkdir -p $MONGO_LOG_DIR
13+
14+
WORKDIR $MONGO_DATA_DIR
15+
16+
COPY ./.docker/mongo_scripts /mongo_scripts
17+
COPY ./lib/mongodump $RESTORE_DIR
18+
19+
RUN chmod +rx /mongo_scripts/*.sh && \
20+
touch /.firstrun
21+
22+
EXPOSE 27017
23+
24+
CMD ["/mongo_scripts/run.sh"]

.docker/mongo_scripts/backup_job.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
# Backup MongoDB
3+
4+
ROOT_USER=${MONGODB_ROOT_USERNAME}
5+
ROOT_PASS=${MONGODB_ROOT_PASSWORD}
6+
DB=${MONGODB_DBNAME}
7+
BACKUP_FOLDER=/opt/backup/`date +"%Y_%m_%d__"`$DB
8+
9+
echo "Backing up $DB to $BACKUP_FOLDER"
10+
/usr/bin/mongodump --port 27017 -u $ROOT_USER -p $ROOT_PASS -d $DB --oplog -o $BACKUP_FOLDER
11+

.docker/mongo_scripts/entrypoint.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
set -e
3+
4+
if [ "${1:0:1}" = '-' ]; then
5+
set -- mongod "$@"
6+
fi
7+
8+
if [ "$1" = 'mongod' ]; then
9+
chown -R mongodb /data/db
10+
11+
numa='numactl --interleave=all'
12+
if $numa true &> /dev/null; then
13+
set -- $numa "$@"
14+
fi
15+
16+
exec gosu mongodb "$@"
17+
fi
18+
19+
exec "$@"

.docker/mongo_scripts/first_run.sh

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
# https://github.com/frodenas/docker-mongodb/blob/master/Dockerfile
3+
4+
ROOT_USER=${MONGODB_ROOT_USERNAME}
5+
ROOT_PASS=${MONGODB_ROOT_PASSWORD}
6+
ROOT_DB="admin"
7+
ROOT_ROLE=${MONGODB_ROOT_ROLE}
8+
9+
USER=${MONGODB_USERNAME}
10+
PASS=${MONGODB_PASSWORD}
11+
DB=${MONGODB_DBNAME}
12+
ROLE=${MONGODB_ROLE}
13+
14+
# Start MongoDB service
15+
#/usr/bin/mongod --nojournal &
16+
echo "Starting MongoDB to add users and roles...."
17+
/usr/bin/mongod &
18+
while ! nc -vz localhost 27017; do sleep 1; done
19+
20+
#Set authSchema to 3 so it works with RoboMongo
21+
#echo "Setting authSchema to currentVersion:3"
22+
#mongo $ROOT_DB --eval "db.system.version.save({ '_id' : 'authSchema', 'currentVersion' : 3 });"
23+
24+
# Create Root User if there are values (-z means empty, -n means not empty)
25+
if [[ -n $ROOT_USER ]] && [[ -n $ROOT_PASS ]] && [[ -n $ROOT_ROLE ]]
26+
then
27+
echo "Creating root user: \"$ROOT_USER\"..."
28+
mongo $ROOT_DB --eval "db.createUser({ user: '$ROOT_USER', pwd: '$ROOT_PASS', roles: [ { role: '$ROOT_ROLE', db: '$ROOT_DB' } ] });"
29+
fi
30+
31+
# Create Web User if there are values (-z means empty, -n means not empty)
32+
if [[ -n $USER ]] && [[ -n $PASS ]] && [[ -n $ROLE ]] && [[ -n $DB ]]
33+
then
34+
echo "Creating web user: \"$USER\"..."
35+
mongo $DB --eval "db.createUser({ user: '$USER', pwd: '$PASS', roles: [ {role:'dbOwner',db:'$DB'}, { role: 'dbAdmin', db: '$DB' }, { role: '$ROLE', db: '$DB' }] });"
36+
fi
37+
38+
echo "Added MongoDB users and roles...."
39+
40+
# restore database backup file in the first run
41+
echo "Running restore_db.sh"
42+
/mongo_scripts/restore_db.sh
43+
# Stop MongoDB service
44+
echo "Shutting down MongoDB after adding users/roles...."
45+
/usr/bin/mongod --shutdown
46+
47+
echo "========================================================================"
48+
echo "MongoDB Root User: $ROOT_USER"
49+
echo "MongoDB Root Role: $ROOT_ROLE"
50+
echo "========================================================================"
51+
echo "========================================================================"
52+
echo "MongoDB User: $USER"
53+
echo "MongoDB Database: $DB"
54+
echo "MongoDB Role: $ROLE"
55+
56+
#Override environment vars for passwords since they're only used
57+
#during initialization of MongoDB container
58+
export MONGODB_ROOT_PASSWORD=""
59+
export MONGODB_PASSWORD=""
60+
61+
rm -f /.firstrun

.docker/mongo_scripts/restore_db.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
# Restore MongoDB
3+
4+
MONGODB_USERNAME=${MONGODB_USERNAME}
5+
MONGODB_PASSWORD=${MONGODB_PASSWORD}
6+
DB=${MONGODB_DBNAME}
7+
RESTORE_DIR=/data/backups
8+
9+
echo "Restoring backup file $DB from $RESTORE_DIR"
10+
/usr/bin/mongorestore --port 27017 -u $MONGODB_USERNAME -p $MONGODB_PASSWORD -d $DB $RESTORE_DIR/$DB

.docker/mongo_scripts/run.sh

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#!/bin/bash
2+
# https://github.com/frodenas/docker-mongodb/blob/master/Dockerfile
3+
4+
# Initialize first run
5+
if [[ -e /.firstrun ]]; then
6+
echo "Running entrypoint.sh"
7+
/mongo_scripts/entrypoint.sh
8+
9+
10+
echo "Scheduling backup CRON job for 13:00"
11+
cat <(crontab -l) <(echo "00 13 * * * /mongo_scripts/backup_job.sh") | crontab -
12+
13+
echo "Scheduling backup CRON job for 1:00"
14+
cat <(crontab -l) <(echo "00 01 * * * /mongo_scripts/backup_job.sh") | crontab -
15+
16+
# * * * * * CRON job time to be executed
17+
# - - - - -
18+
# | | | | |
19+
# | | | | ----- Day of week (0 - 7) (Sunday=0 or 7)
20+
# | | | ------- Month (1 - 12)
21+
# | | --------- Day of month (1 - 31)
22+
# | ----------- Hour (0 - 23)
23+
# ------------- Minute (0 - 59)
24+
25+
26+
echo "Running first_run.sh"
27+
/mongo_scripts/first_run.sh
28+
fi
29+
30+
# Start MongoDB
31+
echo "Starting MongoDB..."
32+
/usr/bin/mongod --auth $@
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM node:6.9.1
2+
3+
MAINTAINER Nodebeats([email protected])
4+
5+
LABEL Description="Admin dashboard of Nodebeats, An Open Source Content Management System built using MEAN Framework"
6+
LABEL Vendor="Bitsbeat IT Solution"
7+
LABEL Version="1.0"
8+
9+
ENV PORT=4200 \
10+
CLI_PORT=49153 \
11+
PROJECT_DIR=/var/www/nodebeats/admin
12+
13+
RUN npm install -g typescript && \
14+
npm install -g webpack && \
15+
npm install -g webpack-dev-server && \
16+
npm install -g angular-cli && \
17+
npm install -g mocha && \
18+
mkdir -p $PROJECT_DIR
19+
20+
# Install app dependencies
21+
COPY admin/package.json $PROJECT_DIR/
22+
23+
# Create app directory
24+
WORKDIR $PROJECT_DIR
25+
26+
RUN npm install
27+
28+
# Bundle app sourceuser
29+
COPY ./admin $PROJECT_DIR
30+
31+
EXPOSE $PORT
32+
EXPOSE $CLI_PORT
33+
34+
CMD ["npm", "start"]
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
FROM node:6.9.1
2+
3+
MAINTAINER Nodebeats([email protected])
4+
5+
LABEL Description="Nodebeats, An Open Source Content Management System built using MEAN Framework"
6+
LABEL Vendor="Bitsbeat IT Solution"
7+
LABEL Version="1.0"
8+
9+
ENV PORT=3000 \
10+
PROJECT_DIR=/var/www/nodebeats \
11+
LOG_DIR=/var/log/pm2
12+
13+
# Add our user and group first to make sure their IDs get assigned consistently
14+
RUN npm install -g pm2 && \
15+
npm install -g express && \
16+
npm install -g gulp && \
17+
npm install -g nodemon && \
18+
mkdir -p $LOG_DIR && \
19+
mkdir -p $PROJECT_DIR
20+
21+
# Install app dependencies
22+
COPY package.json npm-shrinkwrap.json $PROJECT_DIR/
23+
24+
# Create app directory
25+
WORKDIR $PROJECT_DIR
26+
27+
RUN npm install
28+
29+
# Bundle app sourceuser
30+
COPY . $PROJECT_DIR
31+
32+
EXPOSE $PORT
33+
34+
CMD ["pm2", "start", "pm2.json", "--watch", "--no-daemon"]

.docker/redis.development.dockerfile

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
FROM redis:latest
2+
3+
MAINTAINER Nodebeats([email protected])
4+
5+
# Change as appropriate for build
6+
7+
COPY ./.docker/config/redis.conf /etc/redis.conf
8+
9+
ENV REDIS_DATA_DIR=/data/cache
10+
RUN mkdir -p $REDIS_DATA_DIR
11+
EXPOSE 6379
12+
13+
CMD ["redis-server", "/etc/redis.conf"]

.docker/redis_scripts/run.sh

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#!/bin/bash
2+
configFile=/etc/redis.conf
3+
4+
if [[ -r $configFile ]] ; then
5+
. "$configFile"
6+
else
7+
echo "configFile not found or not readable."
8+
exit 1
9+
fi
10+
11+
#for testing only:
12+
echo "$name"
13+
echo "$pass"

.dockerignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.git
2+
.gitignore
3+
node_modules
4+
npm-debug.log
5+
.idea
6+
admin/node_modules
7+
admin/npm-debug.log
8+
ChangeLog.md
9+
code_of_conduct.md
10+
CONTRIBUTING.md
11+
LICENSE
12+
README.md
13+
cluster.js
14+
contributors.txt

admin/.angular-cli.json

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
{
2+
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
3+
"project": {
4+
"name": "admin"
5+
},
6+
"apps": [
7+
{
8+
"root": "src",
9+
"outDir": "dist",
10+
"assets": [
11+
"assets",
12+
"favicon.ico"
13+
],
14+
"index": "index.html",
15+
"main": "main.ts",
16+
"polyfills": "polyfills.ts",
17+
"test": "test.ts",
18+
"tsconfig": "tsconfig.app.json",
19+
"testTsconfig": "tsconfig.spec.json",
20+
"prefix": "app",
21+
"styles": [
22+
"../node_modules/bootstrap/dist/css/bootstrap.min.css",
23+
"../node_modules/primeng/resources/themes/omega/theme.css",
24+
"../node_modules/primeng/resources/primeng.min.css",
25+
"assets/font-awesome/css/font-awesome.min.css",
26+
"../node_modules/@angular/material/core/theming/prebuilt/deeppurple-amber.css",
27+
"assets/css/admin.css",
28+
"assets/css/common.css",
29+
"assets/css/custom.css",
30+
"assets/css/animate.css",
31+
"assets/css/responsive-admin.css",
32+
"assets/plugins/jalert/jAlert-v3.css",
33+
"../node_modules/sweetalert/dist/sweetalert.css"
34+
],
35+
"scripts": [
36+
"../node_modules/primeui/primeui-ng-all.min.js",
37+
"../node_modules/tether/dist/js/tether.js",
38+
"../node_modules/bootstrap/dist/js/bootstrap.min.js",
39+
"assets/plugins/Chart.bundle.js",
40+
"assets/inlineScripts",
41+
"assets/plugins/tinymce/tinymce.js",
42+
"assets/plugins/tinymce/themes/modern/theme.js",
43+
"assets/plugins/tinymce/plugins/media/plugin.js",
44+
"assets/plugins/tinymce/plugins/link/plugin.js",
45+
"assets/plugins/tinymce/plugins/paste/plugin.js",
46+
"assets/plugins/tinymce/plugins/table/plugin.js",
47+
"assets/plugins/tinymce/plugins/advlist/plugin.js",
48+
"assets/plugins/tinymce/plugins/autolink/plugin.js",
49+
"assets/plugins/tinymce/plugins/lists/plugin.js",
50+
"assets/plugins/tinymce/plugins/image/plugin.js",
51+
"assets/plugins/tinymce/plugins/charmap/plugin.js",
52+
"assets/plugins/tinymce/plugins/print/plugin.js",
53+
"assets/plugins/tinymce/plugins/preview/plugin.js",
54+
"assets/plugins/tinymce/plugins/anchor/plugin.js",
55+
"assets/plugins/tinymce/plugins/searchreplace/plugin.js",
56+
"assets/plugins/tinymce/plugins/visualblocks/plugin.js",
57+
"assets/plugins/tinymce/plugins/code/plugin.js",
58+
"assets/plugins/tinymce/plugins/fullscreen/plugin.js",
59+
"assets/plugins/tinymce/plugins/insertdatetime/plugin.js",
60+
"assets/plugins/tinymce/plugins/contextmenu/plugin.js",
61+
"../node_modules/cloudinary-jquery/cloudinary-jquery.js",
62+
"assets/plugins/table-sorter.js",
63+
"../node_modules/sweetalert/dist/sweetalert-dev.js"
64+
],
65+
"environmentSource": "environments/environment.ts",
66+
"environments": {
67+
"dev": "environments/environment.ts",
68+
"prod": "environments/environment.prod.ts"
69+
}
70+
}
71+
],
72+
"e2e": {
73+
"protractor": {
74+
"config": "./protractor.conf.js"
75+
}
76+
},
77+
"lint": [
78+
{
79+
"project": "src/tsconfig.app.json"
80+
},
81+
{
82+
"project": "src/tsconfig.spec.json"
83+
},
84+
{
85+
"project": "e2e/tsconfig.e2e.json"
86+
}
87+
],
88+
"test": {
89+
"karma": {
90+
"config": "./karma.conf.js"
91+
}
92+
},
93+
"defaults": {
94+
"styleExt": "css",
95+
"component": {}
96+
}
97+
}

0 commit comments

Comments
 (0)