/test-affluences

Technical test!

Primary LanguageTypeScript

Test Devops

This is a basic project for Devops test of Affluences. It consists of a REST API for a TODO list app.

Project goals

  • Run the project
  • Fix the tests in /tests
  • Write a Dockerfile and docker-compose.yml
  • Deploy a simple Prometheus + Grafana visualization stack
  • Write a .gitlab-ci.yml to run the tests and build the Docker image

Project folders

  • /src : project source code
  • /tests : test suite
  • /metrics : files needed to setup the visualization stack

Project routes

  • GET /tasks : retrieve all tasks
  • GET /tasks/:id : retrieve a single task
  • POST /tasks : add a new task
  • PUT /tasks/:id : edit an existing task
  • DELETE /tasks/:id : delete an existing task

Metrics

This app can expose Prometheus metrics when setting the following environment variables : ENABLE_METRICS=true and PROM_TOKEN=<random string>

The metrics will be available at /metrics when authenticated using the header Authorization: Bearer <your token>

Project setup

Native setup

Installation

Use the package manager npm, yarn or pnpm to install dependencies.

[npm|yarn|pnpm] install

Environment variables

There is a .env file at the root of the file, do not forget to edit the values

Usage

# Run in watch mode
[npm|yarn|pnpm] run dev
# Build the project
[npm|yarn|pnpm] run build
# Run the built result
[npm|yarn|pnpm] run start
# Run the test suite
[npm|yarn|pnpm] run test

Docker setup

This will check dockerfile syntax, build the project, and make a production image based on alpine.

IMAGENAME="$my-image-name" ./build_dockerfile.sh
docker run --rm -d -p $PORT:$PORT "$my-image-name"

find $PORT value in .env .

License

MIT