Skip to content

Commit b23b09e

Browse files
Add Docker container for the Demo Application (#11)
* npm in Docker, Redis Insight, redismod * Remove package.log and update ioredis * Update Dockerfile and script's name * Update Docker Compose Co-authored-by: Mikhail <47795110+mikhailredis@users.noreply.github.com>
1 parent 8e4604b commit b23b09e

File tree

7 files changed

+122
-282
lines changed

7 files changed

+122
-282
lines changed

Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
FROM node
2+
WORKDIR /app
3+
4+
# Install depenencies
5+
COPY package.json .
6+
COPY yarn.lock .
7+
RUN yarn install
8+
9+
# Install Redis tools
10+
RUN apt update
11+
RUN apt install -y redis-tools
12+
13+
# Copy Gears and application
14+
COPY gears ./gears
15+
COPY src ./src
16+
COPY ./docker-cmd.sh .
17+
18+
# Run
19+
CMD [ "./docker-cmd.sh" ]

docker-cmd.sh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Install StreamReader for Time-Series
2+
cat gears/timeseries.py | redis-cli -h redis -x RG.PYEXECUTE
3+
4+
# Install StreamReader for Orders
5+
cat gears/orders.py | redis-cli -h redis -x RG.PYEXECUTE
6+
7+
# Run Simulation
8+
echo "Starting Customers & Orders simulation"
9+
npm run simulation redis

docker-compose.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
version: "3.4"
22

33
services:
4+
app:
5+
build: .
6+
image: ghcr.io/redisgrafana/pop-up-store:latest
7+
depends_on:
8+
- redis
9+
410
redis:
511
container_name: redis
6-
image: ghcr.io/redisgrafana/redis-prophet:latest
12+
image: redislabs/redismod
713
ports:
814
- "6379:6379"
915

package-lock.json

Lines changed: 0 additions & 214 deletions
This file was deleted.

package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
{
22
"author": "Mikhail Volkov",
33
"dependencies": {
4-
"ioredis": "^4.17.3",
4+
"ioredis": "^4.28.2",
55
"lodash": "^4.17.21"
66
},
77
"description": "Pop-up store using RedisTimeSeries, RedisGears and Redis Datasource for Grafana",
88
"license": "Apache-2.0",
99
"name": "redis-pop-up-store",
1010
"scripts": {
11+
"docker:build": "docker-compose build",
1112
"redis-cli": "docker exec -it redis redis-cli",
1213
"register": "./register.sh && docker exec -it redis redis-cli RG.DUMPREGISTRATIONS",
1314
"simulation": "npm i; node src/pop-up-store.js",
1415
"start": "docker-compose pull && docker-compose up",
1516
"stop": "docker-compose down",
1617
"upgrade": "yarn upgrade --latest"
1718
},
18-
"version": "2.0.0"
19+
"version": "2.1.0"
1920
}

src/pop-up-store.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ const Redis = require("ioredis");
88
/**
99
* You can also specify connection options as a redis:// URL or rediss:// URL when using TLS encryption:
1010
*/
11-
const redis = new Redis("redis://localhost:6379");
11+
const redis = new Redis(getRedisURI());
1212

1313
/**
1414
* There are 10000 products on sale today
@@ -18,6 +18,18 @@ const redis = new Redis("redis://localhost:6379");
1818
const product = 10000;
1919
redis.set("product", product);
2020

21+
/**
22+
* Get Redis host from first argument (optional)
23+
* argv is: [ '/usr/local/bin/node', '/app/src/pop-up-store.js', '...' ]
24+
*/
25+
function getRedisURI() {
26+
if (process.argv.length > 2) {
27+
return "redis://"+process.argv[2]+":6379";
28+
} else {
29+
return "redis://localhost:6379";
30+
}
31+
}
32+
2133
/**
2234
* Generate Id
2335
*/
@@ -62,4 +74,5 @@ function newCustomer() {
6274
/**
6375
* Sale started
6476
*/
77+
console.log("Now running simulation...")
6578
newCustomer();

0 commit comments

Comments
 (0)