Skip to content

Commit

Permalink
feat(core): add module include field and use content hash for versions
Browse files Browse the repository at this point in the history
This changes the version handling to no longer rely on git commit hashes
but instead use content hashes on all included files.

Also added is the `include` field on modules, which allows for control
over which files are considered part of the module sources.

Further, this improves handling of .gardenignore files, so they now
work in subdirectories as well as the project root.

Note: .gitignore files no longer factor in when evaluating module
versions. Use .gardenignore files instead (same format) to exclude files
from file watching and versioning in Garden.

Closes #328
Closes #603
  • Loading branch information
edvald committed Apr 8, 2019
1 parent 13b8028 commit 8bd0b5b
Show file tree
Hide file tree
Showing 76 changed files with 745 additions and 676 deletions.
2 changes: 1 addition & 1 deletion .gardenignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
examples/
test/
node_modules/
25 changes: 25 additions & 0 deletions docs/reference/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,30 @@ module:
| Type | Required |
| ---- | -------- |
| `string` | No
### `module.include[]`
[module](#module) > include

Specify a list of POSIX-style paths or globs that should be regarded as the source files for this
module. Files that do *not* match these paths or globs are excluded when computing the version of the module,
as well as when responding to filesystem watch events.

Note that you can also _exclude_ files by placing `.gardenignore` files in your source tree, which use the
same format as `.gitignore` files.

Also note that specifying an empty list here means _no sources_ should be included.

| Type | Required |
| ---- | -------- |
| `array[string]` | No

Example:
```yaml
module:
...
include:
- Dockerfile
- my-app.js
```
### `module.repositoryUrl`
[module](#module) > repositoryUrl

Expand Down Expand Up @@ -372,6 +396,7 @@ module:
type:
name:
description:
include:
repositoryUrl:
allowPublish: true
build:
Expand Down
2 changes: 1 addition & 1 deletion garden-service/bin/add-version-files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function addVersionFiles() {
const versionFilePath = resolve(path, ".garden-version")

const vcsHandler = new GitHandler(path)
const treeVersion = await vcsHandler.getTreeVersion(path)
const treeVersion = await vcsHandler.getTreeVersion(path, config.include || null)

console.log(`${config.name} -> ${relative(staticPath, versionFilePath)}`)

Expand Down
52 changes: 38 additions & 14 deletions garden-service/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions garden-service/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@
"koa-websocket": "^5.0.1",
"lodash": "^4.17.11",
"log-symbols": "^2.2.0",
"minimatch": "^3.0.4",
"mocha-logger": "^1.0.6",
"moment": "^2.23.0",
"node-emoji": "^1.8.1",
Expand Down Expand Up @@ -125,6 +126,7 @@
"@types/lodash": "^4.14.119",
"@types/log-symbols": "^2.0.0",
"@types/log-update": "^2.0.0",
"@types/minimatch": "^3.0.3",
"@types/mocha": "^5.2.5",
"@types/nock": "^9.3.0",
"@types/node": "^10.12.15",
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/build-dir.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import {
import { zip } from "lodash"
import * as execa from "execa"
import { platform } from "os"
import { toCygwinPath } from "./util/util"
import { toCygwinPath } from "./util/fs"
import { ModuleConfig } from "./config/module"
import { LogEntry } from "./logger/log-entry"

Expand Down
15 changes: 4 additions & 11 deletions garden-service/src/commands/publish.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import {
} from "./base"
import { Module } from "../types/module"
import { PublishTask } from "../tasks/publish"
import { RuntimeError } from "../exceptions"
import { TaskResults } from "../task-graph"
import { Garden } from "../garden"
import { LogEntry } from "../logger/log-entry"
Expand Down Expand Up @@ -80,17 +79,11 @@ export async function publishModules(
forceBuild: boolean,
allowDirty: boolean,
): Promise<TaskResults> {
const tasks = modules.map(module => {
const version = module.version

if (version.dirtyTimestamp && !allowDirty) {
throw new RuntimeError(
`Module ${module.name} has uncommitted changes. ` +
`Please commit them, clean the module's source tree or set the --allow-dirty flag to override.`,
{ moduleName: module.name, version },
)
}
if (!!allowDirty) {
log.warn(`The --allow-dirty flag has been deprecated. It no longer has an effect.`)
}

const tasks = modules.map(module => {
return new PublishTask({ garden, log, module, forceBuild })
})

Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/commands/update-remote/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { difference } from "lodash"
import { join, basename } from "path"
import { remove, pathExists } from "fs-extra"

import { getChildDirNames } from "../../util/util"
import { getChildDirNames } from "../../util/fs"
import {
ExternalSourceType,
getRemoteSourcesDirname,
Expand Down
9 changes: 3 additions & 6 deletions garden-service/src/config/base.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@
*/

import { join, basename, sep, resolve, relative } from "path"
import {
findByName,
getNames,
} from "../util/util"
import { findByName, getNames } from "../util/util"
import * as Joi from "joi"
import * as yaml from "js-yaml"
import { readFile } from "fs-extra"
Expand All @@ -19,8 +16,7 @@ import { baseModuleSpecSchema, ModuleConfig } from "./module"
import { validateWithPath } from "./common"
import { ConfigurationError } from "../exceptions"
import { defaultEnvironments, ProjectConfig, projectSchema } from "../config/project"

const CONFIG_FILENAME = "garden.yml"
import { CONFIG_FILENAME } from "../constants"

export interface GardenConfig {
dirname: string
Expand Down Expand Up @@ -243,6 +239,7 @@ function prepareModuleConfig(moduleSpec: any, path: string): ModuleConfig {
dependencies,
},
description: moduleSpec.description,
include: moduleSpec.include,
name: moduleSpec.name,
outputs: {},
path,
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/config/config-context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ConfigurationError } from "../exceptions"
import { resolveTemplateString } from "../template-string"
import * as Joi from "joi"
import { Garden } from "../garden"
import { ModuleVersion } from "../vcs/base"
import { ModuleVersion } from "../vcs/vcs"

export type ContextKey = string[]

Expand Down
12 changes: 12 additions & 0 deletions garden-service/src/config/module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export interface BaseModuleSpec {
allowPublish: boolean
build: BaseBuildSpec
description?: string
include?: string[]
name: string
path: string
type: string
Expand Down Expand Up @@ -102,6 +103,17 @@ export const baseModuleSpecSchema = Joi.object()
.description("The name of this module.")
.example("my-sweet-module"),
description: Joi.string(),
include: Joi.array().items(Joi.string().uri({ relativeOnly: true }))
.description(
dedent`Specify a list of POSIX-style paths or globs that should be regarded as the source files for this
module. Files that do *not* match these paths or globs are excluded when computing the version of the module,
as well as when responding to filesystem watch events.
Note that you can also _exclude_ files by placing \`.gardenignore\` files in your source tree, which use the
same format as \`.gitignore\` files.
Also note that specifying an empty list here means _no sources_ should be included.`)
.example([["Dockerfile", "my-app.js"], {}]),
repositoryUrl: joiRepositoryUrl()
.description(
dedent`${joiRepositoryUrl().describe().description}
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { resolve, join } from "path"

export const isPkg = !!(<any>process).pkg

export const MODULE_CONFIG_FILENAME = "garden.yml"
export const CONFIG_FILENAME = "garden.yml"
export const LOCAL_CONFIG_FILENAME = "local-config.yml"
export const STATIC_DIR = resolve(isPkg ? process.execPath : __dirname, "..", "static")
// We copy the built dashboard to the garden-service static directory (with gulp in development, otherwise in CI).
Expand Down
Loading

0 comments on commit 8bd0b5b

Please sign in to comment.