Arunachalam k
05/11/2024, 6:14 AM# Stage 1: Build Stage
FROM node:16 as build
WORKDIR /usr/src/app
COPY package.json package-lock.json ./
RUN npm install
COPY . ./
RUN npm run build
# Stage 2: Development Stage
FROM node:16-alpine as dev
WORKDIR /usr/src/app
COPY --from=build /usr/src/app ./
RUN rm -rf tests/
EXPOSE 8080
CMD ["npm", "run", "start"]
My scripts
"main": "index.js",
"scripts": {
"dev": "NODE_ENV=development nodemon src/server.ts",
"watch": "ts-node-dev -r tsconfig-paths/register -r -P tsconfig.json -r tracing.js src/server.ts",
"start": "node -r ./tsconfig-paths-bootstrap.js -r tracing.js dist/src/server.js",
"clean": "rimraf dist/",
"build": "tsc -p tsconfig.json --allowJs",
"postbuild": "npm run copy-json",
"copy-json": "copyfiles -u 1 src/**/*.json dist/src",
"copy-env": "cp example.env .env",
"pretest": "cross-env ENV=test npm migration:run",
"test": "cross-env ENV=test jest tests --forceExit --detectOpenHandles --runInBand",
"lint": "npx tsc --noEmit && eslint . --ext .js,.ts,.json --quiet",
"lint:fix": "eslint . --ext .js,.ts,.json --quiet --fix",
"migration:undoLatest": "sequelize-cli db:migrate:undo",
"migration:gen": "sequelize-cli migration:generate",
"migration:run": "sequelize-cli db:migrate",
"migration:seed": "sequelize-cli db:seed:all",
"jest:clear-cache": "jest --clearCache",
"prepare": "husky install"
},
tracing.js
// tracing.js
const process = require('process');
const { getNodeAutoInstrumentations } = require('@opentelemetry/auto-instrumentations-node');
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http');
const { Resource } = require('@opentelemetry/resources');
const opentelemetry = require('@opentelemetry/sdk-node');
const { SemanticResourceAttributes } = require('@opentelemetry/semantic-conventions');
const exporterOptions = {
url: '<http://localhost:4317/v1/traces>'
};
const traceExporter = new OTLPTraceExporter(exporterOptions);
const sdk = new opentelemetry.NodeSDK({
traceExporter,
instrumentations: [ getNodeAutoInstrumentations() ],
resource: new Resource({
[SemanticResourceAttributes.SERVICE_NAME]: 'node_app'
})
});
// initialize the SDK and register with the OpenTelemetry API
// this enables the API to record telemetry
sdk.start();
// gracefully shut down the SDK on process exit
process.on('SIGTERM', () => {
sdk.shutdown()
.then(() => console.log('Tracing terminated'))
.catch((error) => console.log('Error terminating tracing', error))
// eslint-disable-next-line no-process-exit
.finally(() => process.exit(0));
});
Arunachalam k
05/11/2024, 6:15 AMjohn doe
05/13/2024, 9:51 AM