Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(seed): Always include docker logs #4784

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
},
"dependencies": {
"@fern-api/fs-utils": "workspace:*",
"@fern-api/logger": "workspace:*",
"dockerode": "^4.0.2",
"tmp-promise": "^3.0.3"
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { AbsoluteFilePath, doesPathExist, join, RelativeFilePath } from "@fern-api/fs-utils";
import { CONSOLE_LOGGER } from "@fern-api/logger";
import { exec } from "child_process";
import { mkdir, rm } from "fs/promises";
import path from "path";
Expand Down Expand Up @@ -33,6 +34,7 @@ describe("runDocker", () => {
const expectedOutputFilePath = "my-file.txt";

await runDocker({
logger: CONSOLE_LOGGER,
imageName: BASIC_WRITER_IMAGE_NAME,
args: [expectedOutputFilePath],
binds: [`${HOST_OUTPUT_DIR}:${IMAGE_OUTPUT_DIR}`]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { Logger } from "@fern-api/logger";
import Docker from "dockerode";
import { writeFile } from "fs/promises";
import { Writable } from "stream";
import tmp from "tmp-promise";

export declare namespace runDocker {
export interface Args {
logger: Logger;
imageName: string;
args?: string[];
binds?: string[];
Expand All @@ -18,14 +20,16 @@ export declare namespace runDocker {
}

export async function runDocker({
logger,
imageName,
args,
binds,
writeLogsToFile = true,
removeAfterCompletion = false
}: runDocker.Args): Promise<void> {
const docker = new Docker();
const tryRun = () => tryRunDocker({ docker, imageName, args, binds, removeAfterCompletion, writeLogsToFile });
const tryRun = () =>
tryRunDocker({ logger, docker, imageName, args, binds, removeAfterCompletion, writeLogsToFile });
try {
await tryRun();
} catch (e) {
Expand All @@ -41,13 +45,15 @@ export async function runDocker({

// may throw a 404 if the image hasn't been downloaded
async function tryRunDocker({
logger,
docker,
imageName,
args,
binds,
removeAfterCompletion,
writeLogsToFile
}: {
logger: Logger;
docker: Docker;
imageName: string;
args?: string[];
Expand Down Expand Up @@ -81,14 +87,14 @@ async function tryRunDocker({
throw status.Error;
}

if (writeLogsToFile) {
const tmpFile = await tmp.file();
await writeFile(tmpFile.path, logs);
logger.info(`Generator logs here: ${tmpFile.path}`);
}

if (status.StatusCode !== 0) {
if (writeLogsToFile) {
const tmpFile = await tmp.file();
await writeFile(tmpFile.path, logs);
throw new Error(`Docker exited with a non-zero exit code. Logs here: ${tmpFile.path}`);
} else {
throw new Error("Docker exited with a non-zero exit code.");
}
throw new Error("Docker exited with a non-zero exit code.");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,7 @@ export async function runGenerator({
absolutePathToIr,
absolutePathToWriteConfigJson,
keepDocker,
context,
generatorInvocation,
writeUnitTests,
generateOauthClients,
Expand Down Expand Up @@ -238,6 +239,7 @@ export async function runGenerator({
}

await runDocker({
logger: context.logger,
imageName,
args: [DOCKER_GENERATOR_CONFIG_PATH],
binds,
Expand Down
3 changes: 3 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading