librarianpuppetgo

package module
v0.3.10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 30, 2018 License: MIT Imports: 22 Imported by: 0

README

README

librarian-puppet-go is a simple command to clone modules and to checkout based on Puppetfile.

go run main.go install --modulepath /tmp/modules < Puppetfile

Feature

This command ensures that git repositories are checked out with tag, ref and version.

For instance, let's say you have a following Puppetfile.

mod 'bar', :git => 'git@github.com:tmtk75/tmtk75-bar.git', :ref => 'master'
mod 'foo', :git => 'git@bitbucket.org:tmtk75/tmtk75-foo.git', :ref => 'v0.1.2'
mod 'puppetlabs/stdlib', '4.1.0'

Then modules directory has these repositories after running the command.

modules
  |-- bar       # chekced out at the latest of master origin/branch
  |-- foo       # checked out at the specified tag, v0.1.2
  `-- stdlib    # checked out at the commit versioned as 4.1.0 in puppetlabs.com
  • Check out the present latest commit of origin/${branchname} if :ref is a branch.
  • Check out the tag if :ref is a tag.
  • Check out the commit registered with a version in puppetlabs.com retrieving its URL of source repository using REST API. puppet module command is NOT used.

Extensions

include

include directive allows you to include several Puppetfiles like this.

include "Puppetfile.common"
include "Puppetfile.debug"
mod 'puppetlabs/stdlib'
  • It can be only in the head of file. You cannot put include after mod directive.
  • The latest mod is used if same module name appears. For example, next case is 1.0.0 is enabled.
mod 'puppetlabs/stdlib', '4.1.0'
mod 'puppetlabs/stdlib', '1.0.0'

Performance

  • It takes about 30 seconds in order to clone about 80 modules although basically cloning modules strongly depends on the network speed 😁
  • It takes about 7 seconds in order to fetch & checkout about 80 modules.

Assumption

$ cat Puppetfile.1 | grep '^mod' | wc -l
      84
$ cat Puppetfile.2 | grep '^mod' | wc -l
      81

Puppetfile.1 has 84 mod declarations. For example,

mod 'puppetlabs/stdlib', '4.1.0'
mod 'nodejs', :git => 'git://github.com/danheberden/puppet-nodejs.git'

Puppetfile.2 also has 81 mod declarations which each mod has a specific tag. For instance,

mod 'foo', :git => 'git@github.com:tmtk75/tmtk75-foo.git', :ref => 'v0.1.2'
mod 'bar', :git => 'git@github.com:tmtk75/tmtk75-bar.git', :ref => 'v0.2.0'

Time to cloning all & checkout all

At first there is no modules, which will be created, so all modules are cloned.

$ time ./librarian-puppet-go install --modulepath modules < Puppetfile.1

real    0m32.639s
user    0m14.881s
sys     0m12.581s

Afterward fetch & checkout complete within 5 seconds.

$ time ./librarian-puppet-go install --modulepath modules < Puppetfile.2

real    0m7.282s
user    0m4.266s
sys     0m2.788s

Limitation

Acceptable Puppetfile is NOT compatible to original Puppetfile written in DSL of Ruby.
A mod definition MUST be one line which contains mod, version string, :git or :ref. Please see mod_test.go for expected definitions.

Documentation

Index

Constants

View Source
const (
	STAT    = "STAT"
	FULL    = "FULL"
	SUMMARY = "SUMMARY"
)

Variables

View Source
var Version = ""

Functions

func CLIMain

func CLIMain()

func Diff

func Diff(a, b string, dirs []string, mode string)

func Format

func Format(a string, overwrite bool)

func PrintGitPushCmds

func PrintGitPushCmds(remote, src, dst string)

func Sort

func Sort(a string) (string, error)

func SortCmd

func SortCmd()

Types

type DiffFunc

type DiffFunc func(oldm, newm Mod, oldref, newref string)

type Git

type Git struct {
	Writer   io.Writer
	Remote   string
	IsCommit func(wd, sha1 string) bool
	IsBranch func(wd, name string) bool
	IsTag    func(wd, name string) bool
	Sha1     func(wd, ref string) string
	Diff     func(wd, srcref, dstref string) string
}

func NewGit

func NewGit() *Git

func (*Git) Each

func (g *Git) Each(path string, cmds []string, opts eachOpts)

func (Git) PushCmd

func (g Git) PushCmd(oldm, newm Mod) (string, error)

func (*Git) PushCmds

func (g *Git) PushCmds(src, dst string)

type Ignorable

type Ignorable struct {
	// contains filtered or unexported fields
}

Marker to ignore intentionally

type Mod

type Mod struct {
	// contains filtered or unexported fields
}

mod 'puppetlabs/stdlib', '4.1.0' mod 'fiz', :git => 'git@github.com:foo/bar.git', :ref => 'v0.4.1'

func (Mod) Dest

func (m Mod) Dest() string

func (Mod) Format

func (m Mod) Format() string

func (Mod) Fullname

func (m Mod) Fullname() string

func (Mod) Ref

func (m Mod) Ref() string

func (Mod) RefSemver

func (m Mod) RefSemver() string

func (*Mod) Replace

func (m *Mod) Replace(e *Mod)

func (Mod) String

func (m Mod) String() string

type ModOpts

type ModOpts map[string]string

type Mods

type Mods []Mod

func (Mods) Len

func (v Mods) Len() int

func (Mods) Less

func (v Mods) Less(i, j int) bool

func (Mods) Swap

func (v Mods) Swap(i, j int)

type Res

type Res struct {
	CurrentRelease struct {
		Metadata struct {
			Source      string `json:"source"`
			ProjectPage string `json:"project_page"`
		} `json:"metadata"`
	} `json:"current_release"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL