From a70f3f213d54189ddfd9997a160accf3d1742c66 Mon Sep 17 00:00:00 2001 From: Jurre Stender Date: Wed, 11 Aug 2021 23:59:27 +0200 Subject: [PATCH] Prefix proxy and updater logs --- src/container-service.ts | 7 ++++++- src/proxy.ts | 7 ++++++- src/utils.ts | 19 +++++++++++++++++++ 3 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/container-service.ts b/src/container-service.ts index e025fd9..59ce2f0 100644 --- a/src/container-service.ts +++ b/src/container-service.ts @@ -2,6 +2,7 @@ import * as core from '@actions/core' import {Container} from 'dockerode' import {pack} from 'tar-stream' import {FileFetcherInput, FileUpdaterInput, ProxyConfig} from './file-types' +import {outStream, errStream} from './utils' export const ContainerService = { async storeInput( @@ -35,7 +36,11 @@ export const ContainerService = { stdout: true, stderr: true }) - container.modem.demuxStream(stream, process.stdout, process.stderr) + container.modem.demuxStream( + stream, + outStream('updater'), + errStream('updater') + ) await container.start() await container.wait() diff --git a/src/proxy.ts b/src/proxy.ts index d43392f..b599bc0 100644 --- a/src/proxy.ts +++ b/src/proxy.ts @@ -9,6 +9,7 @@ import { import {ContainerService} from './container-service' import {Credential, JobDetails} from './api-client' import {pki} from 'node-forge' +import {outStream, errStream} from './utils' const KEY_SIZE = 2048 const KEY_EXPIRY_YEARS = 2 @@ -77,7 +78,11 @@ export class ProxyBuilder { stdout: true, stderr: true }) - container.modem.demuxStream(stream, process.stdout, process.stderr) + container.modem.demuxStream( + stream, + outStream(' proxy'), + errStream(' proxy') + ) container.start() const url = `http://${config.proxy_auth.username}:${config.proxy_auth.password}@${name}:1080` diff --git a/src/utils.ts b/src/utils.ts index 3d5ef4f..823a491 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -1,3 +1,4 @@ +import stream, {Writable} from 'stream' import {DependencyFile} from './file-types' const base64Decode = (str: string): string => @@ -10,3 +11,21 @@ export const base64DecodeDependencyFile = ( fileCopy.content = base64Decode(fileCopy.content) return fileCopy } + +export const outStream = (prefix: string): Writable => { + return new stream.Writable({ + write(chunk, _, next) { + process.stderr.write(`${prefix} | ${chunk.toString()}`) + next() + } + }) +} + +export const errStream = (prefix: string): Writable => { + return new stream.Writable({ + write(chunk, _, next) { + process.stderr.write(`${prefix} | ${chunk.toString()}`) + next() + } + }) +}