Skip to content

Commit

Permalink
Merge pull request #68 from Tonomy-Foundation/bug/fix-docker-issues
Browse files Browse the repository at this point in the history
Fixed docker build error
  • Loading branch information
theblockstalk authored Sep 1, 2023
2 parents 001f866 + 8108c2f commit 75f313a
Show file tree
Hide file tree
Showing 8 changed files with 1,447 additions and 4,694 deletions.
19 changes: 19 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,25 @@ jobs:
- run: yarn run test
- run: yarn run test:e2e

- name: Build and push
uses: docker/build-push-action@v4
with:
context: .
file: ./Dockerfile
target: tonomy_communication_base
push: false
tags: tonomy/communication:development

- name: "Run docker container to check it can run"
run: |
docker run \
--add-host host.docker.internal:host-gateway \
-p 5000:5000 \
tonomy/communication:development \
yarn run start:prod &
sleep 5
curl http://localhost:5000
zap_scan:
runs-on: ubuntu-latest
name: OWASP ZAP API Scan
Expand Down
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ FROM node:18.12.1 AS tonomy_communication_base
WORKDIR /app
COPY . .

RUN yarn install
RUN yarn install --immutable
RUN yarn run build

EXPOSE 5000
Expand Down
52 changes: 25 additions & 27 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,44 +20,43 @@
"test:e2e": "jest --config ./test/jest-e2e.json"
},
"dependencies": {
"@nestjs/common": "^9.0.0",
"@nestjs/core": "^9.0.0",
"@nestjs/mapped-types": "*",
"@nestjs/platform-express": "^9.0.0",
"@nestjs/platform-socket.io": "^9.2.1",
"@nestjs/swagger": "^6.1.4",
"@nestjs/websockets": "^9.2.1",
"@tonomy/tonomy-id-sdk": "development",
"@nestjs/common": "^10.2.3",
"@nestjs/core": "^10.2.3",
"@nestjs/mapped-types": "^2.0.2",
"@nestjs/platform-express": "^10.2.3",
"@nestjs/platform-socket.io": "^10.2.3",
"@nestjs/swagger": "^7.1.10",
"@nestjs/websockets": "^10.2.3",
"@tonomy/tonomy-id-sdk": "^0.15.0-development.2",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.0",
"hcaptcha": "^0.1.1",
"helmet": "^7.0.0",
"nestjs-asyncapi": "^1.0.4",
"reflect-metadata": "^0.1.13",
"rxjs": "^7.2.0"
"rxjs": "^7.8.1"
},
"devDependencies": {
"@nestjs/cli": "^9.0.0",
"@nestjs/schematics": "^9.0.0",
"@nestjs/testing": "^9.0.0",
"@nestjs/cli": "^10.1.17",
"@nestjs/schematics": "^10.0.2",
"@nestjs/testing": "^10.2.3",
"@types/express": "^4.17.13",
"@types/jest": "29.2.4",
"@types/node": "18.11.18",
"@types/supertest": "^2.0.11",
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"eslint": "^8.0.1",
"eslint-config-prettier": "^8.3.0",
"eslint-plugin-prettier": "^4.0.0",
"jest": "29.3.1",
"prettier": "^2.3.2",
"source-map-support": "^0.5.20",
"supertest": "^6.1.3",
"ts-jest": "29.0.3",
"ts-loader": "^9.2.3",
"ts-node": "^10.0.0",
"tsconfig-paths": "4.1.1",
"typescript": "^4.7.4"
"eslint": "^8.48.0",
"eslint-config-prettier": "^9.0.0",
"eslint-plugin-prettier": "^5.0.0",
"jest": "^29.6.4",
"prettier": "^3.0.3",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.1",
"ts-loader": "^9.4.4",
"ts-node": "^10.9.1",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.2.2"
},
"jest": {
"moduleFileExtensions": [
Expand All @@ -78,7 +77,6 @@
},
"packageManager": "[email protected]",
"resolutions": {
"@wharfkit/antelope": "0.7.1",
"@openapi-contrib/openapi-schema-to-json-schema": "3.0.0"
"@wharfkit/antelope": "0.7.1"
}
}
21 changes: 0 additions & 21 deletions src/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AsyncApiDocumentBuilder, AsyncApiModule } from 'nestjs-asyncapi';
import { SwaggerModule, DocumentBuilder } from '@nestjs/swagger';

