Skip to content

Commit

Permalink
Merge pull request #21 from radoslavirha/microservices
Browse files Browse the repository at this point in the history
Microservices
  • Loading branch information
radoslavirha authored Oct 10, 2023
2 parents 946d841 + 083b47f commit c3efa96
Show file tree
Hide file tree
Showing 132 changed files with 3,587 additions and 852 deletions.
28 changes: 23 additions & 5 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
*/coverage
*/dist
*/node_modules
*/.DS_Store
*/**/config.json
.act
.git
.github
.husky
.vscode
docker
!docker/nginx
docs
node_modules
.gitignore
.DS_Store
.release-please-manifest.json
CHANGELOG*.md
release-please-config.json

*/config/*.json
coverage
dist
*/.eslintrc.js
*/jest.config.json

packages/config/config/*.json
!packages/config/config/*.template.json
6 changes: 5 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ API: api/**
UI: ui/**
PACKAGE: packages/**

'Authentication API': api/authentication/**
'GraphQL API': api/graphql/**
"Hiker's Book": ui/hikers-book/**
'Stages API': api/stages/**
'Trips API': api/trips/**
"Hiker's Book UI": ui/hikers-book/**
'@hikers-book/cli-tools': packages/cli-tools/**
'@hikers-book/config': packages/config/**
'@hikers-book/eslint-config': packages/eslint-config/**
'@hikers-book/tsed-swagger': packages/tsed-swagger/**

ci: .github/**
deps: '**/package.json'
Expand Down
47 changes: 20 additions & 27 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ permissions:
contents: write
pull-requests: write

env:
IMAGE_API_AUTHENTICATION: radoslavirha/hikers-book-api-authentication
IMAGE_API_GRAPHQL: radoslavirha/hikers-book-api-graphql
IMAGE_API_STAGES: radoslavirha/hikers-book-api-stages
IMAGE_API_TRIPS: radoslavirha/hikers-book-api-trips
IMAGE_UI_HIKERS_BOOK: radoslavirha/hikers-book-ui-hikers-book

jobs:
release-please:
name: Release please
Expand All @@ -25,31 +32,16 @@ jobs:
with:
command: manifest

api-graphql:
name: Build & Publish GraphQL API to Docker Hub
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to Docker Hub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_TOKEN }}
- name: Build and push Docker image
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile.api.graphql.dockerfile
push: true
tags: radoslavirha/hikers-book-api-graphql:${{ needs.release-please.outputs.version }},radoslavirha/hikers-book-api-graphql:latest

