Skip to content

Commit

Permalink
fix(openfaas): build function before getting container build status
Browse files Browse the repository at this point in the history
  • Loading branch information
eysi09 authored and edvald committed Aug 22, 2019
1 parent de4d4a8 commit 4693f13
Showing 1 changed file with 22 additions and 6 deletions.
28 changes: 22 additions & 6 deletions garden-service/src/plugins/openfaas/build.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,25 @@ import { containerHelpers } from "../container/helpers"
import { k8sBuildContainer, k8sGetContainerBuildStatus } from "../kubernetes/container/build"
import { GetBuildStatusParams } from "../../types/plugin/module/getBuildStatus"
import { OpenFaasModule, getK8sProvider, getContainerModule, OpenFaasProvider } from "./config"
import { LogEntry } from "../../logger/log-entry"

export const stackFilename = "stack.yml"

export async function getOpenfaasModuleBuildStatus({ ctx, log, module }: GetBuildStatusParams<OpenFaasModule>) {
const containerModule = getContainerModule(module)
const k8sProvider = getK8sProvider(ctx.provider.dependencies)
const k8sCtx = { ...ctx, provider: k8sProvider }

// We need to do an OpenFaas build before getting the container build status
await buildOpenfaasFunction(<OpenFaasProvider>ctx.provider, k8sProvider, module, log)

return k8sGetContainerBuildStatus({ ctx: k8sCtx, log, module: containerModule })
}

export async function buildOpenfaasModule({ ctx, log, module }: BuildModuleParams<OpenFaasModule>) {
const k8sProvider = getK8sProvider(ctx.provider.dependencies)
await writeStackFile(<OpenFaasProvider>ctx.provider, k8sProvider, module, {})

const buildLog = await faasCli.stdout({
log,
cwd: module.buildPath,
args: ["build", "--shrinkwrap", "-f", stackFilename],
})
const buildLog = await buildOpenfaasFunction(<OpenFaasProvider>ctx.provider, k8sProvider, module, log)

const containerModule = getContainerModule(module)
const k8sCtx = { ...ctx, provider: k8sProvider }
Expand Down Expand Up @@ -67,6 +67,22 @@ export async function writeStackFile(
})
}

/**
* Writes the stack file and builds the OpenFaaS function container with the OpenFaaS CLI
*/
async function buildOpenfaasFunction(
provider: OpenFaasProvider, k8sProvider: KubernetesProvider, module: OpenFaasModule, log: LogEntry,
) {
await writeStackFile(provider, k8sProvider, module, {})

return await faasCli.stdout({
log,
cwd: module.buildPath,
args: ["build", "--shrinkwrap", "-f", stackFilename],
})

}

function getExternalGatewayUrl(provider: OpenFaasProvider) {
const k8sProvider = getK8sProvider(provider.dependencies)
const hostname = provider.config.hostname
Expand Down

0 comments on commit 4693f13

Please sign in to comment.