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

improvement(core): resolve remote sources in parallel #2097

Merged
merged 2 commits into from
Oct 8, 2020
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
17 changes: 8 additions & 9 deletions core/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ import { loadConfigResources, findProjectConfig, prepareModuleResource } from ".
import { DeepPrimitiveMap, StringMap, PrimitiveMap } from "./config/common"
import { validateSchema } from "./config/validation"
import { BaseTask } from "./tasks/base"
import { LocalConfigStore, ConfigStore, GlobalConfigStore } from "./config-store"
import { LocalConfigStore, ConfigStore, GlobalConfigStore, LinkedSource } from "./config-store"
import { getLinkedSources, ExternalSourceType } from "./util/ext-source-util"
import { BuildDependencyConfig, ModuleConfig, ModuleResource } from "./config/module"
import { resolveModuleConfig } from "./resolve-module"
Expand Down Expand Up @@ -999,18 +999,17 @@ export class Garden {

this.log.silly(`Scanning for modules and workflows`)

let extSourcePaths: string[] = []

// Add external sources that are defined at the project level. External sources are either kept in
// the .garden/sources dir (and cloned there if needed), or they're linked to a local path via the link command.
for (const { name, repositoryUrl } of this.projectSources) {
const path = await this.loadExtSourcePath({
const linkedSources = await getLinkedSources(this, "project")
const extSourcePaths = await Bluebird.map(this.projectSources, ({ name, repositoryUrl }) => {
return this.loadExtSourcePath({
name,
linkedSources,
repositoryUrl,
sourceType: "project",
})
extSourcePaths.push(path)
}
})

const dirsToScan = [this.projectRoot, ...extSourcePaths]
const configPaths = flatten(await Bluebird.map(dirsToScan, (path) => this.scanForConfigs(path)))
Expand Down Expand Up @@ -1117,15 +1116,15 @@ export class Garden {
*/
public async loadExtSourcePath({
name,
linkedSources,
repositoryUrl,
sourceType,
}: {
name: string
linkedSources: LinkedSource[]
repositoryUrl: string
sourceType: ExternalSourceType
}): Promise<string> {
const linkedSources = await getLinkedSources(this, sourceType)

const linked = findByName(linkedSources, name)

if (linked) {
Expand Down
3 changes: 3 additions & 0 deletions core/src/resolve-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import { getModuleKey } from "./types/module"
import { getModuleTypeBases } from "./plugins"
import { ModuleConfig, moduleConfigSchema } from "./config/module"
import { profileAsync } from "./util/profiling"
import { getLinkedSources } from "./util/ext-source-util"

export interface ModuleConfigResolveOpts extends ContextResolveOpts {
configContext: ModuleConfigContext
Expand Down Expand Up @@ -81,8 +82,10 @@ export const resolveModuleConfig = profileAsync(async function $resolveModuleCon
})

if (config.repositoryUrl) {
const linkedSources = await getLinkedSources(garden, "module")
config.path = await garden.loadExtSourcePath({
name: config.name,
linkedSources,
repositoryUrl: config.repositoryUrl,
sourceType: "module",
})
Expand Down
22 changes: 12 additions & 10 deletions core/test/unit/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ import { realpath, writeFile } from "fs-extra"
import { dedent, deline } from "../../../src/util/string"
import { ServiceState } from "../../../src/types/service"
import execa from "execa"
import { getLinkedSources } from "../../../src/util/ext-source-util"

describe("Garden", () => {
let tmpDir: tmp.DirectoryResult
Expand Down Expand Up @@ -3519,19 +3520,22 @@ describe("Garden", () => {

describe("loadExtSourcePath", () => {
let garden: TestGarden
let linkedSources: LinkedSource[]

afterEach(async () => {
await resetLocalConfig(garden.gardenDirPath)
})

context("external project sources", () => {
before(async () => {
garden = await makeExtProjectSourcesGarden()
})

afterEach(async () => {
await resetLocalConfig(garden.gardenDirPath)
linkedSources = await getLinkedSources(garden, "module")
})

it("should return the path to the project source if source type is project", async () => {
const projectRoot = getDataDir("test-project-ext-project-sources")
const path = await garden.loadExtSourcePath({
linkedSources,
repositoryUrl: testGitUrl,
name: "source-a",
sourceType: "project",
Expand All @@ -3549,10 +3553,10 @@ describe("Garden", () => {
path: linkedSourcePath,
},
]
await garden.configStore.set(["linkedProjectSources"], linked)

const path = await garden.loadExtSourcePath({
name: "source-a",
linkedSources: linked,
repositoryUrl: testGitUrl,
sourceType: "project",
})
Expand All @@ -3564,15 +3568,13 @@ describe("Garden", () => {
context("external module sources", () => {
before(async () => {
garden = await makeExtModuleSourcesGarden()
})

afterEach(async () => {
await resetLocalConfig(garden.gardenDirPath)
linkedSources = await getLinkedSources(garden, "module")
})

it("should return the path to the module source if source type is module", async () => {
const projectRoot = getDataDir("test-project-ext-module-sources")
const path = await garden.loadExtSourcePath({
linkedSources,
repositoryUrl: testGitUrl,
name: "module-a",
sourceType: "module",
Expand All @@ -3590,10 +3592,10 @@ describe("Garden", () => {
path: linkedModulePath,
},
]
await garden.configStore.set(["linkedModuleSources"], linked)

const path = await garden.loadExtSourcePath({
name: "module-a",
linkedSources: linked,
repositoryUrl: testGitUrl,
sourceType: "module",
})
Expand Down