Skip to content

Commit

Permalink
improvement(core): resolve remote sources in parallel (#2097)
Browse files Browse the repository at this point in the history
* improvement(core): resolve remote sources in parallel

* TBS: Fix tests

Co-authored-by: Thorarinn Sigurdsson <thorarinnsigurdsson@gmail.com>
  • Loading branch information
edvald and thsig committed Oct 8, 2020
1 parent 27af1fd commit 1e3dce0
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 19 deletions.
17 changes: 8 additions & 9 deletions core/src/garden.ts
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
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
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

0 comments on commit 1e3dce0

Please sign in to comment.