Skip to content

Commit

Permalink
Prefix proxy and updater logs
Browse files Browse the repository at this point in the history
  • Loading branch information
Jurre Stender committed Aug 12, 2021
1 parent 1b8f44f commit a70f3f2
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
7 changes: 6 additions & 1 deletion src/container-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion src/proxy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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`
Expand Down
19 changes: 19 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import stream, {Writable} from 'stream'
import {DependencyFile} from './file-types'

const base64Decode = (str: string): string =>
Expand All @@ -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()
}
})
}

0 comments on commit a70f3f2

Please sign in to comment.