diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e696b6a..5e1748d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -2,6 +2,9 @@ on: push: branches: - '**' + pull_request: + branches: + - '**' jobs: install-sprkl-test: runs-on: ubuntu-latest @@ -9,15 +12,15 @@ jobs: 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 diff --git a/docker-compose.yml b/docker-compose.yml index 26fd19b..4ec6ca2 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -4,6 +4,8 @@ services: orders: build: ./orders + depends_on: + - pg environment: MONGO_HOST: mongodb PAYMENTS_URL: http://payments:3000 @@ -11,11 +13,16 @@ services: 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 @@ -23,6 +30,9 @@ services: catalog: build: ./catalog + depends_on: + - pg + - redis environment: REDIS_HOST: redis @@ -37,6 +47,10 @@ services: ./pg.env environment: PGDATA: /data/pg + POSTGRES_USER: admin + POSTGRES_PASSWORD: admin + POSTGRES_DB: payments + redis: image: redis @@ -44,6 +58,14 @@ services: shop: build: ./shop + depends_on: + - pg + - redis + - mongodb + - metrics + - catalog + - orders + - payments restart: always environment: VITE_METRICS_URL: http://metrics:3000 diff --git a/metrics/metrics.js b/metrics/metrics.js index 03ead12..c614a41 100644 --- a/metrics/metrics.js +++ b/metrics/metrics.js @@ -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({ diff --git a/orders/index.js b/orders/index.js index c7a09f4..65f1f69 100644 --- a/orders/index.js +++ b/orders/index.js @@ -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) { diff --git a/package.json b/package.json index 10a94d6..198612e 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/tests/e2e.test.ts b/tests/e2e.test.ts index da88b98..5c89252 100644 --- a/tests/e2e.test.ts +++ b/tests/e2e.test.ts @@ -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); + } })