export async function setupOpenApi(app: any) {
Expand All @@ -15,23 +14,3 @@ export async function setupOpenApi(app: any) {
jsonDocumentUrl: '/openapi.json',
});
}

export async function setupAsyncApi(app: any) {
const asyncApiOptions = new AsyncApiDocumentBuilder()
.setTitle('Tonomy Communication service')
.setDescription(
'Communication service connects client browser to the app and sends notification to the tonomy id app',
)
.setDefaultContentType('application/json')
.addServer('users', {
protocol: 'socket.io',
url: 'localhost:5000',
})
.build();
const asyncapiDocument = await AsyncApiModule.createDocument(
app,
asyncApiOptions,
);

await AsyncApiModule.setup('/asyncapi', app, asyncapiDocument);
}
18 changes: 1 addition & 17 deletions src/communication/communication.gateway.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
UseGuards,
UsePipes,
} from '@nestjs/common';
import { AsyncApiPub } from 'nestjs-asyncapi';
import { TransformVcPipe } from './transform-vc/transform-vc.pipe';
import { MessageDto, MessageRto } from './dto/message.dto';
import { Client } from './dto/client.dto';
Expand All @@ -35,7 +34,7 @@ import { CommunicationGuard } from './communication.guard';
@UseFilters(new BaseWsExceptionFilter())
export class CommunicationGateway implements OnGatewayDisconnect {
private readonly logger = new Logger(CommunicationGateway.name);
constructor(private readonly usersService: CommunicationService) {}
constructor(private readonly usersService: CommunicationService) { }

/**
* Logs in the user and added it to the loggedIn map
Expand All @@ -45,13 +44,6 @@ export class CommunicationGateway implements OnGatewayDisconnect {
* @returns void
*/
@SubscribeMessage('login')
@AsyncApiPub({
channel: 'login',
message: {
payload: MessageRto,
},
description: 'login to the messaging service ',
})
connectUser(
@MessageBody() message: MessageDto,
@ConnectedSocket() client: Client,
Expand All @@ -74,14 +66,6 @@ export class CommunicationGateway implements OnGatewayDisconnect {
*/
@SubscribeMessage('message')
@UseGuards(CommunicationGuard)
@AsyncApiPub({
channel: 'message',
message: {
payload: MessageRto,
},
description:
'send message to client the message must be signed VC having a recipient',
})
relayMessage(
@MessageBody() message: MessageDto,
@ConnectedSocket() client: Client,
Expand Down
11 changes: 1 addition & 10 deletions src/communication/communication.service.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { HttpException, HttpStatus, Injectable, Logger } from '@nestjs/common';
import { AsyncApiSub, AsyncApi } from 'nestjs-asyncapi';
import { Socket } from 'socket.io';
import { Client } from './dto/client.dto';
import { MessageDto, MessageRto } from './dto/message.dto';
import { MessageDto } from './dto/message.dto';
import settings from '../settings';

@AsyncApi()
@Injectable()
export class CommunicationService {
private readonly logger = new Logger(CommunicationService.name);
Expand Down Expand Up @@ -44,13 +42,6 @@ export class CommunicationService {
* @throws if the receiving user isn't online or loggedIn
* @returns boolean if message is sent to the user
*/
@AsyncApiSub({
channel: 'message',
message: {
payload: MessageRto,
},
description: 'receive message from client',
})
sendMessage(socket: Client, message: MessageDto): boolean {
const recipient = this.loggedInUsers.get(message.getRecipient());

Expand Down
3 changes: 1 addition & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { setSettings } from '@tonomy/tonomy-id-sdk';
import settings from './settings';
import { setupAsyncApi, setupOpenApi } from './api';
import { setupOpenApi } from './api';
import helmet from 'helmet';

setSettings({
Expand All @@ -18,7 +18,6 @@ async function bootstrap() {
app.useGlobalPipes(new ValidationPipe({ transform: true }));

await setupOpenApi(app);
await setupAsyncApi(app);

await app.listen(5000);
}
Expand Down
Loading

0 comments on commit 75f313a

Please sign in to comment.