Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
0003d5d9
Commit
0003d5d9
authored
Dec 22, 2014
by
Johan Euphrosine
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
contrib: add git-sync container
parent
9b6aec5e
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
92 additions
and
0 deletions
+92
-0
Dockerfile
contrib/git-sync/Dockerfile
+4
-0
README.md
contrib/git-sync/README.md
+16
-0
main.go
contrib/git-sync/main.go
+72
-0
No files found.
contrib/git-sync/Dockerfile
0 → 100644
View file @
0003d5d9
FROM
golang:1.4-onbuild
VOLUME
["/git"]
CMD
["-dest", "/git"]
ENTRYPOINT
["/go/bin/git-sync"]
contrib/git-sync/README.md
0 → 100644
View file @
0003d5d9
# git-sync
git-sync is a command that periodically sync a git repository to a local directory.
It can be used to source a container volume with the content of a git repo.
## Usage
```
# build the container
docker build -t git-sync .
# run the git-sync container
docker run -d -e INTERVAL=1s -e REPO=https://github.com/GoogleCloudPlatform/kubernetes -e BRANCH=gh-pages -v /git-data:/usr/share/nginx/html git-sync
# run a nginx container to serve sync'ed content
docker run -d -p 8080:80 -v /git-data:/var/www nginx
```
contrib/git-sync/main.go
0 → 100644
View file @
0003d5d9
package
main
// import "github.com/GoogleCloudPlatform/kubernetes/git-sync"
import
(
"flag"
"log"
"net/http"
"os"
"os/exec"
"path"
"strings"
"time"
)
var
interval
=
flag
.
String
(
"interval"
,
env
(
"INTERVAL"
,
"60s"
),
"git pull interval"
)
var
repo
=
flag
.
String
(
"repo"
,
env
(
"REPO"
,
""
),
"git repo url"
)
var
branch
=
flag
.
String
(
"branch"
,
env
(
"BRANCH"
,
"master"
),
"git branch"
)
var
hook
=
flag
.
String
(
"hook"
,
env
(
"HOOK"
,
"/"
),
"web hook path"
)
var
dest
=
flag
.
String
(
"dest"
,
env
(
"DEST"
,
""
),
"destination path"
)
func
env
(
key
,
def
string
)
string
{
if
env
:=
os
.
Getenv
(
key
);
env
!=
""
{
return
env
}
return
def
}
const
usage
=
"usage: REPO= DEST= [INTERVAL= BRANCH= HOOK=] git-sync -repo GIT_REPO_URL -dest PATH [-interval -branch -hook]"
func
main
()
{
flag
.
Parse
()
if
*
repo
==
""
||
*
dest
==
""
{
flag
.
Usage
()
log
.
Fatal
(
usage
)
}
pullInterval
,
err
:=
time
.
ParseDuration
(
*
interval
)
if
err
!=
nil
{
log
.
Fatalf
(
"error parsing time duration %q: %v"
,
*
interval
,
err
)
}
if
_
,
err
:=
exec
.
LookPath
(
"git"
);
err
!=
nil
{
log
.
Fatalf
(
"required git executable not found: %v"
,
err
)
}
go
func
()
{
for
_
=
range
time
.
Tick
(
pullInterval
)
{
gitSync
()
}
}()
http
.
HandleFunc
(
*
hook
,
func
(
w
http
.
ResponseWriter
,
r
*
http
.
Request
)
{
gitSync
()
})
log
.
Fatal
(
http
.
ListenAndServe
(
":8080"
,
nil
))
}
func
gitSync
()
{
if
_
,
err
:=
os
.
Stat
(
path
.
Join
(
*
dest
,
".git"
));
os
.
IsNotExist
(
err
)
{
cmd
:=
exec
.
Command
(
"git"
,
"clone"
,
"-b"
,
*
branch
,
*
repo
,
*
dest
)
output
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
log
.
Printf
(
"command %q : %v"
,
strings
.
Join
(
cmd
.
Args
,
" "
),
err
)
return
}
log
.
Println
(
string
(
output
))
return
}
cmd
:=
exec
.
Command
(
"git"
,
"pull"
,
"origin"
,
*
branch
)
cmd
.
Dir
=
*
dest
output
,
err
:=
cmd
.
CombinedOutput
()
if
err
!=
nil
{
log
.
Printf
(
"command %q : %v"
,
strings
.
Join
(
cmd
.
Args
,
" "
),
err
)
return
}
log
.
Println
(
string
(
output
))
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment