git

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: May 6, 2015 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package git is the middleware that pull sites from git repo

Caddyfile Syntax :

git repo path {
	repo
	path
	branch
	key
	interval
	then command args
}
repo 	- git repository
	compulsory. Both ssh (e.g. git@github.com:user/project.git)
	and https(e.g. https://github.com/user/project) are supported.
	Can be specified in either config block or top level

path 	- directory to pull into, relative to site root
	optional. Defaults to site root.

branch 	- git branch or tag
	optional. Defaults to master

key 	- path to private ssh key
	optional. Required for private repositories. e.g. /home/user/.ssh/id_rsa

interval- interval between git pulls in seconds
	optional. Defaults to 3600 (1 Hour).

then	- command to execute after successful pull
	optional. If set, will execute only when there are new changes.

Examples :

public repo pulled into site root

git github.com/user/myproject

public repo pulled into <root>/mysite

git https://github.com/user/myproject mysite

private repo pulled into <root>/mysite with tag v1.0 and interval of 1 day.

git {
	repo 	git@github.com:user/myproject
	branch 	v1.0
	path	mysite
	key 	/home/user/.ssh/id_rsa
	interval 86400 # 1 day
}

Caddyfile with private git repo and php support via fastcgi. path defaults to /var/www/html/myphpsite as specified in root config.

0.0.0.0:8080

git {
	repo 	git@github.com:user/myphpsite
	key 	/home/user/.ssh/id_rsa
	interval 86400 # 1 day
}

fastcgi / 127.0.0.1:9000 php

root /var/www/html/myphpsite

A pull is first attempted after initialization. Afterwards, a pull is attempted after request to server and if time taken since last successful pull is higher than interval.

After the first successful pull (should be during initialization except an error occurs), subsequent pulls are done in background and do not impact request time.

Note: private repositories are currently only supported and tested on Linux and OSX

Index

Constants

View Source
const DefaultInterval time.Duration = time.Hour * 1

DefaultInterval is the minimum interval to delay before requesting another git pull

Variables

View Source
var Logger *log.Logger

Logger is used to log errors; if nil, the default log.Logger is used.

Functions

func InitGit

func InitGit() error

InitGit validates git installation and locates the git executable binary in PATH

Types

type Repo

type Repo struct {
	Url      string        // Repository URL
	Path     string        // Directory to pull to
	Host     string        // Git domain host e.g. github.com
	Branch   string        // Git branch
	KeyPath  string        // Path to private ssh key
	Interval time.Duration // Interval between pulls
	Then     string        // Command to execute after successful git pull

	sync.Mutex
	// contains filtered or unexported fields
}

Repo is the structure that holds required information of a git repository.

func (*Repo) Prepare

func (r *Repo) Prepare() error

Prepare prepares for a git pull and validates the configured directory

func (*Repo) Pull

func (r *Repo) Pull() error

Pull attempts a git clone. It retries at most numRetries times if error occurs

Jump to

Keyboard shortcuts

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