Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into mongo4
Browse files Browse the repository at this point in the history
  • Loading branch information
kabalin committed Nov 6, 2021
2 parents 1e4f42d + a04dc86 commit 1ff41f6
Show file tree
Hide file tree
Showing 17 changed files with 43 additions and 44 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
12 changes: 0 additions & 12 deletions Dockerfile

This file was deleted.

2 changes: 1 addition & 1 deletion Gruntfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ module.exports = function (grunt) {
command: () => {
const error = 'Version defined in Dockerfile is not matching package version of node.';
const pkgVersion = grunt.template.process('<%= pkg.engines.node %>');
const dockerParse = "sed -n -e '/^ARG NODE_TAG/ s/.*=//p' Dockerfile";
const dockerParse = "sed -n -e '/^ARG NODE_TAG/ s/.*=//p' ./docker/Dockerfile";

return 'if [ "$(' + dockerParse + ')" != "' + pkgVersion + '" ]; then echo "' + error + '"; exit 1; fi;';
},
Expand Down
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ We welcome any keen developer in helping us build the better PastVu. You can ins
You need to have [docker](https://docs.docker.com/engine/install/) and [docker-compose](https://docs.docker.com/compose/install/) installed.

```bash
# Start Mongo container in background
docker-compose up -d mongo
# Import Pastvu database
docker-compose exec mongo initdb
# Install node modules
docker-compose run app npm install
# Start the application
Expand Down
6 changes: 6 additions & 0 deletions bin/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ if (require.main !== module) { // If run.js is required by another module (for e
describe: 'Log config',
'default': true,
})
.options('primary', {
boolean: true,
describe: 'Run as primary instance',
})
.argv;

const config = require('../config');
Expand All @@ -53,6 +57,8 @@ if (require.main !== module) { // If run.js is required by another module (for e

const appName = path.parse(argv.script).name;
const logger = log4js.getLogger(appName);
if (appName === "notifier") config.notifier = true;
config.primary = !!argv.primary; // If not true, the instance will run as a recplica

// Handling uncaught exceptions
process.on('uncaughtException', err => {
Expand Down
3 changes: 0 additions & 3 deletions config/default.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@ module.exports = {
env: 'development', // Enviroment: development, testing, production
locales: ['en', 'ru'], // List of supported locales. First one is the default locale, if user transferred nothing
lang: 'ru', // Language: ru, en
notifier: false, // If true, send periodical emails to users
primary: false, // If not true, the instance will run as a recplica
admin: {
email: '',
},
Expand Down Expand Up @@ -49,7 +47,6 @@ module.exports = {
servePublic: true, // Tell app.js serve out its public folder (js, css, etc)
serveStore: true, // Tell app.js serve out store public folder

logPath: '', // Folder for logs. Setting that property will enable log to files in logPath (relative to project dir). By default it is off
logLongDuration: ms('2s'),
serveLog: false, // Tell app.js serve out its logs folder (path: "logPath") at /nodelog
serveLogAuth: {
Expand Down
2 changes: 0 additions & 2 deletions config/local.config.js.docker-example
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ module.exports = function (config, appRequire) {

_.merge(config, {
// Send periodical emails to users depending on environment variable
notifier: true,
primary: true,
client: {
hostname: 'localhost',
},
Expand Down
2 changes: 0 additions & 2 deletions config/local.config.js.example
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ module.exports = function (config, appRequire) {
const _ = appRequire('lodash');

_.merge(config, {
notifier: true, // Send periodical emails to user
primary: true,
client: {
hostname: 'pastvu.local',
},
Expand Down
5 changes: 3 additions & 2 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: '3.8'

x-defaults: &app-image
build: .
build: ./docker
image: pastvu_node
environment:
- NODE_ENV=development
Expand All @@ -11,6 +11,7 @@ services:
image: mongo:4.4
volumes:
- mongo:/data/db
- ./docker/dev-initdb.sh:/usr/local/bin/initdb
expose:
- "27017"
ports:
Expand All @@ -35,7 +36,7 @@ services:
volumes:
- .:/code
- store:/store
command: run app
command: run app --primary

worker:
<< : *app-image
Expand Down
11 changes: 11 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
ARG NODE_TAG=16.10.0
FROM node:$NODE_TAG
RUN apt-get update && apt-get install -y \
graphicsmagick \
webp \
&& rm -rf /var/lib/apt/lists/*
COPY ./imagick-policy.xml /etc/ImageMagick-6/policy.xml
WORKDIR /code
COPY ./dev-entrypoint.sh /usr/local/bin/
USER node
ENTRYPOINT ["dev-entrypoint.sh"]
6 changes: 2 additions & 4 deletions docker/backend.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,9 @@ COPY . .
RUN npm run build

FROM base
ENV LANG ru
ENV MODULE app
ENV NODE_ENV production
ENV CONFIG /config.js
COPY --from=builder /appBuild/ .
COPY ./docker/docker-healthcheck.sh .
RUN npm install --production
RUN mkdir /store && chown node:node /store
USER node
CMD ["bin/run"]
1 change: 0 additions & 1 deletion docker/dev-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ CONFIG="./config/local.config.js"
# 'run MODULE [options]' special command to run script directly with node, so that system signals are relayed to the process.
if [ "$1" = 'run' -a -f "./${2}.js" ]; then
MODULE=$2
wait-for-it -t 0 mongo:27017
shift 2
exec node ./bin/run.js --script "./${MODULE}.js" "$@"
fi
Expand Down
15 changes: 12 additions & 3 deletions docker/dev-initdb.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
#!/bin/sh
curl -s -o /tmp/pastvu.gz https://varlamov.me/pastvu/github/pastvu.gz
mongorestore --gzip --db pastvu --archive=/tmp/pastvu.gz
rm /tmp/pastvu.gz

# This test database restore script is designed to be bind mounted inside mongo
# container at /usr/local/bin/initdb location, then called on started container as
# 'docker-compose exec mongo initdb'.
if ! command -v curl; then
echo "Installing curl"
apt update -qq && apt-get install -yqq curl
fi
echo "Downloading db dump..."
curl --progress-bar -o /tmp/pastvu.gz https://varlamov.me/pastvu/github/pastvu.gz
mongorestore --drop --gzip --db pastvu --archive=/tmp/pastvu.gz
rm /tmp/pastvu.gz
3 changes: 0 additions & 3 deletions docker/dev-mongo.Dockerfile

This file was deleted.

8 changes: 0 additions & 8 deletions docker/docker-healthcheck.sh

This file was deleted.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "pastvu",
"version": "1.4.4",
"version": "1.4.7",
"description": "Retrospective topography of media content",
"homepage": "https://github.com/pastvu/pastvu",
"keywords": [
Expand Down

0 comments on commit 1ff41f6

Please sign in to comment.