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
9 changes: 6 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,25 @@ on:
push:
branches:
- '**'
pull_request:
branches:
- '**'
jobs:
install-sprkl-test:
runs-on: ubuntu-latest
name: Installing Sprkl Testing
steps:

- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Sprkl Setup
uses: sprkl-dev/sprkl-action/setup@master
with:
npm_token: ${{ secrets.USE_SPRKL_CI_TOKEN }}
token: ${{ secrets.USE_SPRKL_CI_TOKEN }}
setenv: false

- run: yarn install
- run: yarn test:e2e:sprkl
env:
SPRKL_RECIPE: all

22 changes: 22 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,35 @@ services:

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

metrics:
build: ./metrics
depends_on:
- pg
environment:
MONGO_HOST: mongodb

payments:
build: ./payments
restart: always
depends_on:
- pg
environment:
PG_HOST: pg
PG_USER: admin
PG_PASSWORD: admin

catalog:
build: ./catalog
depends_on:
- pg
- redis
environment:
REDIS_HOST: redis

Expand All @@ -37,13 +47,25 @@ services:
./pg.env
environment:
PGDATA: /data/pg
POSTGRES_USER: admin
POSTGRES_PASSWORD: admin
POSTGRES_DB: payments


redis:
image: redis
restart: always

shop:
build: ./shop
depends_on:
- pg
- redis
- mongodb
- metrics
- catalog
- orders
- payments
restart: always
environment:
VITE_METRICS_URL: http://metrics:3000
Expand Down
15 changes: 15 additions & 0 deletions metrics/metrics.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,21 @@ mongoose.connect(`mongodb://${process.env.MONGO_HOST}/mern`, {
useCreateIndex: true,
});

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});
}
});

app.get('/metrics', async (req, res) => {
const metrics = await utils.getMetrics();
res.send({
Expand Down
1 change: 1 addition & 0 deletions orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ fastify.post('/orders', async function (request, reply) {
order.state = 'landed'
ordersCollection.insertOne(order);
reply.send(order.state).code(200);
await axios.put('http://metrics:3000/updateMetrics')
})

fastify.get('/orders', async function (request, reply) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "sprkl-microservices-example",
"private": "true",
"scripts": {
"start": "docker compose up --force-recreate",
"start": "docker compose up --force-recreate --build",
"start:sprkl": "sprkl -- docker compose up -d --force-recreate --build",
"stop": "docker compose down",
"test": "jest",
Expand Down
4 changes: 3 additions & 1 deletion tests/e2e.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,10 @@ describe("End to end", () => {
}

test('PlaceOrder', async () => {
if(true){
const res = await axios.post(ORDERS_URL, order, config);
expect(res.status).toBe(200)
expect(res.status).toBe(200);
}
})


Expand Down