diff --git a/Dockerfile b/Dockerfile index 7f20c02..ac0b230 100644 --- a/Dockerfile +++ b/Dockerfile @@ -22,11 +22,10 @@ RUN yarn install --frozen-lockfile --production FROM base AS production COPY --from=prod-dependencies /root/cf-runtime/node_modules ./node_modules -COPY --from=build /root/cf-runtime/dist ./dist -COPY . . +COPY --from=build /root/cf-runtime/dist ./lib #purpose of security RUN npm -g uninstall npm USER cfu -CMD ["node", "dist/index.js"] +CMD ["node", "lib/index.js"] diff --git a/lib/forever.ps1 b/lib/forever.ps1 index 3e33432..45afb93 100644 --- a/lib/forever.ps1 +++ b/lib/forever.ps1 @@ -1,4 +1,4 @@ while ($true) { Start-Sleep -s 1 - & node dist/index.js + & node lib/index.js } diff --git a/lib/http-server/index.ts b/lib/http-server/index.ts index 5281f56..69868fe 100644 --- a/lib/http-server/index.ts +++ b/lib/http-server/index.ts @@ -14,7 +14,7 @@ export class HttpServer { private readonly port; private readonly server; - constructor(private taskLogger: any) { + constructor(private taskLogger?: any) { try { this.host = process.env.HOST || '0.0.0.0'; this.port = +(process.env.PORT || 8080); @@ -28,6 +28,10 @@ export class HttpServer { } } + setTaskLogger(taskLogger: any) { + this.taskLogger = taskLogger; + } + private initSecrets() { const secretsOptions = { schema: { @@ -44,8 +48,7 @@ export class HttpServer { this.server.post('/secrets', secretsOptions, async (request, reply) => { try { - const { body }: { body: any } = request; - const { secret } = body; + const { body: secret }: { body: any } = request; logger.info(`got request to add new mask: ${secret.key}`); this.taskLogger.addNewMask(secret); reply.code(201); diff --git a/lib/isReady.js b/lib/isReady.js index 5f3407e..93c3511 100644 --- a/lib/isReady.js +++ b/lib/isReady.js @@ -23,7 +23,7 @@ function isContainerLoggerReady(state) { (() => { const containerId = process.argv[2]; - const state = JSON.parse(readFileSync('./dist/state.json').toString('utf-8')); + const state = JSON.parse(readFileSync('./lib/state.json').toString('utf-8')); let isReady = false; if (containerId) { isReady = isContainerReady(state, containerId); diff --git a/lib/isReady.ps1 b/lib/isReady.ps1 index 421779d..efe297b 100644 --- a/lib/isReady.ps1 +++ b/lib/isReady.ps1 @@ -6,7 +6,7 @@ $CONTAINER_ID=$args[0] if ( $CONTAINER_ID ) { echo "checking if container:$CONTAINER_ID exists" - if (select-string -Pattern $CONTAINER_ID -Path ./dist/state.json) { + if (select-string -Pattern $CONTAINER_ID -Path ./lib/state.json) { echo "container $CONTAINER_ID is ready" Exit 0 } else { @@ -15,7 +15,7 @@ if ( $CONTAINER_ID ) { } } else { echo "checking if container logger is ready" - if (select-string -Pattern "ready" -Path ./dist/state.json) { + if (select-string -Pattern "ready" -Path ./lib/state.json) { echo "ready" Exit 0 } else { diff --git a/lib/isReady.sh b/lib/isReady.sh index 329e7ce..3032647 100755 --- a/lib/isReady.sh +++ b/lib/isReady.sh @@ -7,10 +7,10 @@ CONTAINER_ID=$1 if [ -n "$CONTAINER_ID" ]; then echo "checking if container: $CONTAINER_ID exists" - grep -q $CONTAINER_ID ./dist/state.json + grep -q $CONTAINER_ID ./lib/state.json else echo "checking if container logger is ready" - grep -q "ready" ./dist/state.json + grep -q "ready" ./lib/state.json fi diff --git a/lib/logger.js b/lib/logger.js index 5629975..dfc76f3 100644 --- a/lib/logger.js +++ b/lib/logger.js @@ -86,6 +86,7 @@ class Logger { TaskLogger(this.taskLoggerConfig.task, { ...this.taskLoggerConfig.opts, updateLogsRate: true }) .then((taskLogger) => { this.taskLogger = taskLogger; + this.httpServer.setTaskLogger(taskLogger); taskLogger.on('error', (err) => { logger.error(err.stack); }); diff --git a/package.json b/package.json index f4c0a29..7b087fb 100644 --- a/package.json +++ b/package.json @@ -53,6 +53,7 @@ "test:ci": "yarn test", "start": "node dist/index.js", "version": "exit 0", - "build": "rm -rf dist && tsc -p tsconfig.json" + "build": "rm -rf dist && tsc -p tsconfig.json && yarn run build:copy-scripts", + "build:copy-scripts": "cp ./lib/*.sh ./lib/*.ps1 ./dist" } } diff --git a/service.yaml b/service.yaml index fe4a291..ef2cb77 100644 --- a/service.yaml +++ b/service.yaml @@ -1 +1 @@ -version: 1.12.1 +version: 1.12.2