diff --git a/README.md b/README.md index 11cec7e..d99a904 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,7 @@ repo( image( src: Directory | string, exitCode?: number, + image?: string, format?: string, output?: string ): Promise diff --git a/example/.fluentci/mod.ts b/example/.fluentci/mod.ts index 52470dd..fbc1f17 100644 --- a/example/.fluentci/mod.ts +++ b/example/.fluentci/mod.ts @@ -1,3 +1 @@ export * from "./src/dagger/index.ts"; -export * as queries from "./src/dagger/queries.ts"; -export { schema } from "./src/dagger/schema.ts"; diff --git a/example/.fluentci/src/dagger/jobs.ts b/example/.fluentci/src/dagger/jobs.ts index cd39e3a..88c8efe 100644 --- a/example/.fluentci/src/dagger/jobs.ts +++ b/example/.fluentci/src/dagger/jobs.ts @@ -1,4 +1,4 @@ -import Client, { Directory } from "../../deps.ts"; +import Client, { Directory, File } from "../../deps.ts"; import { connect } from "../../sdk/connect.ts"; import { getDirectory } from "./lib.ts"; @@ -19,14 +19,15 @@ export const exclude = [".fluentci"]; * @param {number} exitCode * @param {string} format * @param {string} output - * @returns {Promise} + * @returns {Promise} */ export async function config( src: Directory | string, exitCode?: number, format?: string, output?: string -): Promise { +): Promise { + let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); const args = ["config", "."]; @@ -48,11 +49,10 @@ export async function config( .withWorkdir("/app") .withExec(args); - const result = await ctr.stdout(); - - console.log(result); + await ctr.stdout(); + id = await ctr.file(`/app/${output}`).id(); }); - return "Done"; + return id; } /** @@ -62,14 +62,15 @@ export async function config( * @param {number} exitCode * @param {string} format * @param {string} output - * @returns {Promise} + * @returns {Promise} */ export async function fs( src: Directory | string, exitCode?: number, format?: string, output?: string -): Promise { +): Promise { + let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); const args = ["fs", "."]; @@ -91,11 +92,11 @@ export async function fs( .withWorkdir("/app") .withExec(args); - const result = await ctr.stdout(); + await ctr.stdout(); - console.log(result); + id = await ctr.file(`/app/${output}`).id(); }); - return "Done"; + return id; } /** @@ -106,7 +107,7 @@ export async function fs( * @param {string} repoUrl * @param {string} format * @param {string} output - * @returns {Promise} + * @returns {Promise} */ export async function repo( src: Directory | string, @@ -114,7 +115,8 @@ export async function repo( repoUrl?: string, format?: string, output?: string -): Promise { +): Promise { + let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); const args = ["repo", Deno.env.get("TRIVY_REPO_URL") || repoUrl || "."]; @@ -135,12 +137,11 @@ export async function repo( .withDirectory("/app", context, { exclude }) .withWorkdir("/app") .withExec(args); + await ctr.stdout(); - const result = await ctr.stdout(); - - console.log(result); + id = await ctr.file(`/app/${output}`).id(); }); - return "Done"; + return id; } /** @@ -151,7 +152,7 @@ export async function repo( * @param {string} image * @param {string} format * @param {string} output - * @returns {Promise} + * @returns {Promise} */ export async function image( src: Directory | string, @@ -159,7 +160,8 @@ export async function image( image?: string, format?: string, output?: string -): Promise { +): Promise { + let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); if (!Deno.env.has("TRIVY_IMAGE") && !image) { @@ -187,11 +189,10 @@ export async function image( .withWorkdir("/app") .withExec(args); - const result = await ctr.stdout(); - - console.log(result); + await ctr.stdout(); + id = await ctr.file(`/app/${output}`).id(); }); - return "Done"; + return id; } /** @@ -202,7 +203,7 @@ export async function image( * @param {string} path * @param {string} format * @param {string} output - * @returns {Promise} + * @returns {Promise} */ export async function sbom( src: Directory | string, @@ -210,7 +211,8 @@ export async function sbom( path?: string, format?: string, output?: string -): Promise { +): Promise { + let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); if (!Deno.env.has("TRIVY_SBOM_PATH") && !path) { @@ -237,11 +239,10 @@ export async function sbom( .withWorkdir("/app") .withExec(args); - const result = await ctr.stdout(); - - console.log(result); + await ctr.stdout(); + id = await ctr.file(`/app/${output}`).id(); }); - return "Done"; + return id; } export type JobExec = ( @@ -250,7 +251,7 @@ export type JobExec = ( path?: string, format?: string, output?: string -) => Promise; +) => Promise; export const runnableJobs: Record = { [Job.config]: config, diff --git a/example/.fluentci/src/dagger/queries.ts b/example/.fluentci/src/dagger/queries.ts deleted file mode 100644 index ab7ce92..0000000 --- a/example/.fluentci/src/dagger/queries.ts +++ /dev/null @@ -1,31 +0,0 @@ -import { gql } from "../../deps.ts"; - -export const config = gql` - query config($src: String!, $exitCode: Int!) { - config(src: $src, exitCode: $exitCode) - } -`; - -export const fs = gql` - query fs($src: String!, $exitCode: Int!) { - fs(src: $src, exitCode: $exitCode) - } -`; - -export const repo = gql` - query repo($src: String!, $exitCode: Int!, $repoUrl: String!) { - repo(src: $src, exitCode: $exitCode, repoUrl: $repoUrl) - } -`; - -export const image = gql` - query image($src: String!, $exitCode: Int!, $image: String!) { - image(src: $src, exitCode: $exitCode, image: $image) - } -`; - -export const sbom = gql` - query sbom($src: String!, $exitCode: Int!, $path: String!) { - sbom(src: $src, exitCode: $exitCode, path: $path) - } -`; diff --git a/example/.fluentci/src/dagger/schema.ts b/example/.fluentci/src/dagger/schema.ts deleted file mode 100644 index c98a692..0000000 --- a/example/.fluentci/src/dagger/schema.ts +++ /dev/null @@ -1,67 +0,0 @@ -import { - queryType, - makeSchema, - dirname, - join, - resolve, - stringArg, - nonNull, - intArg, -} from "../../deps.ts"; - -import { config, fs, repo, image, sbom } from "./jobs.ts"; - -const Query = queryType({ - definition(t) { - t.string("config", { - args: { - src: nonNull(stringArg()), - exitCode: nonNull(intArg()), - }, - resolve: async (_root, args, _ctx) => - await config(args.src, args.exitCode), - }); - t.string("fs", { - args: { - src: nonNull(stringArg()), - exitCode: nonNull(intArg()), - }, - resolve: async (_root, args, _ctx) => await fs(args.src, args.exitCode), - }); - t.string("repo", { - args: { - src: nonNull(stringArg()), - exitCode: nonNull(intArg()), - repoUrl: nonNull(stringArg()), - }, - resolve: async (_root, args, _ctx) => - await repo(args.src, args.exitCode, args.repoUrl), - }); - t.string("image", { - args: { - src: nonNull(stringArg()), - exitCode: nonNull(intArg()), - image: nonNull(stringArg()), - }, - resolve: async (_root, args, _ctx) => - await image(args.src, args.exitCode, args.image), - }); - t.string("sbom", { - args: { - src: nonNull(stringArg()), - exitCode: nonNull(intArg()), - path: nonNull(stringArg()), - }, - resolve: async (_root, args, _ctx) => - await sbom(args.src, args.exitCode, args.path), - }); - }, -}); - -export const schema = makeSchema({ - types: [Query], - outputs: { - schema: resolve(join(dirname(".."), dirname(".."), "schema.graphql")), - typegen: resolve(join(dirname(".."), dirname(".."), "gen", "nexus.ts")), - }, -}); diff --git a/src/dagger/jobs.ts b/src/dagger/jobs.ts index 3d0502c..88c8efe 100644 --- a/src/dagger/jobs.ts +++ b/src/dagger/jobs.ts @@ -69,7 +69,7 @@ export async function fs( exitCode?: number, format?: string, output?: string -): Promise { +): Promise { let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); @@ -115,7 +115,7 @@ export async function repo( repoUrl?: string, format?: string, output?: string -): Promise { +): Promise { let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src); @@ -160,7 +160,7 @@ export async function image( image?: string, format?: string, output?: string -): Promise { +): Promise { let id = ""; await connect(async (client: Client) => { const context = getDirectory(client, src);