diff --git a/.devcontainer/Dockerfile b/.devcontainer/Dockerfile new file mode 100644 index 0000000..97aa3cc --- /dev/null +++ b/.devcontainer/Dockerfile @@ -0,0 +1,9 @@ +FROM sprkldev/sprkl-node:0.0.43 + +RUN apk add git curl docker + +RUN mkdir -p /root/.docker/cli-plugins && \ + curl -SL https://github.com/docker/compose/releases/download/v2.10.2/docker-compose-linux-x86_64 -o /root/.docker/cli-plugins/docker-compose && \ + chmod +x /root/.docker/cli-plugins/docker-compose + +ENV DOCKER_HOST=unix:///var/run/docker-host.sock \ No newline at end of file diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json new file mode 100644 index 0000000..5340c11 --- /dev/null +++ b/.devcontainer/devcontainer.json @@ -0,0 +1,15 @@ +{ + "build": { + "dockerfile": "Dockerfile", + // Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04 + // Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon. + "args": { "VARIANT": "ubuntu-22.04" } + }, + "customizations": { + "vscode": { + "extensions": ["sprkldev.sprkl-vscode"] + } + }, + "mounts": ["source=/var/run/docker.sock,target=/var/run/docker-host.sock,type=bind"], + "runArgs": ["--network=host"] +} \ No newline at end of file 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..8e67035 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,8 +50,6 @@ services: VITE_CATALOG_URL: http://catalog:3000 VITE_ORDERS_URL: http://orders:3000 VITE_PAYMENTS_URL: http://payments:3000 - volumes: - - "./shop/src:/code/src" ports: - "80:5000" 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/testfile b/testfile new file mode 100644 index 0000000..e69de29 diff --git a/testfile2 b/testfile2 new file mode 100644 index 0000000..e69de29 diff --git a/testfile3 b/testfile3 new file mode 100644 index 0000000..e69de29 diff --git a/testfile4 b/testfile4 new file mode 100644 index 0000000..e69de29 diff --git a/testfile5 b/testfile5 new file mode 100644 index 0000000..e69de29 diff --git a/testfile6 b/testfile6 new file mode 100644 index 0000000..e69de29 diff --git a/testfile7 b/testfile7 new file mode 100644 index 0000000..e69de29 diff --git a/testfile8 b/testfile8 new file mode 100644 index 0000000..e69de29