ui-hikers-book:
name: Build & Publish Hiker's Book UI to Docker Hub
docker:
name: Build & Publish ${{ matrix.docker.name }} to Docker Hub
strategy:
matrix:
docker:
- { name: Hiker's Book UI, target: ui-hikers-book, image: $IMAGE_UI_HIKERS_BOOK }
- { name: Authentication API, target: api-authentication, image: $IMAGE_API_AUTHENTICATION }
- { name: GraphQL API, target: api-graphql, image: $IMAGE_API_GRAPHQL }
- { name: Stages API, target: api-stages, image: $IMAGE_API_STAGES }
- { name: Trips API, target: api-trips, image: $IMAGE_API_TRIPS }
runs-on: ubuntu-latest
needs: release-please
if: needs.release-please.outputs.release
Expand All @@ -67,6 +59,7 @@ jobs:
uses: docker/build-push-action@v5
with:
context: .
file: ./docker/Dockerfile.ui.hikers-book.dockerfile
file: ./docker/Dockerfile
target: ${{ matrix.docker.target }}
push: true
tags: radoslavirha/hikers-book-ui-hikers-book:${{ needs.release-please.outputs.version }},radoslavirha/hikers-book-ui-hikers-book:latest
tags: ${{ matrix.docker.image }}:${{ needs.release-please.outputs.version }},${{ matrix.docker.image }}:latest
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
**/coverage
**/dist
**/node_modules
*/.DS_Store
*/.DS_Store
api/**/config/*.json
4 changes: 4 additions & 0 deletions .husky/pre-commit
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

pnpm run lint
13 changes: 13 additions & 0 deletions api/authentication/.barrelsby.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"directory": [
"./src/docs/controllers/pages",
"./src/v1/controllers"
],
"exclude": [
"__mock__",
"__mocks__",
".spec.ts"
],
"delete": true,
"singleQuotes": true
}
4 changes: 4 additions & 0 deletions api/authentication/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
root: true,
extends: ['@hikers-book/eslint-config']
};
36 changes: 36 additions & 0 deletions api/authentication/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# Hiker's Book Authentication API

## Getting started

```sh
# install dependencies
pnpm install

# serve
pnpm start

# build for production
pnpm build
pnpm start:prod
```

## Barrelsby

This project uses [barrelsby](https://www.npmjs.com/package/barrelsby) to generate index files to import the controllers.

Edit `.barreslby.json` to customize it:

```json
{
"directory": [
"./src/controllers/rest",
"./src/controllers/pages"
],
"exclude": [
"__mock__",
"__mocks__",
".spec.ts"
],
"delete": true
}
```
File renamed without changes.
21 changes: 21 additions & 0 deletions api/authentication/jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = {
clearMocks: true,
collectCoverage: true,
coverageDirectory: 'coverage',
coveragePathIgnorePatterns: ['index.ts', '/node_modules/'],
coverageThreshold: {
global: {
branches: 70,
functions: 70,
lines: 70,
statements: 70
}
},
globalTeardown: './scripts/jest/teardown.js',
moduleFileExtensions: ['js', 'json', 'jsx', 'ts', 'tsx', 'node'],
testEnvironment: 'node',
testMatch: ['**/src/**/__tests__/**/*.[jt]s?(x)', '**/src/**/?(*.)+(spec|test).[tj]s?(x)'],
transform: {
'\\.(ts)$': 'ts-jest'
}
};
105 changes: 105 additions & 0 deletions api/authentication/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
{
"name": "@hikers-book/authentication-api",
"version": "0.4.0",
"description": "Hiker's Book Authentication API",
"author": "radoslav.irha@gmail.com",
"license": "MIT",
"scripts": {
"build": "pnpm run barrels && tsc --project tsconfig.compile.json",
"barrels": "barrelsby --config .barrelsby.json",
"start": "pnpm run barrels && tsnd --inspect --exit-child --cls --ignore-watch node_modules --respawn --transpile-only -r tsconfig-paths/register src/index.ts",
"start:prod": "cross-env NODE_ENV=production node dist/index.js",
"format": "eslint --ext .ts --fix src",
"lint": "eslint --ext .ts src",
"test": "pnpm run test:coverage",
"test:unit": "cross-env NODE_ENV=test jest",
"test:coverage": "pnpm run test:unit",
"config": "hikers-book-config-cli -s node_modules/@hikers-book/config/config/api.authentication.json -t config/default.json -f json || true",
"config:test": "hikers-book-config-cli -s node_modules/@hikers-book/config/config/api.authentication.json -t config/test.json -f json || true",
"config:env": "hikers-book-config-cli -s node_modules/@hikers-book/config/environment-variables/api.authentication.json -t config/custom-environment-variables.json -f json || true",
"config:clear": "find ./config -name '*.json' -type f -delete",
"config:all": "pnpm run config:env && pnpm run config && pnpm run config:test",
"postinstall": "pnpm run config:all"
},
"dependencies": {
"@hikers-book/tsed-swagger": "workspace:*",
"@tsed/ajv": "^7.36.8",
"@tsed/common": "^7.36.8",
"@tsed/core": "^7.36.8",
"@tsed/di": "^7.36.8",
"@tsed/engines": "^7.36.8",
"@tsed/exceptions": "^7.36.8",
"@tsed/json-mapper": "^7.36.8",
"@tsed/logger": "^6.6.3",
"@tsed/logger-file": "^6.6.3",
"@tsed/mongoose": "^7.36.8",
"@tsed/platform-cache": "^7.36.8",
"@tsed/platform-exceptions": "^7.36.8",
"@tsed/platform-express": "^7.36.8",
"@tsed/platform-log-middleware": "^7.36.8",
"@tsed/platform-middlewares": "^7.36.8",
"@tsed/platform-params": "^7.36.8",
"@tsed/platform-response-filter": "^7.36.8",
"@tsed/platform-views": "^7.36.8",
"@tsed/schema": "^7.36.8",
"@tsed/swagger": "^7.36.8",
"ajv": "^8.12.0",
"barrelsby": "^2.8.1",
"body-parser": "^1.20.2",
"class-validator": "^0.13.2",
"compression": "^1.7.4",
"config": "^3.3.9",
"cookie-parser": "^1.4.6",
"cors": "^2.8.5",
"cross-env": "^7.0.3",
"dotenv": "^16.3.1",
"dotenv-expand": "^10.0.0",
"dotenv-flow": "^3.3.0",
"express": "^4.18.2",
"helmet": "^7.0.0",
"method-override": "^3.0.0",
"mongoose": "^7.5.0"
},
"devDependencies": {
"@hikers-book/cli-tools": "workspace:*",
"@hikers-book/config": "workspace:*",
"@hikers-book/eslint-config": "workspace:*",
"@tsed/cli-plugin-eslint": "4.6.4",
"@tsed/cli-plugin-jest": "4.6.4",
"@tsed/cli-plugin-mongoose": "4.6.4",
"@tsed/testing-mongoose": "^7.36.8",
"@types/body-parser": "^1.19.3",
"@types/compression": "^1.7.3",
"@types/config": "^3.3.1",
"@types/cookie-parser": "^1.4.4",
"@types/cors": "^2.8.14",
"@types/express": "^4.17.18",
"@types/jest": "^29.5.5",
"@types/method-override": "^0.0.33",
"@types/multer": "^1.4.8",
"@types/node": "^20.5.7",
"@types/supertest": "^2.0.14",
"@types/validator": "^13.11.2",
"jest": "^29.7.0",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-node": "^10.9.1",
"ts-node-dev": "^2.0.0",
"tsconfig-paths": "^4.2.0",
"tslib": "^2.6.2",
"typescript": "^5.2.2"
},
"tsed": {
"convention": "conv_default",
"architecture": "arc_default",
"packageManager": "pnpm"
},
"engines": {
"node": ">= 18.0.0",
"pnpm": ">= 8.7.0"
},
"os": [
"darwin",
"linux"
]
}
3 changes: 3 additions & 0 deletions api/authentication/scripts/jest/teardown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = async () => {
(await global.__MONGOD__) && global.__MONGOD__.stop();
};
26 changes: 26 additions & 0 deletions api/authentication/src/Server.integration.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import { PlatformTest } from '@tsed/common';
import { TestMongooseContext } from '@tsed/testing-mongoose';
import SuperTest from 'supertest';
import { Server } from './Server';

describe('Server', () => {
let request: SuperTest.SuperTest<SuperTest.Test>;

beforeEach(TestMongooseContext.bootstrap(Server));
beforeEach(() => {
request = SuperTest(PlatformTest.callback());
});

afterEach(TestMongooseContext.reset);

it('should call GET /rest', async () => {
const response = await request.get('/rest').expect(404);

expect(response.body).toEqual({
errors: [],
message: 'Resource "/rest" not found',
name: 'NOT_FOUND',
status: 404
});
});
});
Loading

0 comments on commit c3efa96

Please sign in to comment.