Skip to content

Commit 643bf36

Browse files
authored
docker apply env on commands where we are using '-e' (actions#11)
* added wrapper for docker -e to apply env * added envs around services as well * added wrapping environment around execute command * fixed setting the env variable for containerRun * added env to exec and not to handle envs by ourself * returned back the comment to run-container-step
1 parent de59bd8 commit 643bf36

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

packages/docker/src/dockerCommands/container.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ export async function createContainer(
6969
}
7070
}
7171

72-
const id = (await runDockerCommand(dockerArgs)).trim()
72+
const id = (
73+
await runDockerCommand(dockerArgs, { env: args.environmentVariables })
74+
).trim()
7375
if (!id) {
7476
throw new Error('Could not read id from docker command')
7577
}
@@ -352,7 +354,7 @@ export async function containerExecStep(
352354
for (const entryPointArg of args.entryPointArgs) {
353355
dockerArgs.push(entryPointArg)
354356
}
355-
await runDockerCommand(dockerArgs)
357+
await runDockerCommand(dockerArgs, { env: args.environmentVariables })
356358
}
357359

358360
export async function containerRun(
@@ -376,9 +378,7 @@ export async function containerRun(
376378
dockerArgs.push(...args.createOptions.split(' '))
377379
}
378380
if (args.environmentVariables) {
379-
for (const [key, value] of Object.entries(args.environmentVariables)) {
380-
// Pass in this way to avoid printing secrets
381-
env[key] = value ?? undefined
381+
for (const [key] of Object.entries(args.environmentVariables)) {
382382
dockerArgs.push('-e')
383383
dockerArgs.push(key)
384384
}
@@ -408,7 +408,7 @@ export async function containerRun(
408408
}
409409
}
410410

411-
await runDockerCommand(dockerArgs)
411+
await runDockerCommand(dockerArgs, { env: args.environmentVariables })
412412
}
413413

414414
export async function isContainerAlpine(containerId: string): Promise<boolean> {

packages/docker/src/hooks/prepare-job.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ export async function prepareJob(
4848
} finally {
4949
await registryLogout(configLocation)
5050
}
51+
5152
containerMetadata = await createContainer(
5253
container,
5354
generateContainerName(container.image),
@@ -78,6 +79,7 @@ export async function prepareJob(
7879
generateContainerName(service.image),
7980
networkName
8081
)
82+
8183
servicesMetadata.push(response)
8284
await containerStart(response.id)
8385
}

packages/docker/src/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const exec = require('@actions/exec')
99
export interface RunDockerCommandOptions {
1010
workingDir?: string
1111
input?: Buffer
12+
env?: { [key: string]: string }
1213
}
1314

1415
export async function runDockerCommand(

0 commit comments

Comments
 (0)