kagami

package module
v0.0.0-...-8ea441c Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2017 License: MIT Imports: 10 Imported by: 0

README

kagami

Build Status

Small daemon that helps mirror git repository between various providers such as github/bitbucket/etc...

Work in progress, pulling should work from github, pushing only works on SSH providers with specifying a key.

Usage

Copy config.sample.hcl to /etc/kagami.hcl, change based on your needs.

usage: kagami [<flags>]

Git mirroring agent

Flags:
      --help             Show context-sensitive help (also try --help-long and --help-man).
  -c, --config="/etc/kagami.hcl"
                         Configuration file.
  -l, --loglevel=INFO    Log level.
      --log-format=text  The format to use for logs.
      --log-output="-"   Where to output logs, use - for stdin.
  -t, --test-config      Test the config and exit.

Config

# optional: cache configuration for kagami
cache {
  # optional: sets the path of caching, otherwise uses system defaults
  # path = "/var/cache/kagami"

  # optional: disable caching (uses /tmp instead)
  # disabled = false
}

# required: http server configuration
server {
  # required: the listen address of the http server
  addr = ":5050"
}

# required (at least one): sets up a named provider for use in mirrors
provider "github" {
  # required: the provider type, see the providers section
  type = "github"
}

provider "gitlab" {
  type = "gitlab"
}

# required (at least one): describes a git mirror
mirror "kagami" {
  # required: the mirror source
  source {
    # required: the provider to use for pulling/cloning
    provider = "github"

    # required: the path to the repository on the given provider
    path = "christopherobin/kagami"
  }

  # required (at least one target): the actual mirror
  target "gitlab" {
    # required: which provider to use for pushing
    provider = "gitlab"

    # required: the path to the repository on the given provider
    path = "crobin/kagami"
  }

}

Providers

github
provider "github" {
  type = "github"

  # optional: use SSH instead of HTTPS
  # use_ssh: true

  # optional: the SSH key to use for SSH
  # deploy_key: /home/kagami/.ssh/id_ecdsa

  # optional: if the SSH key has a passphrase, enter it here
  # deploy_key_password: "passphrase"
}
gitlab
provider "gitlab" {
  type = "gitlab"

  # optional: use SSH instead of HTTPS
  # use_ssh: true

  # optional: the SSH key to use for SSH
  # deploy_key: /home/kagami/.ssh/id_ecdsa

  # optional: if the SSH key has a passphrase, enter it here
  # deploy_key_password: "passphrase"
}

Documentation

Index

Constants

View Source
const Version = "0.1.0"

Version is the current version of the software

View Source
const VersionStability = "dev"

VersionStability is the status of this build, either stable, rc or dev

Variables

This section is empty.

Functions

func GetProviderInstances

func GetProviderInstances() map[string]Provider

GetProviderInstances returns all provider instances

func Init

func Init(configPath string)

Init logs the config, sets the cache and mirrors, then start the http server

func LoadMirror

func LoadMirror(config *Config, node *ast.ObjectItem) error

LoadMirror creates a new mirror

func LoadProvider

func LoadProvider(node *ast.ObjectItem) error

LoadProvider creates a named provider instance

func RegisterProvider

func RegisterProvider(name string, providerFunc ProviderCreateFunc)

RegisterProvider allows a provider to register itself with kagami

func RegisterProviderInstance

func RegisterProviderInstance(name string, provider Provider)

RegisterProviderInstance saves a provider instance under a certain name

func SetCacheInstance

func SetCacheInstance(cache *Cache)

SetCacheInstance sets the cache instance used by kagami

func SetMirrors

func SetMirrors(config *Config)

SetMirrors sets the current active mirrors

func Sync

func Sync(mirror MirrorConfig)

Sync will synchronize a mirror

func TrySync

func TrySync(provider Provider, path string)

TrySync will take path, remote and commitID and try to match mirrors

func VersionString

func VersionString() string

VersionString returns a string in the form version-stability

Types

type Cache

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

Cache takes care of abstracting caching directory name generation and cleanup

func GetCacheInstance

func GetCacheInstance() *Cache

GetCacheInstance returns the cache instance used by kagami

func NewCache

func NewCache(config *Config) *Cache

NewCache creates a new cache instance

func (*Cache) Cleanup

func (c *Cache) Cleanup() error

Cleanup destroys all temporary directories created by the cache system

func (*Cache) Repository

func (c *Cache) Repository(p Provider, r *Repository) (string, error)

Repository returns the cache path for a given repository

type CacheConfig

type CacheConfig struct {
	Path     string `hcl:"path"`
	Disabled bool   `hcl:"disabled"`
}

CacheConfig configures the caching policy of kagami

type Config

type Config struct {
	Cache   CacheConfig             `hcl:"cache"`
	Server  ServerConfig            `hcl:"server"`
	Mirrors map[string]MirrorConfig `hcl:"mirror"`
}

Config is the configuration structure for the kagami project

func LoadConfig

func LoadConfig(name string) (*Config, error)

LoadConfig loads the git mirroring configuration from a file name

func LoadConfigFromBytes

func LoadConfigFromBytes(bytes []byte) (*Config, error)

LoadConfigFromBytes loads the git mirroring configuration from a byte array

type MirrorConfig

type MirrorConfig struct {
	Source  SourceConfig            `hcl:"source"`
	Targets map[string]TargetConfig `hcl:"target"`
}

MirrorConfig represents a git mirror, it should have one source and can have multiple targets

type Provider

type Provider interface {
	Name() string
	Type() string
	Pull(repo *Repository, path string) error
	Push(repo *Repository, path string) error
	ServeHTTP(w http.ResponseWriter, req *http.Request)
}

Provider represents a valid provider with valid credentials

func CreateProvider

func CreateProvider(name string, config ast.Node) Provider

CreateProvider creates a new provider instance

func GetProviderInstance

func GetProviderInstance(name string) Provider

GetProviderInstance returns a named provider instance

type ProviderCreateFunc

type ProviderCreateFunc func(name string, config ast.Node) Provider

ProviderCreateFunc is a function that creates a provider from a HCL config node

type Repository

type Repository struct {
	Provider Provider
	Path     string
	// contains filtered or unexported fields
}

Repository represents a git repo on the disk

func NewRepository

func NewRepository(p Provider, path string) *Repository

NewRepository creates a new repository instance

func (*Repository) Exists

func (r *Repository) Exists() bool

Exists checks if the repo currently exists on the disk

func (*Repository) GetRepoPath

func (r *Repository) GetRepoPath() (string, error)

GetRepoPath creates and return a valid path where to clone the repository

type Server

type Server struct {
}

Server is a struct holding the configuration of git-mirror

func NewServer

func NewServer(config *Config) (*Server, error)

NewServer creates a new server instance that can answer to hooks

type ServerConfig

type ServerConfig struct {
	Addr string `hcl:"addr"`
}

ServerConfig configures the http server that listens to service hooks

type SourceConfig

type SourceConfig struct {
	Provider string `hcl:"provider"`
	Path     string `hcl:"path"`
}

SourceConfig tells the mirror where to pull the repository from

type TargetConfig

type TargetConfig struct {
	Provider string `hcl:"provider"`
	Path     string `hcl:"path"`
}

TargetConfig is a push target, represented by a provider name and a path to push to

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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