export type CreateApiBuildArgs = {dockerfile?: string | undefined, t?: string | undefined, extrahosts?: string | undefined, remote?: string | undefined, q?: boolean | undefined, nocache?: boolean | undefined, cachefrom?: string | undefined, pull?: string | undefined, rm?: boolean | undefined, forcerm?: boolean | undefined, memory?: number | undefined, memswap?: number | undefined, cpushares?: number | undefined, cpusetcpus?: string | undefined, cpuperiod?: number | undefined, cpuquota?: number | undefined, buildargs?: string | undefined, shmsize?: number | undefined, squash?: boolean | undefined, labels?: string | undefined, networkmode?: string | undefined, 'Content-type'?: 'application/x-tar' | undefined, 'X-Registry-Config'?: string | undefined, platform?: string | undefined, target?: string | undefined, outputs?: string | undefined, version?: ('1' | '2') | undefined, body: BodyInit}; export type CreateApiBuildOptions = {baseUrl: string, fetch?: typeof fetch | undefined}; /** * Build an image * * POST /build */ export const createApiBuild = async (args: CreateApiBuildArgs, options: CreateApiBuildOptions) => { const {baseUrl, fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/octet-stream") if (args.dockerfile != null) query.append("dockerfile", String(args.dockerfile)) if (args.t != null) query.append("t", String(args.t)) if (args.extrahosts != null) query.append("extrahosts", String(args.extrahosts)) if (args.remote != null) query.append("remote", String(args.remote)) if (args.q != null) query.append("q", String(args.q)) if (args.nocache != null) query.append("nocache", String(args.nocache)) if (args.cachefrom != null) query.append("cachefrom", String(args.cachefrom)) if (args.pull != null) query.append("pull", String(args.pull)) if (args.rm != null) query.append("rm", String(args.rm)) if (args.forcerm != null) query.append("forcerm", String(args.forcerm)) if (args.memory != null) query.append("memory", String(args.memory)) if (args.memswap != null) query.append("memswap", String(args.memswap)) if (args.cpushares != null) query.append("cpushares", String(args.cpushares)) if (args.cpusetcpus != null) query.append("cpusetcpus", String(args.cpusetcpus)) if (args.cpuperiod != null) query.append("cpuperiod", String(args.cpuperiod)) if (args.cpuquota != null) query.append("cpuquota", String(args.cpuquota)) if (args.buildargs != null) query.append("buildargs", String(args.buildargs)) if (args.shmsize != null) query.append("shmsize", String(args.shmsize)) if (args.squash != null) query.append("squash", String(args.squash)) if (args.labels != null) query.append("labels", String(args.labels)) if (args.networkmode != null) query.append("networkmode", String(args.networkmode)) if (args['Content-type'] != null) headers.set("Content-type", String(args['Content-type'])) if (args['X-Registry-Config'] != null) headers.set("X-Registry-Config", String(args['X-Registry-Config'])) if (args.platform != null) query.append("platform", String(args.platform)) if (args.target != null) query.append("target", String(args.target)) if (args.outputs != null) query.append("outputs", String(args.outputs)) if (args.version != null) query.append("version", String(args.version)) const url = `${baseUrl.replace(/\/+$/, '')}/build${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };