Skip to content
This repository was archived by the owner on May 12, 2018. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/runner
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ require 'bundler/setup'

require_relative '../lib/runner'

GitlabCi::Runner.new
GitlabCi::Runner.new(ARGV.fetch(0, '0'))
exit
5 changes: 3 additions & 2 deletions lib/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class Build

attr_accessor :id, :commands, :ref, :tmp_file_path, :output, :before_sha, :run_at, :post_message

def initialize(data)
def initialize(runner, data)
@runner = runner
@output = ""
@post_message = ""
@commands = data[:commands].to_a
Expand Down Expand Up @@ -182,7 +183,7 @@ def repo_exists?
end

def config
@config ||= Config.new
@config ||= Config.new(@runner)
end

def project_dir
Expand Down
5 changes: 3 additions & 2 deletions lib/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ module GitlabCi
class Config
attr_reader :config

def initialize
def initialize(runner)
@runner = runner
if File.exists?(config_path)
@config = YAML.load_file(config_path)
else
Expand All @@ -26,7 +27,7 @@ def url
end

def builds_dir
@builds_path ||= File.join($root_path, 'tmp', 'builds')
@builds_path ||= File.join($root_path, 'tmp', 'builds', 'runner-' + @runner.to_s)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long. [87/80]
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just followed convention in the same file ...
See line below:
opts.on('-CWORKING_DIRECTORY', 'Specify the working directory for gitlab-ci-runner') do |v|

Anyway, I will fix single quotes

end

def write(key, value)
Expand Down
8 changes: 6 additions & 2 deletions lib/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ module GitlabCi
class Network
include HTTParty

def initialize(runner)
@runner = runner
end

# check for available build from coordinator
# and pick a pending one
# {
Expand Down Expand Up @@ -95,7 +99,7 @@ def register_runner(token)
private

def broadcast message
print "#{Time.now.to_s} | #{message}"
print "#{Time.now.to_s} | #{@runner} | #{message}"

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant use of Object#to_s in interpolation.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not a ruby expert, so could you please show me how to fix this issue and I will apply it to later ones

end

def api_url
Expand All @@ -107,7 +111,7 @@ def token
end

def config
@config ||= Config.new
@config ||= Config.new(@runner)
end

def default_options
Expand Down
15 changes: 8 additions & 7 deletions lib/runner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@ module GitlabCi
class Runner
attr_accessor :current_build, :thread

def initialize
puts '* Gitlab CI Runner started'
def initialize(runner)
@runner = runner
puts "* Gitlab CI Runner #{@runner} started"
puts '* Waiting for builds'
loop do
if running?
Expand Down Expand Up @@ -34,7 +35,7 @@ def abort_if_timeout

def update_build
return unless @current_build.completed?
puts "#{Time.now.to_s} | Completed build #{@current_build.id}, #{@current_build.state}."
puts "#{Time.now.to_s} | Completed build #{@current_build.id}, #{@current_build.state} on runner #{@runner}."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant use of Object#to_s in interpolation.
Line is too long. [115/80]


# Make sure we push latest build info submitted
# before we clean build
Expand Down Expand Up @@ -70,14 +71,14 @@ def get_build
end

def network
@network ||= Network.new
@network ||= Network.new(@runner)
end

def run(build_data)
@current_build = GitlabCi::Build.new(build_data)
puts "#{Time.now.to_s} | Starting new build #{@current_build.id}..."
@current_build = GitlabCi::Build.new(@runner, build_data)
puts "#{Time.now.to_s} | Starting new build #{@current_build.id} with runner #{@runner}..."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant use of Object#to_s in interpolation.
Line is too long. [97/80]

@current_build.run
puts "#{Time.now.to_s} | Build #{@current_build.id} started."
puts "#{Time.now.to_s} | Build #{@current_build.id} on runner #{@runner} started."

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Redundant use of Object#to_s in interpolation.
Line is too long. [88/80]

end

def collect_trace
Expand Down
2 changes: 1 addition & 1 deletion lib/setup.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def register_runner
def write_token(token)
puts "Runner token: #{token}"

Config.new.write('token', token)
Config.new(0).write('token', token)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

end
end
end
16 changes: 10 additions & 6 deletions lib/support/init.d/gitlab_ci_runner
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ NAME="gitlab-ci-runner"
DESC="GitLab CI runner"
RUNNERS_REGISTERED=0
RUNNERS_RUNNING=0
INIT_LOG="/var/log/gitlab_ci_runner.log"
INIT_LOG='/var/log/gitlab_ci_runner.log'
#INIT_LOG='/var/log/gitlab_ci_runner_$RUNNER.log'

check_pid() {
# Number of registered runners in PID file
Expand Down Expand Up @@ -54,13 +55,16 @@ start() {
# Spawn runners
for (( i=1; i<=$RUNNERS_NUM; i++ ))
do
# eval is required for making dedicated logs for each logger. Then use $RUNNER substitution in INIT_LOG variable
RUNNER=$((i-1))
eval "LOGFILE=\"$INIT_LOG\""
# Check log file
if [ ! -f $INIT_LOG ]; then
touch $INIT_LOG
chown $APP_USER $INIT_LOG
if [ ! -f $LOGFILE ]; then
touch $LOGFILE
chown $APP_USER $LOGFILE
fi
echo "Starting runner #$i"
execute "$START_RUNNER >> $INIT_LOG 2>&1 & echo \$! >> $RUNNERS_PID"
execute "$START_RUNNER $i >> $LOGFILE 2>&1 & echo \$! >> $RUNNERS_PID"
done
echo "SUCCESS: Started $RUNNERS_NUM $DESC(s)."
fi
Expand Down Expand Up @@ -99,7 +103,7 @@ stop() {
ps -C "$PROCESS_NAME" -o "%p" h | xargs kill -USR2
[ $? -eq 0 ] && echo "OK"
else
echo "No ghost runners have been found.This is good."
echo "No ghost runners have been found. This is good."
fi
}

Expand Down
3 changes: 2 additions & 1 deletion spec/build_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

describe 'Build' do
describe :run do
let(:build) { GitlabCi::Build.new(build_data) }
let(:build) { GitlabCi::Build.new(0, build_data) }

before do
build.run
Expand All @@ -27,3 +27,4 @@ def build_data
}
end
end

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 trailing blank lines detected.