Skip to content

Commit

Permalink
Add Docker container for the Demo Application (#11)
Browse files Browse the repository at this point in the history
* 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>
  • Loading branch information
alexvasseur and mikhail-vl committed Dec 24, 2021
1 parent 8e4604b commit b23b09e
Show file tree
Hide file tree
Showing 7 changed files with 122 additions and 282 deletions.
19 changes: 19 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
FROM node
WORKDIR /app

# Install depenencies
COPY package.json .
COPY yarn.lock .
RUN yarn install

# Install Redis tools
RUN apt update
RUN apt install -y redis-tools

# Copy Gears and application
COPY gears ./gears
COPY src ./src
COPY ./docker-cmd.sh .

# Run
CMD [ "./docker-cmd.sh" ]
9 changes: 9 additions & 0 deletions docker-cmd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Install StreamReader for Time-Series
cat gears/timeseries.py | redis-cli -h redis -x RG.PYEXECUTE

# Install StreamReader for Orders
cat gears/orders.py | redis-cli -h redis -x RG.PYEXECUTE

# Run Simulation
echo "Starting Customers & Orders simulation"
npm run simulation redis
8 changes: 7 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
version: "3.4"

services:
app:
build: .
image: ghcr.io/redisgrafana/pop-up-store:latest
depends_on:
- redis

redis:
container_name: redis
image: ghcr.io/redisgrafana/redis-prophet:latest
image: redislabs/redismod
ports:
- "6379:6379"

Expand Down
214 changes: 0 additions & 214 deletions package-lock.json

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
{
"author": "Mikhail Volkov",
"dependencies": {
"ioredis": "^4.17.3",
"ioredis": "^4.28.2",
"lodash": "^4.17.21"
},
"description": "Pop-up store using RedisTimeSeries, RedisGears and Redis Datasource for Grafana",
"license": "Apache-2.0",
"name": "redis-pop-up-store",
"scripts": {
"docker:build": "docker-compose build",
"redis-cli": "docker exec -it redis redis-cli",
"register": "./register.sh && docker exec -it redis redis-cli RG.DUMPREGISTRATIONS",
"simulation": "npm i; node src/pop-up-store.js",
"start": "docker-compose pull && docker-compose up",
"stop": "docker-compose down",
"upgrade": "yarn upgrade --latest"
},
"version": "2.0.0"
"version": "2.1.0"
}
15 changes: 14 additions & 1 deletion src/pop-up-store.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const Redis = require("ioredis");
/**
* You can also specify connection options as a redis:// URL or rediss:// URL when using TLS encryption:
*/
const redis = new Redis("redis://localhost:6379");
const redis = new Redis(getRedisURI());

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

/**
* Get Redis host from first argument (optional)
* argv is: [ '/usr/local/bin/node', '/app/src/pop-up-store.js', '...' ]
*/
function getRedisURI() {
if (process.argv.length > 2) {
return "redis://"+process.argv[2]+":6379";
} else {
return "redis://localhost:6379";
}
}

/**
* Generate Id
*/
Expand Down Expand Up @@ -62,4 +74,5 @@ function newCustomer() {
/**
* Sale started
*/
console.log("Now running simulation...")
newCustomer();
Loading

0 comments on commit b23b09e

Please sign in to comment.