@tahminator/pipeline 1.0.103 → 1.0.104

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -447,6 +447,8 @@ await client.buildImage({
447
447
  tags: ["latest", "sha-abc123"], // define as many as you would like
448
448
  platforms: ["linux/amd64", "linux/arm64"], // build for multiple platforms
449
449
  buildArgs: { NODE_ENV: "production" }, // pass in build args
450
+ // read in the Dockerfile with `RUN --mount=type=secret,id=NPM_TOKEN`
451
+ secrets: { NPM_TOKEN: process.env.NPM_TOKEN! },
450
452
  });
451
453
 
452
454
  await client.buildImage({
@@ -35,6 +35,11 @@ export declare class DockerClient {
35
35
  shouldUpload?: boolean;
36
36
  platforms?: string[];
37
37
  buildArgs?: Record<string, string | number | boolean>;
38
+ /**
39
+ * BuildKit secrets keyed by id, readable in the Dockerfile via `RUN --mount=type=secret,id=<id>`.
40
+ * Values are handed to `docker buildx build` through environment variables, so they never reach argv or disk.
41
+ */
42
+ secrets?: Record<string, string>;
38
43
  }): Promise<void>;
39
44
  [Symbol.asyncDispose](): Promise<void>;
40
45
  cleanup(): Promise<void>;
@@ -41,7 +41,7 @@ export class DockerClient {
41
41
  console.log(`Promoted ${originalTag} to: ${newGithubTags.join(", ")}`);
42
42
  }
43
43
  async buildImage(args) {
44
- const { dockerFileLocation, tags, dockerRepository, shouldUpload = true, platforms = ["linux/amd64"], buildArgs = {}, } = args;
44
+ const { dockerFileLocation, tags, dockerRepository, shouldUpload = true, platforms = ["linux/amd64"], buildArgs = {}, secrets = {}, } = args;
45
45
  if (!tags.length) {
46
46
  throw new Error("You must provide atleast one tag.");
47
47
  }
@@ -65,16 +65,23 @@ export class DockerClient {
65
65
  "--build-arg",
66
66
  `${k}=${v.toString()}`,
67
67
  ]);
68
+ const secretEnv = {};
69
+ const secretFlags = Object.entries(secrets).flatMap(([id, value], i) => {
70
+ const envName = `PIPELINE_DOCKER_BUILD_SECRET_${i}`;
71
+ secretEnv[envName] = value;
72
+ return ["--secret", `id=${id},env=${envName}`];
73
+ });
68
74
  await $ `docker buildx build ${buildModeFlag} \
69
75
  --platform ${platforms.join(",")} \
70
76
  --file ${dockerFileLocation} \
71
77
  --cache-from=type=gha \
72
78
  --cache-to=type=gha,mode=max \
73
79
  ${buildArgFlags} \
80
+ ${secretFlags} \
74
81
  --network host \
75
82
  --allow network.host \
76
83
  ${tagFlags} \
77
- .`;
84
+ .`.env({ ...process.env, ...secretEnv });
78
85
  console.log(shouldUpload
79
86
  ? `Image build & successfully uploaded to ${this.username}/${dockerRepository}`
80
87
  : "Image has been built (upload skipped.)");
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tahminator/pipeline",
3
- "version": "1.0.103",
3
+ "version": "1.0.104",
4
4
  "description": "A collection of Bun shell scripts that can be re-used in various CICD pipelines.",
5
5
  "author": "Tahmid Ahmed",
6
6
  "repository": {