Skip to content
This repository has been archived by the owner on Nov 14, 2023. It is now read-only.

equinor/radix-api-contract-testing

Repository files navigation

Radix API Contract Testing

This project is now archived - 2023.11.14

This repository is not longer in use.

This application provides contract testing of the Radix API and consumer projects. This document is for Radix developers, or anyone interested in poking around

Windows notes

If using Windows, you need at least Windows 10 Creators Update.

There is currently a problem with Docker that prevents auto-reload of the development server from working when source files change. A simple workaround is to use a little watcher process.

Running, building

Good news: for development, you only need Docker and a code editor! To start the development environment:

docker-compose up

This builds a Docker image radix-api-contract-testing-dev, runs it in the container radix-api-contract-testing-dev_container, mounts the local directory into /app in the container, and runs npm run nodemon, which watches for changes and serves the app on port 3000. The debugger also runs on port 9222.

Stop the server with Ctrl+C, but also run docker-compose down to clean the Docker state.

Important: the node_modules and workspace directories are not mapped to the host (if you don't have node_modules locally, it will be created but it will remain empty and it will not map between local and container environments). NPM commands must be run in the container, even if you have NPM installed on the host. To run a command in the container:

docker exec -ti radix-api-contract-testing-dev_container <command>

For instance:

docker exec -ti radix-api-contract-testing-dev_container npm install --save left-pad

To get a shell:

docker exec -ti radix-api-contract-testing-dev_container sh

If you need to nuke node_modules or workspace you can stop the container and run:

docker container rm radix-api-contract-testing-dev_container
docker volume rm radix-api-contract-testing-dev_node-modules
docker volume rm radix-api-contract-testing-dev_workspace

If you change package.json (e.g. add a dependency), or want to force a clean dev environment, you will need to rebuild the dev image:

docker-compose up --build

Deploying

This is a Radix application. Commits to master will trigger a build and deployment to the only (prod) environment.

Project configuration

The GitHub repos for radix-web-console and radix-api require a webhook each, with the following settings:

  • Payload URL: https://radix-api-contract-testing.app.radix.equinor.com/webhook
  • Content type: application/json
  • Secret: The same as used in the Secerts section below
  • Events: Just the push event

Secrets

The application requires one environment variable, GITHUB_SHARED_SECRET, that should be defined as a Radix secret in production. For local development, instead of an environment variable you can create the file /config/local.json (this won't be added to git), and specify the value as such:

{
  "githubSharedSecret": "secret-value-here"
}

Folder structure

The base directory is organised as defined by Create React App. Within /src, however:

  • /project-*/:
  • /static/:
  • /views/:
  • /index.js: Entry point for the app

Coding standards

Coding standards are enforced by Prettier and ESLint. Please use appropriate plugins for your editor:

To get ESLint to run properly from your editor you will need to have it set up in your local environment (not the dev Docker container). You can do that by running:

npm install --only=dev && npm install --no-save eslint

Note the "no save" eslint installation — this is to avoid a conflict with the version within the Docker container, which sometimes does not work from within a code editor.

Contribution

Want to contribute? Read our contributing guidelines

Production build

The production build is containerised in the project's Dockerfile. To run the build image locally:

docker build -t radix-api-contract-testing-prod .
docker run --name radix-api-contract-testing-prod_container --rm -p 8080:80 radix-api-contract-testing-prod

The web server will be available on http://localhost:8080

Security

This is how we handle security issues