Skip to content

Commit

Permalink
Merge branch 'develop' into release/2024-04-24
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed May 24, 2024
2 parents 1261701 + 5d12914 commit 90f3374
Show file tree
Hide file tree
Showing 177 changed files with 15,609 additions and 4,916 deletions.
5 changes: 5 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
.tmp/
.cache/
.git/
node_modules/
.env
38 changes: 38 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Port
PORT=8080

# Database
DATABASE_USERNAME=bff-db-user
DATABASE_PASSWORD=bff-db-password
DATABASE_NAME=bff-db
DATABASE_PORT=5432

# Rabbit MQ
QUEUE_USER=rabbit
QUEUE_PASSWORD=my-rabbit-password
QUEUE_HOST=localhost
QUEUE_PORT=5672

# Telegram
TELEGRAM_SECRET=

# Orderbook
ORDERBOOK_DATABASE_HOST=
ORDERBOOK_DATABASE_PORT=
ORDERBOOK_DATABASE_USERNAME=
ORDERBOOK_DATABASE_PASSWORD=

# CMS
CMS_API_KEY=
CMS_BASE_URL=https://cms.cow.fi

# Infura
INFURA_KEY=infura-key
INFURA_JWT_ID=infura-jwt-id

# Proxy
PROXY_UPSTREAM=proxy-upstream
PROXY_ORIGIN=proxy-origin

# JWT
JWT_CERT_PASSPHRASE=secret
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
42 changes: 42 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"root": true,
"ignorePatterns": ["**/*"],
"plugins": ["@nx"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {
"@nx/enforce-module-boundaries": [
"error",
{
"enforceBuildableLibDependency": true,
"allow": [],
"depConstraints": [
{
"sourceTag": "*",
"onlyDependOnLibsWithTags": ["*"]
}
]
}
]
}
},
{
"files": ["*.ts", "*.tsx"],
"extends": ["plugin:@nx/typescript"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"extends": ["plugin:@nx/javascript"],
"rules": {}
},
{
"files": ["*.spec.ts", "*.spec.tsx", "*.spec.js", "*.spec.jsx"],
"env": {
"jest": true
},
"rules": {}
}
]
}
57 changes: 57 additions & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Publish Docker image

on:
push:
branches: [main]
tags: [v*]

jobs:
docker:
runs-on: ubuntu-latest
strategy:
matrix:
package:
- apps/api
- apps/twap
- apps/notification-producer
- apps/telegram
steps:
- name: Checkout
uses: actions/checkout@v3

- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: yarn install
- run: yarn build

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Login to GitHub Container Registry
uses: docker/#-action@v2
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}

- name: Extract package name
run: echo "PACKAGE_NAME=$(basename ${{ matrix.package }})" >> $GITHUB_ENV

- name: 'Image metadata for ${{ env.PACKAGE_NAME }}'
id: image_meta
uses: docker/metadata-action@v4
with:
images: ghcr.io/${{ github.repository }}/${{ env.PACKAGE_NAME }}

- name: 'BFF: Build and push ${{ env.PACKAGE_NAME }}'
uses: docker/build-push-action@v4
with:
context: .
file: ${{ matrix.package }}/Dockerfile
push: true
tags: ${{ steps.image_meta.outputs.tags }}
labels: ${{ steps.image_meta.outputs.labels }}
builder: ${{ steps.setup-buildx.outputs.name }}
platforms: linux/amd64
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
tmp

# Logs
logs
*.log
Expand Down Expand Up @@ -65,4 +67,5 @@ test/types/index.js
dist

# env file
.env
.env*
!.env.examples
3 changes: 3 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Add files here to ignore them from prettier formatting
/dist
/coverage
3 changes: 3 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singleQuote": true
}
74 changes: 72 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,73 @@
# Cow Web Services
# BFF (Backend For Frontend)

Backend for frontend is a series of backend services and libraries that enhance user experience for the frontend.

## Getting Started

Install dependencies:

```bash
yarn
```

Create the `.env` file:

```bash
# If you are not using docker
cp .env.example .env

# If you are using docker (handy to launch a service directly using NX)
cp .env.example .env.docker
```

Start docker:
```bash
yarn compose:up
```

# Develop
## Notification Producer
Make sure your `.env` file is defined, if not create one using `.env.example` as a template.

```bash
# Start RabbitMQ
docker-compose up -d queue

# Start the notification producer
yarn producer
```
## Create a new service or library

To add a new app or library, you can run the following command;

