Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Docker container for the Demo Application #11

Merged
merged 4 commits into from
Dec 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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