Skip to content
Open
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
2 changes: 2 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.git
**/node_modules
26 changes: 26 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
on:
push:
branches:
- '**'
jobs:
install-sprkl-test:
runs-on: ubuntu-latest
name: Installing Sprkl Testing
steps:

- uses: actions/checkout@v3


- name: Sprkl Setup
uses: sprkl-dev/sprkl-action/setup@v0.0.30
with:
npm_token: ${{ secrets.SPRKL_NPM_TOKEN }}
setenv: false

- run: yarn install
- run: yarn test:e2e:sprkl

- name: Sprkl Push
uses: sprkl-dev/sprkl-action/push@v0.0.30
with:
token: ${{ secrets.SPRKL_CI_TOKEN }}
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.git
build
node_modules
*.log
sprkl_diagnostics.*.tar
.sprkl.docker-compose.yml

2 changes: 1 addition & 1 deletion catalog/catalog.test.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const getCatalog = require('./catalog')
const { getCatalog } = require('./catalog')

const redis = require('redis-mock')

Expand Down
5 changes: 5 additions & 0 deletions catalog/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,5 +27,10 @@ app.get('/catalog', async (req, res) => {
res.send(await getCatalog());
})

app.get('/healthz', async (req, res) => {
res.status(200)
res.send("Ready");
})

bootstrap();

4,111 changes: 2,052 additions & 2,059 deletions catalog/yarn.lock

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions ci.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
sprkl ci pull --token=$SPRKL_MSE_TOKEN --run=2867069798 --repository=sprkl-dev/sprkl-microservices-example
35 changes: 17 additions & 18 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,21 @@ services:

orders:
build: ./orders
ports:
- 3000:3000
environment:
MONGO_HOST: mongodb
PAYMENTS_URL: http://payments:3000
CATALOG_URL: http://catalog:3000

metrics:
build: ./metrics
environment:
MONGO_HOST: mongodb

payments:
build: ./payments
restart: always
depends_on:
- "pg"
environment:
PG_HOST: pg
PG_USER: admin
Expand All @@ -26,37 +32,30 @@ services:
mongodb:
image: mongo
restart: always
ports:
- 27017:27017
volumes:
- mongodb-data:/data/db

pg:
image: postgres
restart: always
ports:
- 5432:5432
env_file:
./pg.env
environment:
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: payments
PGDATA: /data/pg
volumes:
- pg-data:/data/pg

redis:
image: redis
restart: always
ports:
- 6379:6379

shop:
build: ./shop
restart: always
environment:
VITE_METRICS_URL: http://metrics:3000
VITE_CATALOG_URL: http://catalog:3000
VITE_ORDERS_URL: http://orders:3000
VITE_PAYMENTS_URL: http://payments:3000
volumes:
- "./shop:/code/"
- "./shop/src:/code/src"
ports:
- "80:5000"

volumes:
pg-data:
mongodb-data:
1 change: 1 addition & 0 deletions metrics/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
**/node_modules
13 changes: 13 additions & 0 deletions metrics/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@

FROM node:18-alpine

WORKDIR /code/
COPY package.json .

RUN yarn install

COPY . .

EXPOSE 3000

CMD ["yarn", "start"]
31 changes: 31 additions & 0 deletions metrics/backup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
const { default: axios } = require("axios");

app.put('/updateMetrics', async (req, res) => {
try {
const metrics = await utils.retrieveMetrics();
if (new Date().getDay() == 7) {
metrics.saturdaysCounter++;
} else {
metrics.totalCounter++;
}
await utils.updateMetrics(metrics);
res.sendStatus(200);
} catch(ex) {
res.status(401).send({ message: 'Failed updating metrics' + ex});
}
});

const json = {
totalCounter: metrics.totalCounter,
saturdaysCounter: metrics.saturdaysCounter
}



async function updateMetrics() {
try {
await axios.put('http://metrics:3000/updateMetrics')
} catch(ex) {
console.log("Failed updating metrics")
}
}
1 change: 1 addition & 0 deletions metrics/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require('./metrics')
48 changes: 48 additions & 0 deletions metrics/metrics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const express = require('express');
const req = require('express/lib/request');
const route = require("./route")
const mongoose = require('mongoose');
const utils = require('./utils')

const app = express();
app.use(express.json());

const port = 3000;

//db connect
// console.log(process.env.MONGODB_URI );
mongoose.connect(`mongodb://${process.env.MONGO_HOST}/mern`, {
useNewUrlParser: true,
useUnifiedTopology: true,
useCreateIndex: true,
});

app.get('/metrics', async (req, res) => {
const metrics = await utils.getMetrics();
res.send({
totalCounter : metrics.totalCounter,
saturdaysCounter : metrics.saturdaysCounter
});
})

app.post('/metrics', async (req, res) => {
try {
const metrics = {
totalCounter: req.body.totalCounter,
saturdaysCounter: req.body.saturdaysCounter
}
await utils.setMetrics(metrics);
res.sendStatus(200);
} catch (ex) {
res.sendStatus(404);
}
})

app.get('/healthz', async (req, res) => {
res.status(200);
res.send("Ready");
})

app.listen(port, () => {
console.log(`Demo app listening at http://localhost:${port}`);
});
22 changes: 22 additions & 0 deletions metrics/models/metric.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const mongoose = require('mongoose');

const metricsSchema = new mongoose.Schema(
{
totalCounter: {
type: Number,
required: true
},
saturdaysCounter: {
type: Number,
required: true
}
},
{
timestamps: true
}

);

const Metrics = mongoose.model('Metrics', metricsSchema);

module.exports = Metrics;
Loading