|
1 | 1 | import type { Context } from "../context.ts"; |
2 | 2 | import { Resource } from "../resource.ts"; |
| 3 | +import { Secret } from "../secret.ts"; |
3 | 4 | import { |
4 | 5 | DockerApi, |
5 | 6 | normalizeDuration, |
@@ -145,7 +146,7 @@ export interface ContainerProps { |
145 | 146 | /** |
146 | 147 | * Environment variables |
147 | 148 | */ |
148 | | - environment?: Record<string, string>; |
| 149 | + environment?: Record<string, string | Secret>; |
149 | 150 |
|
150 | 151 | /** |
151 | 152 | * Port mappings |
@@ -413,7 +414,7 @@ export const Container = Resource( |
413 | 414 | // Create new container |
414 | 415 | const containerId = await api.createContainer(imageRef, containerName, { |
415 | 416 | ports: portMappings, |
416 | | - env: props.environment, |
| 417 | + env: normalizeEnvironment(props.environment), |
417 | 418 | volumes: volumeMappings, |
418 | 419 | cmd: props.command, |
419 | 420 | healthcheck: props.healthcheck, |
@@ -530,7 +531,12 @@ function shouldReplace( |
530 | 531 | } |
531 | 532 |
|
532 | 533 | // Environment variables |
533 | | - if (!compareEnv(props.environment, containerInfo.Config.Env)) { |
| 534 | + if ( |
| 535 | + !compareEnv( |
| 536 | + normalizeEnvironment(props.environment), |
| 537 | + containerInfo.Config.Env, |
| 538 | + ) |
| 539 | + ) { |
534 | 540 | return true; |
535 | 541 | } |
536 | 542 |
|
@@ -566,6 +572,21 @@ function shouldReplace( |
566 | 572 | return false; |
567 | 573 | } |
568 | 574 |
|
| 575 | +/** |
| 576 | + * Unwrap secrets in given environment variables |
| 577 | + * @internal |
| 578 | + */ |
| 579 | +function normalizeEnvironment( |
| 580 | + environment: Record<string, string | Secret> | undefined, |
| 581 | +): Record<string, string> { |
| 582 | + return Object.fromEntries( |
| 583 | + Object.entries(environment ?? {}).map(([key, value]) => [ |
| 584 | + key, |
| 585 | + Secret.unwrap(value), |
| 586 | + ]), |
| 587 | + ); |
| 588 | +} |
| 589 | + |
569 | 590 | /** |
570 | 591 | * Normalize port mappings to a comparable format |
571 | 592 | * @internal |
|
0 commit comments