gitlab-mirror-pull 0.2.2 → 0.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +43 -19
- data/bin/gitlab-mirror-pull +11 -6
- data/extconf.rb +18 -0
- data/init.d/gitlab-mirror-server.sh +100 -0
- data/lib/{gitlab-mirror-pull.rb → gitlab_mirror_pull.rb} +4 -3
- metadata +7 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c847596586376e72096363509de165d2b7a7c0523999c683433b2de163e35c28
|
4
|
+
data.tar.gz: be7a17f14463e9173d37f0243267d2b78459f73c030874bf53ac6ddab7fac255
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1cc83bfa75b327b0fbc99252600158366ade011c6564952b447db416eb9503943d70b619740fd5e8d33488dd7a1d38b9b7d75732835bac484280f6a72e7b6349
|
7
|
+
data.tar.gz: 5b23b8accb84df8dc0a08110d8edf6db929a3e1fe3cab69c6545859c2f1535efe4aab492c7ae247afeb2544f2f09baba488c4e60a368f407698436fe66a8f5ca
|
data/README.md
CHANGED
@@ -6,40 +6,64 @@ Description
|
|
6
6
|
|
7
7
|
Update your git repositories automatically when `remote` is set
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
* Adds a command to fetch repositories
|
10
|
+
* Run a tiny Webserver to integrate with Gitlabs webhooks
|
11
|
+
* Adds init script to `/etc/init.d/gitlab-mirror-server`
|
11
12
|
|
12
|
-
|
13
|
-
- Run bundler: `bundle install`
|
14
|
-
- Copy and modify `config.example.yml` to `config.yml`
|
13
|
+
# Install (for development)
|
15
14
|
|
16
|
-
|
17
|
-
|
15
|
+
* Clone repository: `git clone https://github.com/ochorocho/gitlab-mirror-pull.git`
|
16
|
+
* Run bundler: `bundle install`
|
17
|
+
* Copy and modify `config.example.yml` to `config.yml`
|
18
18
|
|
19
|
-
|
20
|
-
|
19
|
+
## Run
|
20
|
+
|
21
|
+
```bash
|
22
|
+
./bin/gitlab-mirror-pull -c config.yml -l INFO
|
21
23
|
```
|
22
24
|
|
23
|
-
|
24
|
-
---------------
|
25
|
+
# Using 'gem install'
|
25
26
|
|
26
|
-
|
27
|
+
### Install
|
27
28
|
|
28
29
|
```bash
|
29
|
-
|
30
|
+
gem install gitlab-mirror-pull
|
30
31
|
```
|
31
32
|
|
32
|
-
|
33
|
-
-------------------
|
33
|
+
### Run
|
34
34
|
|
35
|
-
|
35
|
+
```bash
|
36
|
+
gitlab-mirror-pull -c /path/to/config.yml
|
37
|
+
```
|
38
|
+
|
39
|
+
Default config location
|
36
40
|
|
37
41
|
```bash
|
38
|
-
|
42
|
+
/etc/gitlab-mirror-pull/config.yml
|
39
43
|
```
|
40
44
|
|
41
|
-
|
45
|
+
## Setup a CronJob
|
46
|
+
|
47
|
+
If you want to trigger periodically
|
42
48
|
|
43
49
|
```bash
|
44
|
-
gitlab-mirror-pull
|
50
|
+
* */1 * * * git /usr/bin/ruby /usr/local/bin/gitlab-mirror-pull
|
45
51
|
```
|
52
|
+
|
53
|
+
## Setup gitlab webhook
|
54
|
+
|
55
|
+
Allow webhooks on `localhost` in gitlab (Admin -> Settings -> Outbound requests)
|
56
|
+
and check `Allow requests to the local network from hooks and services` and hit save
|
57
|
+
|
58
|
+
Go to your porject -> Settings -> Integrations:
|
59
|
+
|
60
|
+
* Add URL `http://localhost:8088/commit`
|
61
|
+
* Leave Token empty
|
62
|
+
* Check `Enable SSL verification`
|
63
|
+
* Tick boxes to enable `Triggers`
|
64
|
+
* Run server `sudo /etc/init.d/gitlab-mirror-server start`
|
65
|
+
|
66
|
+
**Logs**
|
67
|
+
|
68
|
+
* `/var/log/gitlab-mirror-server.err`
|
69
|
+
* `/var/log/gitlab-mirror-server.log`
|
data/bin/gitlab-mirror-pull
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require_relative '../lib/
|
3
|
+
require_relative '../lib/gitlab_mirror_pull.rb'
|
4
4
|
|
5
5
|
options = {
|
6
|
-
:config =>
|
6
|
+
:config => "/etc/gitlab-mirror-pull/config.yml",
|
7
7
|
:log_level => Logger::ERROR
|
8
8
|
}
|
9
9
|
|
@@ -21,7 +21,7 @@ OptionParser.new do |opts|
|
|
21
21
|
opts.set_summary_indent(' ')
|
22
22
|
opts.set_summary_width(50)
|
23
23
|
opts.define_head "Fetch gitlab repositories when remote set.
|
24
|
-
Default config
|
24
|
+
Default config /etc/gitlab-mirror-pull/config.yml\n\n"
|
25
25
|
|
26
26
|
# Config argument
|
27
27
|
opts.on("-c", "--config [config.yml]", "Specify config yaml") do |yml|
|
@@ -60,19 +60,24 @@ if options[:run] == 'server'
|
|
60
60
|
require 'multi_json'
|
61
61
|
|
62
62
|
config = YAML.load_file(options[:config])
|
63
|
+
pull = GitlabMirrorPull.new(options[:config], options[:log_level])
|
63
64
|
|
64
65
|
# Configure server
|
65
66
|
set :port, config['server']['port']
|
66
67
|
set :bind, config['server']['bind']
|
68
|
+
# Set to true to run sinatra webserver in production
|
69
|
+
set :run, true
|
67
70
|
|
68
71
|
post '/commit' do
|
69
72
|
gitlab_json = MultiJson.load(request.body.read)
|
70
73
|
# File.join(File.dirname(__FILE__), "../config.example.yml")
|
71
|
-
repo_path = File.join(config['git']['repos'], gitlab_json['project']['namespace'].downcase, gitlab_json['project']['name'].downcase)
|
72
|
-
|
74
|
+
repo_path = File.join(config['git']['repos'], gitlab_json['project']['namespace'].downcase, gitlab_json['project']['name'].downcase + ".git")
|
75
|
+
pull.fetch_repositories([repo_path])
|
76
|
+
return ''
|
73
77
|
end
|
74
78
|
|
75
79
|
else
|
76
80
|
# Run `git fetch` depending on options[:config]
|
77
|
-
GitlabMirrorPull.new(options[:config], options[:log_level])
|
81
|
+
pull = GitlabMirrorPull.new(options[:config], options[:log_level])
|
82
|
+
pull.fetch_repositories
|
78
83
|
end
|
data/extconf.rb
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
require "fileutils"
|
2
|
+
|
3
|
+
# Create fake Makefile - without this install fails due to missing Makefile
|
4
|
+
require "mkmf"
|
5
|
+
create_makefile ''
|
6
|
+
|
7
|
+
# Make sure config folder exists
|
8
|
+
directory_name = "/etc/gitlab-mirror-pull/"
|
9
|
+
Dir.mkdir(directory_name) unless File.exists?(directory_name)
|
10
|
+
|
11
|
+
# Copy config if it does not exist
|
12
|
+
config_copy = "/etc/gitlab-mirror-pull/config.yml"
|
13
|
+
FileUtils.cp("./config.example.yml",config_copy) unless File.exists?(config_copy)
|
14
|
+
|
15
|
+
# Copy init script into place
|
16
|
+
init_copy = "/etc/init.d/gitlab-mirror-server"
|
17
|
+
FileUtils.rm(init_copy) unless File.exists?(init_copy)
|
18
|
+
FileUtils.cp("./init.d/gitlab-mirror-server.sh",init_copy)
|
@@ -0,0 +1,100 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
### BEGIN INIT INFO
|
3
|
+
# Provides:
|
4
|
+
# Required-Start: $remote_fs $syslog
|
5
|
+
# Required-Stop: $remote_fs $syslog
|
6
|
+
# Default-Start: 2 3 4 5
|
7
|
+
# Default-Stop: 0 1 6
|
8
|
+
# Short-Description: Start gitlab-mirror-pull webserver
|
9
|
+
# Description: Start gitlab-mirror-pull webserver. Set url to http://localhost:[:port] to trigger git fetch on triggered repo
|
10
|
+
### END INIT INFO
|
11
|
+
|
12
|
+
dir="/"
|
13
|
+
binary=`which gitlab-mirror-pull`
|
14
|
+
config="/etc/gitlab-mirror-pull/config.yml"
|
15
|
+
cmd="$binary -r server -c $config -l ERROR"
|
16
|
+
user=""
|
17
|
+
|
18
|
+
name=`basename $0`
|
19
|
+
pid_file="/var/run/$name.pid"
|
20
|
+
stdout_log="/var/log/$name.log"
|
21
|
+
stderr_log="/var/log/$name.err"
|
22
|
+
|
23
|
+
get_pid() {
|
24
|
+
cat "$pid_file"
|
25
|
+
}
|
26
|
+
|
27
|
+
is_running() {
|
28
|
+
[ -f "$pid_file" ] && ps `get_pid` > /dev/null 2>&1
|
29
|
+
}
|
30
|
+
|
31
|
+
case "$1" in
|
32
|
+
start)
|
33
|
+
if is_running; then
|
34
|
+
echo "$name already started ..."
|
35
|
+
else
|
36
|
+
echo "Starting $name ..."
|
37
|
+
cd "$dir"
|
38
|
+
if [ -z "$user" ]; then
|
39
|
+
sudo $cmd >> "$stdout_log" 2>> "$stderr_log" &
|
40
|
+
else
|
41
|
+
sudo -u "$user" $cmd >> "$stdout_log" 2>> "$stderr_log" &
|
42
|
+
fi
|
43
|
+
echo $! > "$pid_file"
|
44
|
+
if ! is_running; then
|
45
|
+
echo "Unable to start, see $stdout_log and $stderr_log"
|
46
|
+
exit 1
|
47
|
+
fi
|
48
|
+
fi
|
49
|
+
;;
|
50
|
+
stop)
|
51
|
+
if is_running; then
|
52
|
+
echo -n "Stopping $name ..."
|
53
|
+
kill `get_pid`
|
54
|
+
for i in {1..10}
|
55
|
+
do
|
56
|
+
if ! is_running; then
|
57
|
+
break
|
58
|
+
fi
|
59
|
+
|
60
|
+
echo -n "."
|
61
|
+
sleep 1
|
62
|
+
done
|
63
|
+
echo
|
64
|
+
|
65
|
+
if is_running; then
|
66
|
+
echo "Not stopped; may still be shutting down or shutdown may have failed"
|
67
|
+
exit 1
|
68
|
+
else
|
69
|
+
echo "$name stopped ..."
|
70
|
+
if [ -f "$pid_file" ]; then
|
71
|
+
rm "$pid_file"
|
72
|
+
fi
|
73
|
+
fi
|
74
|
+
else
|
75
|
+
echo "$name not running ..."
|
76
|
+
fi
|
77
|
+
;;
|
78
|
+
restart)
|
79
|
+
$0 stop
|
80
|
+
if is_running; then
|
81
|
+
echo "Unable to stop, will not attempt to start"
|
82
|
+
exit 1
|
83
|
+
fi
|
84
|
+
$0 start
|
85
|
+
;;
|
86
|
+
status)
|
87
|
+
if is_running; then
|
88
|
+
echo "$name is running ..."
|
89
|
+
else
|
90
|
+
echo "$name stopped ..."
|
91
|
+
exit 1
|
92
|
+
fi
|
93
|
+
;;
|
94
|
+
*)
|
95
|
+
echo "Usage: $0 {start|stop|restart|status}"
|
96
|
+
exit 1
|
97
|
+
;;
|
98
|
+
esac
|
99
|
+
|
100
|
+
exit 0
|
@@ -3,6 +3,7 @@ require 'git'
|
|
3
3
|
require 'logger'
|
4
4
|
require 'yaml'
|
5
5
|
|
6
|
+
# Fetch Gitlab repositories
|
6
7
|
class GitlabMirrorPull
|
7
8
|
|
8
9
|
attr_accessor :config, :log_level
|
@@ -20,7 +21,6 @@ class GitlabMirrorPull
|
|
20
21
|
@log = Logger.new(STDOUT)
|
21
22
|
@log.level = log_level
|
22
23
|
@config = YAML.load_file(config)
|
23
|
-
self.fetch_repositories
|
24
24
|
end
|
25
25
|
|
26
26
|
# Prepare list of repositories
|
@@ -45,16 +45,17 @@ class GitlabMirrorPull
|
|
45
45
|
|
46
46
|
# Fetch repositories return by `repositories_to_fetch`
|
47
47
|
#
|
48
|
+
# @param [Array<String>] repos with absolute path to repositories you want to fetch
|
48
49
|
# @return Logging infos on fetched repos
|
49
50
|
#
|
50
|
-
def fetch_repositories
|
51
|
+
def fetch_repositories(repos = nil)
|
51
52
|
# Init git settings
|
52
53
|
Git.configure do |config|
|
53
54
|
config.binary_path = "#{@config['git']['path']}"
|
54
55
|
end
|
55
56
|
|
56
57
|
# Loop through repos and fetch it
|
57
|
-
repos_to_fetch = self.repositories_to_fetch
|
58
|
+
repos_to_fetch = repos.nil? ? self.repositories_to_fetch : repos
|
58
59
|
repos_to_fetch.each do |repo|
|
59
60
|
if File.directory?(repo)
|
60
61
|
# Get branches
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gitlab-mirror-pull
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- ochorocho
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-06-
|
11
|
+
date: 2018-06-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: git
|
@@ -55,13 +55,16 @@ description: Checks for repositories with a set remote and run git fetch on thes
|
|
55
55
|
email: rothjochen@gmail.com
|
56
56
|
executables:
|
57
57
|
- gitlab-mirror-pull
|
58
|
-
extensions:
|
58
|
+
extensions:
|
59
|
+
- extconf.rb
|
59
60
|
extra_rdoc_files: []
|
60
61
|
files:
|
61
62
|
- README.md
|
62
63
|
- bin/gitlab-mirror-pull
|
63
64
|
- config.example.yml
|
64
|
-
-
|
65
|
+
- extconf.rb
|
66
|
+
- init.d/gitlab-mirror-server.sh
|
67
|
+
- lib/gitlab_mirror_pull.rb
|
65
68
|
homepage: https://github.com/ochorocho/gitlab-mirror-pull
|
66
69
|
licenses:
|
67
70
|
- MIT
|