Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add integration test
Browse files Browse the repository at this point in the history
Mitchell Friedman committed Mar 23, 2020

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
1 parent 90980a6 commit 823a596
Showing 3 changed files with 74 additions and 18 deletions.
25 changes: 14 additions & 11 deletions garden-service/src/plugins/kubernetes/commands/pull-image.ts
Original file line number Diff line number Diff line change
@@ -23,6 +23,7 @@ import { PodRunner } from "../run"
import { inClusterRegistryHostname } from "../constants"
import { getAppNamespace, getSystemNamespace } from "../namespace"
import { makePodName, skopeoImage, getSkopeoContainer, getDockerAuthVolume } from "../util"
import { getRegistryPortForward } from "../container/util"

export const pullImage: PluginCommand = {
name: "pull-image",
@@ -96,21 +97,23 @@ async function pullModules(ctx: KubernetesPluginContext, modules: Module[], log:

async function pullModule(ctx: KubernetesPluginContext, module: Module, log: LogEntry) {
if (ctx.provider.config.deploymentRegistry?.hostname === inClusterRegistryHostname) {
await pullFromInClusterRegistry(module, log)
await pullFromInClusterRegistry(ctx, module, log)
} else {
await pullFromExternalRegistry(ctx, module, log)
}
}

async function pullFromInClusterRegistry(module: Module, log: LogEntry) {
const localId = await containerHelpers.getLocalImageId(module)
const remoteId = await containerHelpers.getPublicImageId(module)

await containerHelpers.dockerCli(module.buildPath, ["pull", remoteId], log)
export async function pullFromInClusterRegistry(k8sCtx: KubernetesPluginContext, module: Module, log: LogEntry) {
const fwd = await getRegistryPortForward(k8sCtx, log)
const imageId = await containerHelpers.getDeploymentImageId(module, k8sCtx.provider.config.deploymentRegistry)
const pullImageName = containerHelpers.unparseImageId({
...containerHelpers.parseImageId(imageId),
// Note: using localhost directly here has issues with Docker for Mac.
// https://github.com/docker/for-mac/issues/3611
host: `local.app.garden:${fwd.localPort}`,
})

if (localId !== remoteId) {
await containerHelpers.dockerCli(module.buildPath, ["tag", remoteId, localId], log)
}
await containerHelpers.dockerCli(module.buildPath, ["pull", pullImageName], log)
}

async function pullFromExternalRegistry(ctx: KubernetesPluginContext, module: Module, log: LogEntry) {
@@ -144,13 +147,13 @@ async function pullFromExternalRegistry(ctx: KubernetesPluginContext, module: Mo

async function importImage(module: Module, runner: PodRunner, tarName: string, imageId: string, log: LogEntry) {
const sourcePath = `/${tarName}`
const getOuputCommand = ["cat", sourcePath]
const getOutputCommand = ["cat", sourcePath]
const tmpFile = await tmp.fileSync()

let writeStream = fs.createWriteStream(tmpFile.name)

await runner.spawn({
command: getOuputCommand,
command: getOutputCommand,
container: "skopeo",
ignoreError: false,
log,
9 changes: 2 additions & 7 deletions garden-service/src/plugins/kubernetes/container/build.ts
Original file line number Diff line number Diff line change
@@ -13,13 +13,7 @@ import { containerHelpers } from "../../container/helpers"
import { buildContainerModule, getContainerBuildStatus, getDockerBuildFlags } from "../../container/build"
import { GetBuildStatusParams, BuildStatus } from "../../../types/plugin/module/getBuildStatus"
import { BuildModuleParams, BuildResult } from "../../../types/plugin/module/build"
import {
millicpuToString,
megabytesToString,
getRunningPodInDeployment,
makePodName,
getSkopeoContainer,
} from "../util"
import { millicpuToString, megabytesToString, getRunningPodInDeployment, makePodName } from "../util"
import { RSYNC_PORT, dockerAuthSecretName, inClusterRegistryHostname } from "../constants"
import { posix, resolve } from "path"
import { KubeApi } from "../api"
@@ -44,6 +38,7 @@ const dockerDaemonDeploymentName = "garden-docker-daemon"
const dockerDaemonContainerName = "docker-daemon"

const kanikoImage = "gcr.io/kaniko-project/executor:debug-v0.19.0"
const skopeoImage = "gardendev/skopeo:1.41.0-1"

const registryPort = 5000

Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/*
* Copyright (C) 2018-2020 Garden Technologies, Inc. <[email protected]>
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/

import { pullFromInClusterRegistry } from "../../../../../../src/plugins/kubernetes/commands/pull-image"
import { Garden } from "../../../../../../src/garden"
import { ConfigGraph } from "../../../../../../src/config-graph"
import { getContainerTestGarden } from "../container/container"
import { k8sBuildContainer } from "../../../../../../src/plugins/kubernetes/container/build"
import { PluginContext } from "../../../../../../src/plugin-context"
import { KubernetesProvider, KubernetesPluginContext } from "../../../../../../src/plugins/kubernetes/config"
import { Module } from "../../../../../../src/types/module"

describe("pull-image plugin command", () => {
let garden: Garden
let graph: ConfigGraph
let provider: KubernetesProvider
let ctx: PluginContext

after(async () => {
if (garden) {
await garden.close()
}
})

const init = async (environmentName: string) => {
garden = await getContainerTestGarden(environmentName)
graph = await garden.getConfigGraph(garden.log)
provider = <KubernetesProvider>await garden.resolveProvider("local-kubernetes")
ctx = garden.getPluginContext(provider)
}

context("using the in cluster registry", () => {
let module: Module

before(async () => {
await init("cluster-docker")

module = await graph.getModule("simple-service")
// build the image
await garden.buildDir.syncFromSrc(module, garden.log)

await k8sBuildContainer({
ctx,
log: garden.log,
module,
})
})

it("should pull the image", async () => {
await pullFromInClusterRegistry(ctx as KubernetesPluginContext, module, garden.log)
})
})
})

0 comments on commit 823a596

Please sign in to comment.