From dad7220d0e0a52467bc6db25130d18ee98aebdde Mon Sep 17 00:00:00 2001 From: Alejo Thomas Ortega Date: Wed, 24 Jan 2024 09:14:37 -0300 Subject: [PATCH] init testcase --- .github/workflows/build-docker.yml | 7 +- Dockerfile | 4 +- consumer-server/src/components.ts | 17 +++-- consumer-server/src/logic/boot-validator.ts | 70 +++++++++++++++++++ consumer-server/src/logic/message-consumer.ts | 64 ++++++++--------- consumer-server/src/types.ts | 2 - 6 files changed, 120 insertions(+), 44 deletions(-) create mode 100644 consumer-server/src/logic/boot-validator.ts diff --git a/.github/workflows/build-docker.yml b/.github/workflows/build-docker.yml index 5d63e84f..d1fdd681 100644 --- a/.github/workflows/build-docker.yml +++ b/.github/workflows/build-docker.yml @@ -24,4 +24,9 @@ jobs: - name: Build Docker image run: docker build -t lods --build-arg VULKAN_DLL_PATH=./vulkan-sdt/1.3.268.0/runtime/x64/vulkan-1.dll . - + + - name: Execute test case | tmp + run: | + docker run -d -e HTTP_SERVER_PORT=8080 -e HTTP_SERVER_HOST=0.0.0.0 lods > container_id.txt + sleep 180 + docker logs $(cat container_id.txt) \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 8b7d3008..0312b860 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,5 +1,5 @@ # prepare base image for TS projects -FROM mcr.microsoft.com/windows/servercore:ltsc2019 as base +FROM mcr.microsoft.com/windows/nanoserver:ltsc2019 as base ADD https://aka.ms/vs/16/release/vc_redist.x64.exe C:\\vc_redist.x64.exe RUN C:\\vc_redist.x64.exe /quiet /install @@ -59,7 +59,7 @@ ARG VULKAN_DLL_PATH COPY ${VULKAN_DLL_PATH} ./publish/vulkan-1.dll # bundle all apps -FROM mcr.microsoft.com/windows:ltsc2019 +FROM mcr.microsoft.com/windows/nanoserver:ltsc2019 ADD https://aka.ms/vs/16/release/vc_redist.x64.exe C:\\vc_redist.x64.exe RUN C:\\vc_redist.x64.exe /quiet /install diff --git a/consumer-server/src/components.ts b/consumer-server/src/components.ts index f38d7a04..c54d7504 100644 --- a/consumer-server/src/components.ts +++ b/consumer-server/src/components.ts @@ -5,10 +5,12 @@ import { createMetricsComponent, instrumentHttpServerWithMetrics } from '@well-k import { AppComponents, GlobalContext } from './types' import { metricDeclarations } from './metrics' -import { createSqsAdapter } from './adapters/sqs' -import { createMessagesConsumerComponent } from './logic/message-consumer' +// import { createSqsAdapter } from './adapters/sqs' +// import { createMessagesConsumerComponent } from './logic/message-consumer' import { buildLicense } from './utils/license-builder' +import { validate } from './logic/boot-validator' + export async function initComponents(): Promise { const config = await createDotEnvConfigComponent({ path: ['.env.default', '.env'] }) @@ -19,8 +21,9 @@ export async function initComponents(): Promise { await instrumentHttpServerWithMetrics({ metrics, server, config }) - const queue = await createSqsAdapter({ config }) - const messageConsumer = await createMessagesConsumerComponent({ logs, queue }) + // const queue = await createSqsAdapter({ config }) + // const messageConsumer = await createMessagesConsumerComponent({ logs, queue }) + const result = await validate({ logs }) await buildLicense({ config, logs }) @@ -29,8 +32,8 @@ export async function initComponents(): Promise { logs, server, metrics, - statusChecks, - queue, - messageConsumer + statusChecks + // queue, + // messageConsumer } } diff --git a/consumer-server/src/logic/boot-validator.ts b/consumer-server/src/logic/boot-validator.ts new file mode 100644 index 00000000..540b2b9e --- /dev/null +++ b/consumer-server/src/logic/boot-validator.ts @@ -0,0 +1,70 @@ +import { exec } from 'child_process' +import path from 'path' +import fs from 'fs' +import os from 'os' + +import { AppComponents } from '../types' + +const projectRoot = path.resolve(__dirname, '..', '..', '..') +const lodGeneratorProgram = path.join(projectRoot, 'api', 'DCL_PiXYZ.exe') +const sceneLodEntitiesManifestBuilder = path.join(projectRoot, 'scene-lod') + +export async function validate({ logs }: Pick): Promise { + const logger = logs.getLogger('boot-validator') + + logger.info('Validating boot...') + + logger.info('Checking if PiXYZ is present at', { lodGeneratorProgram }) + if (fs.existsSync(lodGeneratorProgram)) { + logger.info('PiXYZ program found') + } else { + logger.error('PiXYZ program not found') + } + + if (fs.existsSync(sceneLodEntitiesManifestBuilder)) { + logger.info('Scene LOD Entities directory found') + } else { + logger.error('Scene LOD Entities directory not found') + } + + if (fs.existsSync(lodGeneratorProgram) && fs.existsSync(sceneLodEntitiesManifestBuilder)) { + logger.info('Executing test case...') + const outputPath = path.join(os.tmpdir(), 'output'); + if (!fs.existsSync(outputPath)) { + fs.mkdirSync(outputPath); + } + + const command = `${lodGeneratorProgram} "coords" "-129,-77" "50" ${sceneLodEntitiesManifestBuilder} "${outputPath}"` + // trigger exec asynchronously + await Promise.all([ + new Promise((resolve, _) => { + logger.info('Triggering command') + return exec(command, (error, stdout, stderr) => { + if (error) { + logger.error(`exec error: ${error}`) + resolve(false) + } + logger.info(`stdout: ${stdout}`) + logger.error(`stderr: ${stderr}`) + resolve(true) + }) + }) + ]) + + // await new Promise((resolve, reject) => { + // exec(command, (error, stdout, stderr) => { + // if (error) { + // logger.error(`exec error: ${error}`) + // resolve(false) + // } + // logger.info(`stdout: ${stdout}`) + // logger.error(`stderr: ${stderr}`) + // resolve(true) + // }) + // }) + // list files from outputPath + const files = fs.readdirSync(outputPath) + logger.info('Output files:', { files: JSON.stringify(files, null, 2) }) + } + process.exit(0) +} \ No newline at end of file diff --git a/consumer-server/src/logic/message-consumer.ts b/consumer-server/src/logic/message-consumer.ts index aec6b41d..175a8e14 100644 --- a/consumer-server/src/logic/message-consumer.ts +++ b/consumer-server/src/logic/message-consumer.ts @@ -1,36 +1,36 @@ -import { AppComponents, QueueWorker } from '../types' +// import { AppComponents, QueueWorker } from '../types' -export async function createMessagesConsumerComponent({ - logs, - queue -}: Pick): Promise { - const logger = logs.getLogger('messages-consumer') +// export async function createMessagesConsumerComponent({ +// logs, +// queue +// }: Pick): Promise { +// const logger = logs.getLogger('messages-consumer') - async function start() { - while (true) { - const messages = await queue.receiveSingleMessage() - for (const message of messages) { - const { MessageId, Body, ReceiptHandle } = message +// async function start() { +// while (true) { +// const messages = await queue.receiveSingleMessage() +// for (const message of messages) { +// const { MessageId, Body, ReceiptHandle } = message - try { - const parsedMessage: { Message: string } = JSON.parse(Body!) - logger.info('Handling message from queue', { - id: MessageId!, - message: parsedMessage.Message - }) - } catch (error: any) { - logger.error('Failed while handling message from queue', { - id: MessageId!, - error - }) - } finally { - await queue.deleteMessage(ReceiptHandle!) - } - } - } - } +// try { +// const parsedMessage: { Message: string } = JSON.parse(Body!) +// logger.info('Handling message from queue', { +// id: MessageId!, +// message: parsedMessage.Message +// }) +// } catch (error: any) { +// logger.error('Failed while handling message from queue', { +// id: MessageId!, +// error +// }) +// } finally { +// await queue.deleteMessage(ReceiptHandle!) +// } +// } +// } +// } - return { - start - } -} +// return { +// start +// } +// } diff --git a/consumer-server/src/types.ts b/consumer-server/src/types.ts index 6a848b1a..d97cdf91 100644 --- a/consumer-server/src/types.ts +++ b/consumer-server/src/types.ts @@ -19,8 +19,6 @@ export type BaseComponents = { logs: ILoggerComponent server: IHttpServerComponent metrics: IMetricsComponent - queue: QueueService - messageConsumer: QueueWorker } // components used in runtime