```bash
# New API
yarn new:fastify

# New Library
yarn new:lib

# New Node app
yarn new:node
```

For APIs and apps, it will create a Dockerfile. Please, remember to update:
- The `docker-compose.yml` file to include the new service.
- The github actions to include the new service (`.github/workflows/ci.yml`)

For more info, see:
- [@nx/node:application](https://nx.dev/packages/node/generators/application): Generator for Applications
- [@nx/node:application (Fastify)](https://nx.dev/showcase/example-repos/add-fastify): Generator for API Applications using Fastify
- [@nx/node:setup-docker](https://nx.dev/nx-api/node/generators/library): Generator for NodeJS Libraries
- [@nx/node:setup-docker](https://nx.dev/nx-api/node/generators/setup-docker): Docker Generator


# Build
## Docker

Build docker containers and publish to a local registry:

```bash
yarn docker-build:affected
```

Collection of typescript based services, mainly for the use of CoW Swap.
11 changes: 0 additions & 11 deletions api/serverless.ts

This file was deleted.

Empty file added apps/.gitkeep
Empty file.
10 changes: 10 additions & 0 deletions apps/api-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
}
]
}
19 changes: 19 additions & 0 deletions apps/api-e2e/jest.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/* eslint-disable */
export default {
displayName: 'api-e2e',
preset: '../../jest.preset.js',
globalSetup: '<rootDir>/src/support/global-setup.ts',
globalTeardown: '<rootDir>/src/support/global-teardown.ts',
setupFiles: ['<rootDir>/src/support/test-setup.ts'],
testEnvironment: 'node',
transform: {
'^.+\\.[tj]s$': [
'ts-jest',
{
tsconfig: '<rootDir>/tsconfig.spec.json',
},
],
},
moduleFileExtensions: ['ts', 'js', 'html'],
coverageDirectory: '../../coverage/api-e2e',
};
30 changes: 30 additions & 0 deletions apps/api-e2e/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "api-e2e",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"implicitDependencies": [
"api"
],
"targets": {
"e2e": {
"executor": "@nx/jest:jest",
"outputs": [
"{workspaceRoot}/coverage/{e2eProjectRoot}"
],
"options": {
"jestConfig": "packages/api-e2e/jest.config.ts",
"passWithNoTests": true
}
},
"lint": {
"executor": "@nx/linter:eslint",
"outputs": [
"{options.outputFile}"
],
"options": {
"lintFilePatterns": [
"packages/api-e2e/**/*.{js,ts}"
]
}
}
}
}
7 changes: 7 additions & 0 deletions apps/api-e2e/src/bff/example.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import axios from 'axios';

test('GET /example', async () => {
const res = await axios.get('/example');

expect(res.data).toEqual('this is an example');
});
10 changes: 10 additions & 0 deletions apps/api-e2e/src/support/global-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */
var __TEARDOWN_MESSAGE__: string;

module.exports = async function () {
// Start services that that the app needs to run (e.g. database, docker-compose, etc.).
console.log('\nSetting up...\n');

// Hint: Use `globalThis` to pass variables to global teardown.
globalThis.__TEARDOWN_MESSAGE__ = '\nTearing down...\n';
};
7 changes: 7 additions & 0 deletions apps/api-e2e/src/support/global-teardown.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/* eslint-disable */

module.exports = async function () {
// Put clean up logic here (e.g. stopping services, docker-compose, etc.).
// Hint: `globalThis` is shared between setup and teardown.
console.log(globalThis.__TEARDOWN_MESSAGE__);
};
10 changes: 10 additions & 0 deletions apps/api-e2e/src/support/test-setup.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/* eslint-disable */

import axios from 'axios';

module.exports = async function () {
// Configure axios for tests to use.
const host = process.env.HOST ?? 'localhost';
const port = process.env.PORT ?? '3000';
axios.defaults.baseURL = `http://${host}:${port}`;
};
13 changes: 13 additions & 0 deletions apps/api-e2e/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"extends": "../../tsconfig.base.json",
"files": [],
"include": [],
"references": [
{
"path": "./tsconfig.spec.json"
}
],
"compilerOptions": {
"esModuleInterop": true
}
}
9 changes: 9 additions & 0 deletions apps/api-e2e/tsconfig.spec.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"extends": "./tsconfig.json",
"compilerOptions": {
"outDir": "../../dist/out-tsc",
"module": "commonjs",
"types": ["jest", "node"]
},
"include": ["jest.config.ts", "src/**/*.ts"]
}
Loading

0 comments on commit 90f3374

Please # to comment.