From 818e68c9906d0537e0d9c790c6f2836a172aa19b Mon Sep 17 00:00:00 2001 From: Erez Voitiz Date: Tue, 6 Sep 2022 17:10:30 +0300 Subject: [PATCH 01/10] chore(gha): set tokens --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e696b6a..ba68f41 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,7 +13,7 @@ jobs: - name: Sprkl Setup uses: sprkl-dev/sprkl-action/setup@master with: - npm_token: ${{ secrets.USE_SPRKL_CI_TOKEN }} + npm: ${{ secrets.USE_SPRKL_CI_TOKEN }} setenv: false - run: yarn install From 95c22985a2e36d9f437d7c118171ec5af93cb3bf Mon Sep 17 00:00:00 2001 From: Erez Voitiz Date: Tue, 6 Sep 2022 17:11:25 +0300 Subject: [PATCH 02/10] chore(gha): execute ci on PRs --- .github/workflows/ci.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index ba68f41..c54af3c 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 @@ -13,7 +16,7 @@ jobs: - name: Sprkl Setup uses: sprkl-dev/sprkl-action/setup@master with: - npm: ${{ secrets.USE_SPRKL_CI_TOKEN }} + token: ${{ secrets.USE_SPRKL_CI_TOKEN }} setenv: false - run: yarn install From 2a40cb413167352805e519f2185cfc678918bca0 Mon Sep 17 00:00:00 2001 From: Erez Voitiz Date: Wed, 7 Sep 2022 10:26:42 +0300 Subject: [PATCH 03/10] chore(gha): instrument code changes only --- .github/workflows/ci.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c54af3c..596209e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,4 @@ jobs: - run: yarn install - run: yarn test:e2e:sprkl - env: - SPRKL_RECIPE: all From 861ce64a5ef674f68333fbc9b2a51c9d4291caca Mon Sep 17 00:00:00 2001 From: Erez Voitiz Date: Wed, 7 Sep 2022 11:25:03 +0300 Subject: [PATCH 04/10] feat(metrics): added metrics --- metrics/metrics.js | 15 +++++++++++++++ orders/index.js | 1 + 2 files changed, 16 insertions(+) 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) { From cf470911ef03ba82862451f7758d618fcfdda17a Mon Sep 17 00:00:00 2001 From: Erez Voitiz Date: Thu, 8 Sep 2022 09:42:26 +0300 Subject: [PATCH 05/10] fix(gha): fetch depth --- .github/workflows/ci.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 596209e..5e1748d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -12,6 +12,8 @@ jobs: steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Sprkl Setup uses: sprkl-dev/sprkl-action/setup@master From c47277a1f8889a6aa44ba0356f82c3ce05c7d49e Mon Sep 17 00:00:00 2001 From: Eliran Maman Date: Thu, 8 Sep 2022 10:33:06 +0300 Subject: [PATCH 06/10] test: test github application --- docker-compose.yml | 22 ++++++++++++++++++++++ package.json | 2 +- tests/e2e.test.ts | 4 +++- 3 files changed, 26 insertions(+), 2 deletions(-) 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/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); + } }) From bb1a09d65927831be9822aba96dc086fb90899d4 Mon Sep 17 00:00:00 2001 From: Eliran Maman Date: Thu, 8 Sep 2022 11:11:32 +0300 Subject: [PATCH 07/10] chore: test with new push --- some-change | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 some-change diff --git a/some-change b/some-change new file mode 100644 index 0000000..e69de29 From 0598998ab7f330242af918088a576c854979bb50 Mon Sep 17 00:00:00 2001 From: Eliran Maman Date: Thu, 8 Sep 2022 11:22:43 +0300 Subject: [PATCH 08/10] chore: delete some change --- some-change | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 some-change diff --git a/some-change b/some-change deleted file mode 100644 index e69de29..0000000 From 5f7e893acad92c533cc163be3020337b831af1e7 Mon Sep 17 00:00:00 2001 From: Eliran Maman Date: Thu, 8 Sep 2022 11:35:16 +0300 Subject: [PATCH 09/10] chore: add commit to rerun the workflow and close the pr --- close-pr | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 close-pr diff --git a/close-pr b/close-pr new file mode 100644 index 0000000..e69de29 From b79015ae70e1977c40cabd62cb056a5d74ddb1b1 Mon Sep 17 00:00:00 2001 From: Eliran Maman Date: Thu, 8 Sep 2022 11:41:06 +0300 Subject: [PATCH 10/10] chore: re-open pull request --- close-pr | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 close-pr diff --git a/close-pr b/close-pr deleted file mode 100644 index e69de29..0000000