feat: docker support
This commit is contained in:
6
.dockerignore
Normal file
6
.dockerignore
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
*
|
||||||
|
!/bin/
|
||||||
|
!/src
|
||||||
|
!/package.json
|
||||||
|
!/pnpm-lock.yaml
|
||||||
|
!/tsconfig.json
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
FROM node:23-slim
|
||||||
|
RUN corepack enable
|
||||||
|
WORKDIR /app
|
||||||
|
COPY package.json pnpm-lock.yaml ./
|
||||||
|
RUN pnpm install --frozen-lockfile --prod
|
||||||
|
COPY . .
|
||||||
|
RUN chmod +x /app/bin/start.js
|
||||||
|
CMD ["/app/bin/start.js"]
|
||||||
|
|||||||
2
bin/start.js
Normal file
2
bin/start.js
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
#!/usr/local/bin/node --no-warnings
|
||||||
|
import '../src/start.ts';
|
||||||
12
docker-compose.yaml
Normal file
12
docker-compose.yaml
Normal file
@@ -0,0 +1,12 @@
|
|||||||
|
name: backbone
|
||||||
|
services:
|
||||||
|
app:
|
||||||
|
build:
|
||||||
|
context: .
|
||||||
|
environment:
|
||||||
|
HTTP_ENABLED: 'true'
|
||||||
|
TCP_ENABLED: 'true'
|
||||||
|
TOKEN_SECRET: 'test'
|
||||||
|
ports:
|
||||||
|
- 1883:1883
|
||||||
|
- 8883:8883
|
||||||
@@ -2,6 +2,7 @@
|
|||||||
"type": "module",
|
"type": "module",
|
||||||
"main": "dist/exports.js",
|
"main": "dist/exports.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
"dev": "node --no-warnings --watch src/start.ts",
|
||||||
"test:lint": "eslint",
|
"test:lint": "eslint",
|
||||||
"build": "tsc --build",
|
"build": "tsc --build",
|
||||||
"test:unit": "vitest --run --passWithNoTests",
|
"test:unit": "vitest --run --passWithNoTests",
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { AccessHandler } from './access/access.handler.ts';
|
import { AccessHandler } from './access/access.handler.ts';
|
||||||
|
import { Config } from './config/config.ts';
|
||||||
import { K8sService } from './k8s/k8s.ts';
|
import { K8sService } from './k8s/k8s.ts';
|
||||||
import { MqttServer } from './server/server.ts';
|
import { MqttServer } from './server/server.ts';
|
||||||
import { TopicsHandler } from './topics/topics.handler.ts';
|
import { TopicsHandler } from './topics/topics.handler.ts';
|
||||||
@@ -15,6 +16,10 @@ class Backbone {
|
|||||||
return this.#services;
|
return this.#services;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public get config() {
|
||||||
|
return this.services.get(Config);
|
||||||
|
}
|
||||||
|
|
||||||
public get server() {
|
public get server() {
|
||||||
return this.#services.get(MqttServer);
|
return this.#services.get(MqttServer);
|
||||||
}
|
}
|
||||||
@@ -31,10 +36,29 @@ class Backbone {
|
|||||||
return this.#services.get(K8sService);
|
return this.#services.get(K8sService);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public start = async () => {
|
||||||
|
if (this.config.k8s.enabled) {
|
||||||
|
await this.setupK8sOperator();
|
||||||
|
}
|
||||||
|
if (this.config.http.enabled) {
|
||||||
|
console.log('starting http');
|
||||||
|
const http = await this.server.getHttpServer();
|
||||||
|
http.listen({ port: this.config.http.port, host: '0.0.0.0' });
|
||||||
|
}
|
||||||
|
if (this.config.tcp) {
|
||||||
|
const tcp = this.server.getTcpServer();
|
||||||
|
tcp.listen(this.config.tcp.port);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
public setupK8sOperator = async () => {
|
public setupK8sOperator = async () => {
|
||||||
await this.k8s.setup();
|
await this.k8s.setup();
|
||||||
this.accessHandler.register('k8s', this.k8s.clients);
|
this.accessHandler.register('k8s', this.k8s.clients);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public destroy = async () => {
|
||||||
|
await this.services.destroy();
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export { Backbone };
|
export { Backbone };
|
||||||
|
|||||||
32
src/config/config.ts
Normal file
32
src/config/config.ts
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
class Config {
|
||||||
|
public get tokenSecret() {
|
||||||
|
return process.env.TOKEN_SECRET;
|
||||||
|
}
|
||||||
|
|
||||||
|
public get k8s() {
|
||||||
|
const enabled = process.env.K8S_ENABLED === 'true';
|
||||||
|
return {
|
||||||
|
enabled,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public get http() {
|
||||||
|
const enabled = (process.env.HTTP_ENABLED = 'true');
|
||||||
|
const port = process.env.HTTP_PORT ? parseInt(process.env.HTTP_PORT) : 8883;
|
||||||
|
return {
|
||||||
|
enabled,
|
||||||
|
port,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public get tcp() {
|
||||||
|
const enabled = (process.env.TCP_ENABLED = 'true');
|
||||||
|
const port = process.env.TCP_PORT ? parseInt(process.env.TCP_PORT) : 1883;
|
||||||
|
return {
|
||||||
|
enabled,
|
||||||
|
port,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export { Config };
|
||||||
6
src/start.ts
Normal file
6
src/start.ts
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
import { Backbone } from './backbone.ts';
|
||||||
|
|
||||||
|
const backbone = new Backbone();
|
||||||
|
await backbone.start();
|
||||||
|
|
||||||
|
console.log('started');
|
||||||
11
src/test.ts
11
src/test.ts
@@ -1,11 +0,0 @@
|
|||||||
import { Backbone } from './backbone.ts';
|
|
||||||
|
|
||||||
const backbone = new Backbone();
|
|
||||||
await backbone.setupK8sOperator();
|
|
||||||
|
|
||||||
const tcp = backbone.server.getTcpServer();
|
|
||||||
tcp.listen(1883);
|
|
||||||
const http = await backbone.server.getHttpServer();
|
|
||||||
http.listen({ port: 8883 });
|
|
||||||
|
|
||||||
console.log('started');
|
|
||||||
Reference in New Issue
Block a user