From fb9a7a4e228c3dd0e6157d258151c0cd8b96998d Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 3 Oct 2018 17:27:31 +0300 Subject: [PATCH 01/19] move config to folder --- .gitignore | 2 +- Dockerfile => Dockerfile_analytics | 0 Dockerfile_server | 29 +++++++++++++++++++ .../config.example.json | 0 4 files changed, 30 insertions(+), 1 deletion(-) rename Dockerfile => Dockerfile_analytics (100%) create mode 100644 Dockerfile_server rename config.example.json => config/config.example.json (100%) diff --git a/.gitignore b/.gitignore index b6debd5..bdafef7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ data dist -config.json +config/config.json node_modules/ diff --git a/Dockerfile b/Dockerfile_analytics similarity index 100% rename from Dockerfile rename to Dockerfile_analytics diff --git a/Dockerfile_server b/Dockerfile_server new file mode 100644 index 0000000..44cd632 --- /dev/null +++ b/Dockerfile_server @@ -0,0 +1,29 @@ +FROM alpine:3.8 + +EXPOSE 8000 + +VOLUME [ "/var/www/data" ] + +COPY . /var/www + +WORKDIR /var/www/analytics + +RUN pip install -r requirements.txt + +RUN apt-get update && apt-get install -y \ + apt-utils \ + gnupg \ + curl \ + python \ + make \ + g++ \ + git +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - + +RUN apt-get update && apt-get install -y nodejs + +WORKDIR /var/www/server + +RUN npm install && npm run build + +CMD ["npm", "start"] diff --git a/config.example.json b/config/config.example.json similarity index 100% rename from config.example.json rename to config/config.example.json From 3c69271418595babecf2bdf115f924131808f191 Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 3 Oct 2018 17:38:27 +0300 Subject: [PATCH 02/19] fix docker files --- Dockerfile_analytics | 28 +++++++++------------------- Dockerfile_server | 30 ++++++++++++------------------ 2 files changed, 21 insertions(+), 37 deletions(-) diff --git a/Dockerfile_analytics b/Dockerfile_analytics index 4bf865f..4d66ca6 100644 --- a/Dockerfile_analytics +++ b/Dockerfile_analytics @@ -4,26 +4,16 @@ EXPOSE 8000 VOLUME [ "/var/www/data" ] -COPY . /var/www +COPY analytics config /var/www WORKDIR /var/www/analytics -RUN pip install -r requirements.txt +RUN pip install -r requirements.txt && + apt-get update && apt-get install -y \ + gnupg \ + curl \ + make \ + g++ \ + git -RUN apt-get update && apt-get install -y \ - apt-utils \ - gnupg \ - curl \ - python \ - make \ - g++ \ - git -RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - - -RUN apt-get update && apt-get install -y nodejs - -WORKDIR /var/www/server - -RUN npm install && npm run build - -CMD ["npm", "start"] +CMD ["python", "server.py"] diff --git a/Dockerfile_server b/Dockerfile_server index 44cd632..24024c4 100644 --- a/Dockerfile_server +++ b/Dockerfile_server @@ -4,26 +4,20 @@ EXPOSE 8000 VOLUME [ "/var/www/data" ] -COPY . /var/www - -WORKDIR /var/www/analytics - -RUN pip install -r requirements.txt - -RUN apt-get update && apt-get install -y \ - apt-utils \ - gnupg \ - curl \ - python \ - make \ - g++ \ - git -RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - - -RUN apt-get update && apt-get install -y nodejs +COPY server config /var/www WORKDIR /var/www/server -RUN npm install && npm run build +#RUN apt-get update && apt-get install -y \ +# gnupg \ +# curl \ +# make \ +# g++ + +RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && + apt-get update && + apt-get install -y nodejs && + npm install && + npm run build CMD ["npm", "start"] From 15fd7a2b38de7c17856ca49edaf3ef6743c3e5aa Mon Sep 17 00:00:00 2001 From: amper43 Date: Thu, 4 Oct 2018 21:41:14 +0300 Subject: [PATCH 03/19] WIP --- Dockerfile_analytics | 6 ++-- Dockerfile_server | 28 +++++++++---------- Makefile | 9 ++++++ ...config.example.json => config.example.json | 0 docker-compose.yml | 23 +++++++++++++++ server/src/services/analytics_service.ts | 2 +- 6 files changed, 50 insertions(+), 18 deletions(-) create mode 100644 Makefile rename config/config.example.json => config.example.json (100%) create mode 100644 docker-compose.yml diff --git a/Dockerfile_analytics b/Dockerfile_analytics index 4d66ca6..f11ef38 100644 --- a/Dockerfile_analytics +++ b/Dockerfile_analytics @@ -4,12 +4,12 @@ EXPOSE 8000 VOLUME [ "/var/www/data" ] -COPY analytics config /var/www +COPY analytics /var/www WORKDIR /var/www/analytics -RUN pip install -r requirements.txt && - apt-get update && apt-get install -y \ +RUN pip install -r requirements.txt \ + && apt-get update && apt-get install -y \ gnupg \ curl \ make \ diff --git a/Dockerfile_server b/Dockerfile_server index 24024c4..771166e 100644 --- a/Dockerfile_server +++ b/Dockerfile_server @@ -1,23 +1,23 @@ -FROM alpine:3.8 - -EXPOSE 8000 +FROM python:3.6.6 VOLUME [ "/var/www/data" ] -COPY server config /var/www +COPY server /var/www/ WORKDIR /var/www/server -#RUN apt-get update && apt-get install -y \ -# gnupg \ -# curl \ -# make \ -# g++ +RUN apt-get install curl \ + bash \ + gnupg \ + curl \ + make \ + g++ \ + && curl -sL https://deb.nodesource.com/setup_8.x | bash - \ + && apt-get update \ + && apt-get install nodejs \ + && npm install \ + && npm run build -RUN curl -sL https://deb.nodesource.com/setup_8.x | bash - && - apt-get update && - apt-get install -y nodejs && - npm install && - npm run build +ENV INSIDE_DOCKER true CMD ["npm", "start"] diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..ab71d33 --- /dev/null +++ b/Makefile @@ -0,0 +1,9 @@ +.PHONY: server analytics + +server: + docker build . -f Dockerfile_server + +analytics: + docker build . -f Dockerfile_analytics + +all: server analytics diff --git a/config/config.example.json b/config.example.json similarity index 100% rename from config/config.example.json rename to config.example.json diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..b342253 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,23 @@ +version: '3' +services: + server: + build: + dockerfile: Dockerfile_server + volumes: + - "/var/www/data" + ports: + - data-volume:"8000:8000" + privileged: true + ipc: host + analytics: + build: + dockerfile: Dockerfile_analytics + volumes: + - data-volume:"/var/www/data" + ports: + - "8002:8002" + privileged: true + ipc: host + +volumes: + data-volume: diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 4c7ab22..c6097c9 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -67,7 +67,7 @@ export class AnalyticsService { private async _init() { this._requester = zmq.socket('pair'); - let productionMode = process.env.NODE_ENV !== 'development'; + let productionMode = process.env.NODE_ENV !== 'development' && process.env.INSIDE_DOCKER !== 'true'; this._zmqConnectionString = `tcp://127.0.0.1:${config.ZMQ_DEV_PORT}`; // debug mode if(productionMode) { From fb53633fed132d52a9af9e20c3505db14c0b4d85 Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 5 Oct 2018 00:01:41 +0300 Subject: [PATCH 04/19] fix uncommited --- docker-compose.yml | 7 +++++++ server/src/services/analytics_service.ts | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index b342253..9da7a3e 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -9,6 +9,10 @@ services: - data-volume:"8000:8000" privileged: true ipc: host + deploy: + restart_policy: + condition: on-failure + analytics: build: dockerfile: Dockerfile_analytics @@ -18,6 +22,9 @@ services: - "8002:8002" privileged: true ipc: host + deploy: + restart_policy: + condition: on-failure volumes: data-volume: diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index c6097c9..94413b2 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -165,7 +165,7 @@ export class AnalyticsService { private async _onAnalyticsDown() { console.log('Analytics is down'); - if(process.env.NODE_ENV !== 'development') { + if(process.env.NODE_ENV !== 'development' && process.env.INSIDE_DOCKER !== 'true') { await AnalyticsService._runAnalyticsProcess(this._zmqConnectionString); } } From 94aa2349b85021acfc3c42280e4fb1757b3c4cce Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 5 Oct 2018 04:44:01 +0300 Subject: [PATCH 05/19] add new dockerfiles --- analytics/.dockerignore | 3 +++ analytics/Dockerfile | 18 ++++++++++++++++++ server/.dockerignore | 3 +++ server/Dockerfile | 25 +++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 analytics/.dockerignore create mode 100644 analytics/Dockerfile create mode 100644 server/.dockerignore create mode 100644 server/Dockerfile diff --git a/analytics/.dockerignore b/analytics/.dockerignore new file mode 100644 index 0000000..4a0e90e --- /dev/null +++ b/analytics/.dockerignore @@ -0,0 +1,3 @@ +.git +node_modules +npm-debug diff --git a/analytics/Dockerfile b/analytics/Dockerfile new file mode 100644 index 0000000..79a71ec --- /dev/null +++ b/analytics/Dockerfile @@ -0,0 +1,18 @@ +FROM python:3.6.6 + +VOLUME [ "/var/www/data" ] + +COPY analytics/ /var/www/analytics/ + +WORKDIR /var/www/analytics + +RUN pip install -r requirements.txt \ + && apt-get update && apt-get install -y \ + apt-utils \ + gnupg \ + curl \ + make \ + g++ \ + git + +CMD ["python", "server.py"] diff --git a/server/.dockerignore b/server/.dockerignore new file mode 100644 index 0000000..4a0e90e --- /dev/null +++ b/server/.dockerignore @@ -0,0 +1,3 @@ +.git +node_modules +npm-debug diff --git a/server/Dockerfile b/server/Dockerfile new file mode 100644 index 0000000..d7702ae --- /dev/null +++ b/server/Dockerfile @@ -0,0 +1,25 @@ +#base image +FROM node:carbon AS base + +#dependencies +FROM base AS dependencies +WORKDIR /var/www/server +COPY package*.json ./ +RUN npm install + +#build +FROM dependencies AS build +COPY . /var/www/server +WORKDIR /var/www/server +RUN npm run build + +#release +FROM node:8.9-alpine AS release +WORKDIR /var/www/server +COPY --from=dependencies /var/www/server/package.json ./ +RUN npm install +COPY --from=build /var/www/server ./ + +ENV INSIDE_DOCKER true +VOLUME [ "/var/www/data" ] +CMD ["npm", "start"] From 172a17bf697910ae9b0c5b52b1ef3f5fb6783e73 Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 5 Oct 2018 04:44:56 +0300 Subject: [PATCH 06/19] remove old dockerfiles --- Dockerfile_analytics | 19 ------------------- Dockerfile_server | 23 ----------------------- 2 files changed, 42 deletions(-) delete mode 100644 Dockerfile_analytics delete mode 100644 Dockerfile_server diff --git a/Dockerfile_analytics b/Dockerfile_analytics deleted file mode 100644 index f11ef38..0000000 --- a/Dockerfile_analytics +++ /dev/null @@ -1,19 +0,0 @@ -FROM python:3.6.6 - -EXPOSE 8000 - -VOLUME [ "/var/www/data" ] - -COPY analytics /var/www - -WORKDIR /var/www/analytics - -RUN pip install -r requirements.txt \ - && apt-get update && apt-get install -y \ - gnupg \ - curl \ - make \ - g++ \ - git - -CMD ["python", "server.py"] diff --git a/Dockerfile_server b/Dockerfile_server deleted file mode 100644 index 771166e..0000000 --- a/Dockerfile_server +++ /dev/null @@ -1,23 +0,0 @@ -FROM python:3.6.6 - -VOLUME [ "/var/www/data" ] - -COPY server /var/www/ - -WORKDIR /var/www/server - -RUN apt-get install curl \ - bash \ - gnupg \ - curl \ - make \ - g++ \ - && curl -sL https://deb.nodesource.com/setup_8.x | bash - \ - && apt-get update \ - && apt-get install nodejs \ - && npm install \ - && npm run build - -ENV INSIDE_DOCKER true - -CMD ["npm", "start"] From e54436d8d0acc11ed2a64ac650fdc2f44d672118 Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 5 Oct 2018 04:45:44 +0300 Subject: [PATCH 07/19] move makefile to new layout --- Makefile | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index ab71d33..5181763 100644 --- a/Makefile +++ b/Makefile @@ -1,9 +1,12 @@ -.PHONY: server analytics +.PHONY: server analytics compose + +all: server analytics server: - docker build . -f Dockerfile_server + docker build server -t hastic-server analytics: - docker build . -f Dockerfile_analytics + docker build analytics -t hastic-analytics -all: server analytics +compose: + docker-compose up From b85cabe2bcb094218e579ce9f18638040c2202c7 Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 5 Oct 2018 04:58:22 +0300 Subject: [PATCH 08/19] fix --- server/Dockerfile | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/server/Dockerfile b/server/Dockerfile index d7702ae..2aa9945 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,25 +1,22 @@ -#base image -FROM node:carbon AS base +FROM python:3.6.6 -#dependencies -FROM base AS dependencies -WORKDIR /var/www/server -COPY package*.json ./ -RUN npm install +VOLUME [ "/var/www/data" ] -#build -FROM dependencies AS build -COPY . /var/www/server -WORKDIR /var/www/server -RUN npm run build +COPY server /var/www/ -#release -FROM node:8.9-alpine AS release WORKDIR /var/www/server -COPY --from=dependencies /var/www/server/package.json ./ -RUN npm install -COPY --from=build /var/www/server ./ + +RUN apt-get install curl \ + bash \ + gnupg \ + make \ + g++ \ + && curl -sL https://deb.nodesource.com/setup_8.x | bash - \ + && apt-get update \ + && apt-get install nodejs \ + && npm install \ + && npm run build ENV INSIDE_DOCKER true -VOLUME [ "/var/www/data" ] + CMD ["npm", "start"] From d01ee7bf8b912b9ae97b699f11b0873019e6020d Mon Sep 17 00:00:00 2001 From: amper43 Date: Mon, 8 Oct 2018 13:41:20 +0300 Subject: [PATCH 09/19] test --- docker-compose.yml | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 9da7a3e..6341237 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,30 +1,28 @@ -version: '3' +version: '2' services: server: - build: - dockerfile: Dockerfile_server + build: server volumes: - "/var/www/data" ports: - data-volume:"8000:8000" privileged: true ipc: host - deploy: - restart_policy: - condition: on-failure + # deploy: + # restart_policy: + # condition: on-failure analytics: - build: - dockerfile: Dockerfile_analytics + build: analytics volumes: - data-volume:"/var/www/data" ports: - "8002:8002" privileged: true ipc: host - deploy: - restart_policy: - condition: on-failure + # deploy: + # restart_policy: + # condition: on-failure volumes: data-volume: From f72cc35589f054f76e5f7a3dfa68a134415324d6 Mon Sep 17 00:00:00 2001 From: amper43 Date: Tue, 9 Oct 2018 13:01:04 +0300 Subject: [PATCH 10/19] fix ZMQ connection string --- analytics/.dockerignore | 4 +++- analytics/Dockerfile | 2 +- docker-compose.yml | 27 ++++++++++-------------- server/.dockerignore | 1 + server/Dockerfile | 2 +- server/src/config.ts | 1 + server/src/services/analytics_service.ts | 2 +- 7 files changed, 19 insertions(+), 20 deletions(-) diff --git a/analytics/.dockerignore b/analytics/.dockerignore index 4a0e90e..0a87603 100644 --- a/analytics/.dockerignore +++ b/analytics/.dockerignore @@ -1,3 +1,5 @@ .git -node_modules npm-debug +node_modules +__pychache__ +.vscode diff --git a/analytics/Dockerfile b/analytics/Dockerfile index 79a71ec..c1e80eb 100644 --- a/analytics/Dockerfile +++ b/analytics/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.6.6 VOLUME [ "/var/www/data" ] -COPY analytics/ /var/www/analytics/ +COPY . /var/www/analytics/ WORKDIR /var/www/analytics diff --git a/docker-compose.yml b/docker-compose.yml index 6341237..89d9906 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,28 +1,23 @@ version: '2' services: server: - build: server + image: hastic-server + #build: server + environment: + HASTIC_API_KEY: "eyJrIjoiNzhiYjIyTGZDMjY4M3lnYTNwWHo3WFVaNnVDSm9qakkiLCJuIjoiaGFzIiwiaWQiOjF9" + ZMQ_HOST: analytics volumes: - - "/var/www/data" + - data-volume:/var/www/data ports: - - data-volume:"8000:8000" + - 8000:8000 privileged: true - ipc: host - # deploy: - # restart_policy: - # condition: on-failure - + analytics: - build: analytics + image: hastic-analytics + #build: analytics volumes: - - data-volume:"/var/www/data" - ports: - - "8002:8002" + - data-volume:/var/www/data privileged: true - ipc: host - # deploy: - # restart_policy: - # condition: on-failure volumes: data-volume: diff --git a/server/.dockerignore b/server/.dockerignore index 4a0e90e..cf23c6e 100644 --- a/server/.dockerignore +++ b/server/.dockerignore @@ -1,3 +1,4 @@ .git node_modules npm-debug +.vscode diff --git a/server/Dockerfile b/server/Dockerfile index 2aa9945..6db9cae 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -2,7 +2,7 @@ FROM python:3.6.6 VOLUME [ "/var/www/data" ] -COPY server /var/www/ +COPY . /var/www/ WORKDIR /var/www/server diff --git a/server/src/config.ts b/server/src/config.ts index 46349b9..ced4f12 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -20,6 +20,7 @@ export const HASTIC_PORT = getConfigField('HASTIC_PORT', '8000'); export const ZMQ_CONNECTION_STRING = getConfigField('ZMQ_CONNECTION_STRING', null); export const ZMQ_IPC_PATH = getConfigField('ZMQ_IPC_PATH', path.join(os.tmpdir(), 'hastic')); export const ZMQ_DEV_PORT = getConfigField('ZMQ_DEV_PORT', '8002'); +export const ZMQ_HOST = getConfigField('ZMQ_HOST', '127.0.0.1'); export const HASTIC_API_KEY = getConfigField('HASTIC_API_KEY'); export const ANLYTICS_PING_INTERVAL = 500; // ms diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 94413b2..5592a20 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -69,7 +69,7 @@ export class AnalyticsService { this._requester = zmq.socket('pair'); let productionMode = process.env.NODE_ENV !== 'development' && process.env.INSIDE_DOCKER !== 'true'; - this._zmqConnectionString = `tcp://127.0.0.1:${config.ZMQ_DEV_PORT}`; // debug mode + this._zmqConnectionString = `tcp://${config.ZMQ_HOST}:${config.ZMQ_DEV_PORT}`; // debug mode if(productionMode) { this._zmqConnectionString = config.ZMQ_CONNECTION_STRING; if(this._zmqConnectionString === null) { From 3042ddc81b886cd90c0aea498fa721f0df356abe Mon Sep 17 00:00:00 2001 From: amper43 Date: Tue, 9 Oct 2018 17:12:56 +0300 Subject: [PATCH 11/19] fix compose --- analytics/config.py | 2 ++ docker-compose.yml | 13 +++++-------- server/src/services/analytics_service.ts | 12 +++++++++--- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/analytics/config.py b/analytics/config.py index c4b2b2e..b867a3b 100644 --- a/analytics/config.py +++ b/analytics/config.py @@ -1,3 +1,5 @@ + + import os import json diff --git a/docker-compose.yml b/docker-compose.yml index 89d9906..d757602 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -2,22 +2,19 @@ version: '2' services: server: image: hastic-server - #build: server + build: server environment: HASTIC_API_KEY: "eyJrIjoiNzhiYjIyTGZDMjY4M3lnYTNwWHo3WFVaNnVDSm9qakkiLCJuIjoiaGFzIiwiaWQiOjF9" - ZMQ_HOST: analytics - volumes: - - data-volume:/var/www/data + ZMQ_CONNECTION_STRING: tcp://analytics:8002 ports: - 8000:8000 + volumes: + - data-volume:/var/www/data privileged: true analytics: image: hastic-analytics - #build: analytics - volumes: - - data-volume:/var/www/data - privileged: true + build: analytics volumes: data-volume: diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 5592a20..6dda688 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -18,8 +18,12 @@ export class AnalyticsService { private _ipcPath: string = null; private _analyticsPinger: NodeJS.Timer = null; private _isClosed = false; + private _productionMode = false; + private _inDocker = false; constructor(private _onMessage: (message: AnalyticsMessage) => void) { + this._productionMode = process.env.NODE_ENV !== 'development'; + this._inDocker = process.env.INSIDE_DOCKER === 'true'; this._init(); } @@ -67,10 +71,12 @@ export class AnalyticsService { private async _init() { this._requester = zmq.socket('pair'); - let productionMode = process.env.NODE_ENV !== 'development' && process.env.INSIDE_DOCKER !== 'true'; this._zmqConnectionString = `tcp://${config.ZMQ_HOST}:${config.ZMQ_DEV_PORT}`; // debug mode - if(productionMode) { + + if(this._inDocker) { + this._zmqConnectionString = config.ZMQ_CONNECTION_STRING; + } else if(this._productionMode) { this._zmqConnectionString = config.ZMQ_CONNECTION_STRING; if(this._zmqConnectionString === null) { var createResult = await AnalyticsService.createIPCAddress(); @@ -84,7 +90,7 @@ export class AnalyticsService { this._requester.on("message", this._onAnalyticsMessage.bind(this)); console.log('Ok'); - if(productionMode) { + if(this._productionMode && !this._inDocker) { console.log('Creating analytics process...'); try { var cp = await AnalyticsService._runAnalyticsProcess(this._zmqConnectionString); From 8fa210d23fde556375e27e1c5ffb7243a034d785 Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 10 Oct 2018 15:24:23 +0300 Subject: [PATCH 12/19] remove debug logging --- .gitignore | 2 +- Makefile | 12 ------------ analytics/Dockerfile | 10 ++++++---- analytics/config.py | 2 +- docker-compose.yml | 10 +++++----- server/Dockerfile | 17 +++++++++-------- server/src/services/analytics_service.ts | 2 +- 7 files changed, 23 insertions(+), 32 deletions(-) delete mode 100644 Makefile diff --git a/.gitignore b/.gitignore index bdafef7..b6debd5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ data dist -config/config.json +config.json node_modules/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 5181763..0000000 --- a/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -.PHONY: server analytics compose - -all: server analytics - -server: - docker build server -t hastic-server - -analytics: - docker build analytics -t hastic-analytics - -compose: - docker-compose up diff --git a/analytics/Dockerfile b/analytics/Dockerfile index c1e80eb..7b3e23a 100644 --- a/analytics/Dockerfile +++ b/analytics/Dockerfile @@ -1,11 +1,9 @@ FROM python:3.6.6 -VOLUME [ "/var/www/data" ] - -COPY . /var/www/analytics/ - WORKDIR /var/www/analytics +COPY ./requirements.txt /var/www/analytics + RUN pip install -r requirements.txt \ && apt-get update && apt-get install -y \ apt-utils \ @@ -15,4 +13,8 @@ RUN pip install -r requirements.txt \ g++ \ git +VOLUME [ "/var/www/data" ] + +COPY . /var/www/analytics/ + CMD ["python", "server.py"] diff --git a/analytics/config.py b/analytics/config.py index b867a3b..97faa14 100644 --- a/analytics/config.py +++ b/analytics/config.py @@ -27,4 +27,4 @@ def get_config_field(field, default_val = None): raise Exception('Please configure {}'.format(field)) ZMQ_DEV_PORT = get_config_field('ZMQ_DEV_PORT', '8002') -ZMQ_CONNECTION_STRING = get_config_field('ZMQ_CONNECTION_STRING', 'tcp://*:%s' % ZMQ_DEV_PORT) +ZMQ_CONNECTION_STRING = get_config_field('ZMQ_CONNECTION_STRING', 'tcp://0.0.0.0:%s' % ZMQ_DEV_PORT) diff --git a/docker-compose.yml b/docker-compose.yml index d757602..da7c5e2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,17 +4,17 @@ services: image: hastic-server build: server environment: - HASTIC_API_KEY: "eyJrIjoiNzhiYjIyTGZDMjY4M3lnYTNwWHo3WFVaNnVDSm9qakkiLCJuIjoiaGFzIiwiaWQiOjF9" - ZMQ_CONNECTION_STRING: tcp://analytics:8002 - ports: - - 8000:8000 + HASTIC_API_KEY: ${HASTIC_API_KEY} + ZMQ_CONNECTION_STRING: tcp://0.0.0.0:8002 + network_mode: host volumes: - data-volume:/var/www/data - privileged: true analytics: image: hastic-analytics build: analytics + ports: + - 8002:8002 volumes: data-volume: diff --git a/server/Dockerfile b/server/Dockerfile index 6db9cae..f893f61 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -1,11 +1,5 @@ FROM python:3.6.6 -VOLUME [ "/var/www/data" ] - -COPY . /var/www/ - -WORKDIR /var/www/server - RUN apt-get install curl \ bash \ gnupg \ @@ -13,8 +7,15 @@ RUN apt-get install curl \ g++ \ && curl -sL https://deb.nodesource.com/setup_8.x | bash - \ && apt-get update \ - && apt-get install nodejs \ - && npm install \ + && apt-get install nodejs + +VOLUME [ "/var/www/data" ] + +COPY . /var/www/server + +WORKDIR /var/www/server + +RUN npm install \ && npm run build ENV INSIDE_DOCKER true diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 6dda688..8cec1a4 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -76,7 +76,7 @@ export class AnalyticsService { if(this._inDocker) { this._zmqConnectionString = config.ZMQ_CONNECTION_STRING; - } else if(this._productionMode) { + } else if(this._productionMode && !this._inDocker) { this._zmqConnectionString = config.ZMQ_CONNECTION_STRING; if(this._zmqConnectionString === null) { var createResult = await AnalyticsService.createIPCAddress(); From 3e51fd027a8d6b28844789d4f655b72e908ea0e2 Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 10 Oct 2018 15:40:28 +0300 Subject: [PATCH 13/19] fix according review --- analytics/.dockerignore | 2 +- analytics/config.py | 2 -- server/src/services/analytics_service.ts | 2 +- 3 files changed, 2 insertions(+), 4 deletions(-) diff --git a/analytics/.dockerignore b/analytics/.dockerignore index 0a87603..ce5fca2 100644 --- a/analytics/.dockerignore +++ b/analytics/.dockerignore @@ -1,5 +1,5 @@ .git npm-debug node_modules -__pychache__ +__pycache__ .vscode diff --git a/analytics/config.py b/analytics/config.py index 97faa14..d71d955 100644 --- a/analytics/config.py +++ b/analytics/config.py @@ -1,5 +1,3 @@ - - import os import json diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index 8cec1a4..a41940a 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -23,7 +23,7 @@ export class AnalyticsService { constructor(private _onMessage: (message: AnalyticsMessage) => void) { this._productionMode = process.env.NODE_ENV !== 'development'; - this._inDocker = process.env.INSIDE_DOCKER === 'true'; + this._inDocker = process.env.INSIDE_DOCKER !== undefined; this._init(); } From ad57315f5ac49177234caf6a128f699652868057 Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 10 Oct 2018 15:56:56 +0300 Subject: [PATCH 14/19] add docker tag --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index da7c5e2..8c0e56f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: server: - image: hastic-server + image: hastic-server:latest build: server environment: HASTIC_API_KEY: ${HASTIC_API_KEY} @@ -11,7 +11,7 @@ services: - data-volume:/var/www/data analytics: - image: hastic-analytics + image: hastic-analytics:latest build: analytics ports: - 8002:8002 From ca3c9b9cf4fb7b19a90759828e3f1ec8d5e160bc Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 10 Oct 2018 16:22:02 +0300 Subject: [PATCH 15/19] fix typo --- docker-compose.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index 8c0e56f..b4d71d0 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,7 +1,7 @@ version: '2' services: server: - image: hastic-server:latest + image: hastic/server:latest build: server environment: HASTIC_API_KEY: ${HASTIC_API_KEY} @@ -11,7 +11,7 @@ services: - data-volume:/var/www/data analytics: - image: hastic-analytics:latest + image: hastic/analytics:latest build: analytics ports: - 8002:8002 From aa43bac335e338a29f20bc4ae91817bf05d866f9 Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 10 Oct 2018 16:30:54 +0300 Subject: [PATCH 16/19] fix analytics restart --- server/src/services/analytics_service.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/server/src/services/analytics_service.ts b/server/src/services/analytics_service.ts index a41940a..38c4954 100644 --- a/server/src/services/analytics_service.ts +++ b/server/src/services/analytics_service.ts @@ -171,12 +171,13 @@ export class AnalyticsService { private async _onAnalyticsDown() { console.log('Analytics is down'); - if(process.env.NODE_ENV !== 'development' && process.env.INSIDE_DOCKER !== 'true') { + if(this._productionMode && !this._inDocker) { await AnalyticsService._runAnalyticsProcess(this._zmqConnectionString); } } private _onAnalyticsMessage(data: any) { + let text = data.toString(); if(text === 'PONG') { this._pingResponded = true; From f15f865d77fcff4074e54b16ce658a6008edad95 Mon Sep 17 00:00:00 2001 From: amper43 Date: Wed, 10 Oct 2018 22:35:02 +0300 Subject: [PATCH 17/19] finalyze --- docker-compose.yml | 7 +++---- server/Dockerfile | 11 +++++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index b4d71d0..1dde626 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,16 +5,15 @@ services: build: server environment: HASTIC_API_KEY: ${HASTIC_API_KEY} - ZMQ_CONNECTION_STRING: tcp://0.0.0.0:8002 - network_mode: host + ZMQ_CONNECTION_STRING: tcp://analytics:8002 + ports: + - 8000:8000 volumes: - data-volume:/var/www/data analytics: image: hastic/analytics:latest build: analytics - ports: - - 8002:8002 volumes: data-volume: diff --git a/server/Dockerfile b/server/Dockerfile index f893f61..ff47b00 100644 --- a/server/Dockerfile +++ b/server/Dockerfile @@ -11,12 +11,15 @@ RUN apt-get install curl \ VOLUME [ "/var/www/data" ] -COPY . /var/www/server - WORKDIR /var/www/server -RUN npm install \ - && npm run build +COPY package.json /var/www/server + +RUN npm install + +COPY . /var/www/server + +RUN npm run build ENV INSIDE_DOCKER true From ec6b245c20cd203b85b2ac2109e5c661783d0673 Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 12 Oct 2018 11:29:06 +0300 Subject: [PATCH 18/19] add .env file --- docker-compose.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker-compose.yml b/docker-compose.yml index 1dde626..eb9742b 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,7 +5,7 @@ services: build: server environment: HASTIC_API_KEY: ${HASTIC_API_KEY} - ZMQ_CONNECTION_STRING: tcp://analytics:8002 + ZMQ_CONNECTION_STRING: ${ZMQ_CONNECTION_STRING} ports: - 8000:8000 volumes: From 9ae8a07f87e8975775dcf2a581afbc2d691ce38f Mon Sep 17 00:00:00 2001 From: amper43 Date: Fri, 12 Oct 2018 11:29:16 +0300 Subject: [PATCH 19/19] fix --- .env | 1 + 1 file changed, 1 insertion(+) create mode 100644 .env diff --git a/.env b/.env new file mode 100644 index 0000000..a6f559f --- /dev/null +++ b/.env @@ -0,0 +1 @@ +ZMQ_CONNECTION_STRING=tcp://analytics:8002