Skip to content

Commit

Permalink
Merge pull request #323 from garden-io/remote-sources-tags
Browse files Browse the repository at this point in the history
docs(examples): use version tags in remote-sources repo urls
  • Loading branch information
eysi09 authored Oct 11, 2018
2 parents 53fefa6 + 7c48383 commit b0b5599
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 11 deletions.
8 changes: 4 additions & 4 deletions examples/remote-sources/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ project:
name: remote-sources
sources:
- name: web-services
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-web-services.git#master
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-web-services.git#v0.1.0
- name: db-services
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-db-services.git#master
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-db-services.git#v0.1.0
```
> Remote repository URLs must contain a hash part that references a specific branch or tag, e.g. `https://github.com/org/repo.git/#v1.0`.
> Remote repository URLs must contain a hash part that references a specific branch or tag, e.g. `https://github.com/org/repo.git/#my-tag-or-branch`. The remote repositories used in this example all contain the tag `v0.1.0`. Read more about Git tagging [here](https://git-scm.com/book/en/v2/Git-Basics-Tagging).

### Configuring remote modules

Expand All @@ -94,7 +94,7 @@ module:
description: worker
type: container
name: jworker
repositoryUrl: https://github.com/garden-io/garden-example-remote-module-jworker.git#master
repositoryUrl: https://github.com/garden-io/garden-example-remote-module-jworker.git#v0.1.0
services:
- name: javaworker
dependencies:
Expand Down
4 changes: 2 additions & 2 deletions examples/remote-sources/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ project:
name: remote-sources
sources:
- name: web-services
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-web-services.git#master
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-web-services.git#v0.1.0
- name: db-services
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-db-services.git#master
repositoryUrl: https://github.com/garden-io/garden-example-remote-sources-db-services.git#v0.1.0
2 changes: 1 addition & 1 deletion examples/remote-sources/services/jworker/garden.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module:
description: worker
type: container
name: jworker
repositoryUrl: https://github.com/garden-io/garden-example-remote-module-jworker.git#master
repositoryUrl: https://github.com/garden-io/garden-example-remote-module-jworker.git#v0.1.0
services:
- name: javaworker
dependencies:
Expand Down
24 changes: 20 additions & 4 deletions garden-service/src/vcs/git.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import { ensureDir, pathExists, stat } from "fs-extra"
import Bluebird = require("bluebird")

import { NEW_MODULE_VERSION, VcsHandler, RemoteSourceParams } from "./base"
import { ConfigurationError } from "../exceptions"
import { ConfigurationError, RuntimeError } from "../exceptions"

export const helpers = {
gitCli: (cwd: string): (cmd: string, args: string[]) => Promise<string> => {
Expand Down Expand Up @@ -105,7 +105,15 @@ export class GitHandler extends VcsHandler {
const entry = logEntry.info({ section: name, msg: `Fetching from ${url}`, status: "active" })
const { repositoryUrl, hash } = parseGitUrl(url)

await git("clone", ["--depth=1", `--branch=${hash}`, repositoryUrl, absPath])
try {
await git("clone", ["--depth=1", `--branch=${hash}`, repositoryUrl, absPath])
} catch (err) {
entry.setError()
throw new RuntimeError(`Downloading remote ${sourceType} failed with error: \n\n${err}`, {
repositoryUrl: url,
message: err.message,
})
}

entry.setSuccess()
}
Expand All @@ -129,8 +137,16 @@ export class GitHandler extends VcsHandler {
if (localCommitId !== remoteCommitId) {
entry.setState(`Fetching from ${url}`)

await git("fetch", ["--depth=1", "origin", hash])
await git("reset", ["--hard", `origin/${hash}`])
try {
await git("fetch", ["--depth=1", "origin", hash])
await git("reset", ["--hard", `origin/${hash}`])
} catch (err) {
entry.setError()
throw new RuntimeError(`Updating remote ${sourceType} failed with error: \n\n${err}`, {
repositoryUrl: url,
message: err.message,
})
}

entry.setSuccess("Source updated")
} else {
Expand Down

0 comments on commit b0b5599

Please sign in to comment.