Skip to content

Commit

Permalink
fixup! feat(cli): build based on configuration
Browse files Browse the repository at this point in the history
suport to docker build context
  • Loading branch information
tuler committed Oct 11, 2024
1 parent 2173cc9 commit 8ec7c5b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 4 additions & 3 deletions apps/cli/src/builder/docker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { tarToExt } from "./index.js";

type ImageBuildOptions = Pick<
DockerDriveConfig,
"dockerfile" | "tags" | "target"
"context" | "dockerfile" | "tags" | "target"
>;

type ImageInfo = {
Expand All @@ -22,7 +22,7 @@ type ImageInfo = {
* Build Docker image (linux/riscv64). Returns image id.
*/
const buildImage = async (options: ImageBuildOptions): Promise<string> => {
const { dockerfile, tags, target } = options;
const { context, dockerfile, tags, target } = options;
const buildResult = tmp.tmpNameSync();
const args = [
"buildx",
Expand All @@ -32,6 +32,7 @@ const buildImage = async (options: ImageBuildOptions): Promise<string> => {
"--load",
"--iidfile",
buildResult,
context,
];

// set tags for the image built
Expand All @@ -41,7 +42,7 @@ const buildImage = async (options: ImageBuildOptions): Promise<string> => {
args.push("--target", target);
}

await execa("docker", [...args, process.cwd()], { stdio: "inherit" });
await execa("docker", args, { stdio: "inherit" });
return fs.readFileSync(buildResult, "utf8");
};

Expand Down
4 changes: 4 additions & 0 deletions apps/cli/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export type DirectoryDriveConfig = {

export type DockerDriveConfig = {
builder: "docker";
context: string;
dockerfile: string;
extraSize: number; // default is 0 (no extra size)
format: DriveFormat;
Expand Down Expand Up @@ -98,6 +99,7 @@ type TomlTable = { [key: string]: TomlPrimitive };

export const defaultRootDriveConfig = (): DriveConfig => ({
builder: "docker",
context: ".",
dockerfile: "Dockerfile", // file on current working directory
extraSize: 0,
format: DEFAULT_FORMAT,
Expand Down Expand Up @@ -333,6 +335,7 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
}
case "docker": {
const {
context,
dockerfile,
extraSize,
format,
Expand All @@ -346,6 +349,7 @@ const parseDrive = (drive: TomlPrimitive): DriveConfig => {
return {
builder: "docker",
image: parseOptionalString(image),
context: parseString(context, "."),
dockerfile: parseString(dockerfile, "Dockerfile"),
extraSize: parseBytes(extraSize, 0),
format: parseFormat(format),
Expand Down

0 comments on commit 8ec7c5b

Please sign in to comment.