Skip to content
This repository has been archived by the owner on Oct 28, 2024. It is now read-only.

Commit

Permalink
Gitlab CI Script (#40)
Browse files Browse the repository at this point in the history
* gitlab ci script

* add rubocop

* appease rubocop

* cache deps
  • Loading branch information
davidsiaw authored and Yuuki77 committed Jan 15, 2020
1 parent 1d16d60 commit 11afb9b
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 47 deletions.
21 changes: 21 additions & 0 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
image: "ruby:2.5"

# Cache gems in between builds
cache:
key: ${CI_COMMIT_REF_SLUG}
paths:
- vendor/ruby

before_script:
- ruby -v
- which ruby
- gem install bundler --no-document
- bundle install --jobs $(nproc) --path vendor "${FLAGS[@]}"

rspec:
script:
- bundle exec rspec

rubocop:
script:
- bundle exec rubocop
75 changes: 53 additions & 22 deletions .rubocop_todo.yml
Original file line number Diff line number Diff line change
@@ -1,51 +1,82 @@
# This configuration was generated by
# `rubocop --auto-gen-config`
# on 2018-12-05 10:41:34 +0900 using RuboCop version 0.54.0.
# on 2020-01-15 15:29:46 +0900 using RuboCop version 0.79.0.
# The point is for the user to remove these configuration records
# one by one as the offenses are removed from the code base.
# Note that changes in the inspected code, or installation of new
# versions of RuboCop, may require this file to be generated again.

# Offense count: 1
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle.
# SupportedStyles: auto_detection, squiggly, active_support, powerpack, unindent
Layout/IndentHeredoc:
Lint/AmbiguousOperator:
Exclude:
- 'exe/kaiser'
- 'lib/kaiser/cli.rb'

# Offense count: 4
# Offense count: 1
# Configuration parameters: AllowComments.
Lint/SuppressedException:
Exclude:
- 'lib/kaiser/command_runner.rb'

# Offense count: 11
Metrics/AbcSize:
Max: 30
Max: 57

# Offense count: 1
# Offense count: 4
# Configuration parameters: CountComments, ExcludedMethods.
# ExcludedMethods: refine
Metrics/BlockLength:
Max: 30
Max: 63

# Offense count: 1
# Configuration parameters: CountComments.
Metrics/ClassLength:
Max: 366
Max: 425

# Offense count: 4
# Configuration parameters: CountComments.
# Offense count: 2
Metrics/CyclomaticComplexity:
Max: 8

# Offense count: 11
# Configuration parameters: CountComments, ExcludedMethods.
Metrics/MethodLength:
Max: 30
Max: 44

# Offense count: 1
# Configuration parameters: CountKeywordArgs.
Metrics/ParameterLists:
Max: 7

# Offense count: 1
# Cop supports --auto-correct.
Style/IfUnlessModifier:
# Offense count: 2
Metrics/PerceivedComplexity:
Max: 8

# Offense count: 14
# Configuration parameters: ForbiddenDelimiters.
# ForbiddenDelimiters: (?-mix:(^|\s)(EO[A-Z]{1}|END)(\s|$))
Naming/HeredocDelimiterNaming:
Exclude:
- 'lib/kaiser/kaiser_cli.rb'
- 'lib/kaiser/cmds/attach.rb'
- 'lib/kaiser/cmds/db_load.rb'
- 'lib/kaiser/cmds/db_reset.rb'
- 'lib/kaiser/cmds/db_reset_hard.rb'
- 'lib/kaiser/cmds/db_save.rb'
- 'lib/kaiser/cmds/deinit.rb'
- 'lib/kaiser/cmds/down.rb'
- 'lib/kaiser/cmds/init.rb'
- 'lib/kaiser/cmds/login.rb'
- 'lib/kaiser/cmds/logs.rb'
- 'lib/kaiser/cmds/set.rb'
- 'lib/kaiser/cmds/show.rb'
- 'lib/kaiser/cmds/shutdown.rb'
- 'lib/kaiser/cmds/up.rb'

# Offense count: 2
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# Offense count: 16
Style/Documentation:
Enabled: false

# Offense count: 27
# Cop supports --auto-correct.
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
# URISchemes: http, https
Metrics/LineLength:
Max: 92
Layout/LineLength:
Max: 143
18 changes: 17 additions & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
kaiser (0.4.1)
kaiser (0.4.3)
optimist

GEM
Expand All @@ -26,6 +26,7 @@ GEM
aruba
aruba-doubles
rspec (>= 3.0)
ast (2.4.0)
backports (3.11.4)
builder (3.2.3)
childprocess (0.9.0)
Expand Down Expand Up @@ -55,10 +56,15 @@ GEM
gherkin (5.1.0)
i18n (1.1.1)
concurrent-ruby (~> 1.0)
jaro_winkler (1.5.4)
minitest (5.11.3)
multi_json (1.13.1)
multi_test (0.1.2)
optimist (3.0.0)
parallel (1.19.1)
parser (2.7.0.2)
ast (~> 2.4.0)
rainbow (3.0.0)
rake (10.5.0)
rspec (3.8.0)
rspec-core (~> 3.8.0)
Expand All @@ -73,10 +79,19 @@ GEM
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.8.0)
rspec-support (3.8.0)
rubocop (0.79.0)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
thor (0.20.3)
thread_safe (0.3.6)
tzinfo (1.2.5)
thread_safe (~> 0.1)
unicode-display_width (1.6.0)

PLATFORMS
ruby
Expand All @@ -88,6 +103,7 @@ DEPENDENCIES
kaiser!
rake (~> 10.0)
rspec (~> 3.0)
rubocop

BUNDLED WITH
2.0.2
4 changes: 2 additions & 2 deletions exe/kaiser
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ cmd = commands.first

begin
Kaiser::Cli.run_command(:"#{cmd}", global_opts)
rescue Kaiser::Error => err
rescue Kaiser::Error => e
puts ''
puts err.message
puts e.message
end

puts ''
1 change: 1 addition & 0 deletions kaiser.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency 'factory_bot', '~> 4.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
end
8 changes: 2 additions & 6 deletions lib/kaiser/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -317,9 +317,7 @@ def wait_for_app
echo '!'
SCRIPT
run_blocking_script('alpine', '', wait_script) do |line|
if line != '!' && container_dead?(app_container_name)
raise Kaiser::Error, 'App container died. Run `kaiser logs` to see why.'
end
raise Kaiser::Error, 'App container died. Run `kaiser logs` to see why.' if line != '!' && container_dead?(app_container_name)
end
Config.info_out.puts 'Started.'
end
Expand Down Expand Up @@ -555,9 +553,7 @@ def killrm(container)
x = JSON.parse(`docker inspect #{container} 2>/dev/null`)
return if x.length.zero?

if x[0]['State'] && x[0]['State']['Running'] == true
CommandRunner.run Config.out, "docker kill #{container}"
end
CommandRunner.run Config.out, "docker kill #{container}" if x[0]['State'] && x[0]['State']['Running'] == true
CommandRunner.run Config.out, "docker rm #{container}" if x[0]['State']
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/attach.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
attach_app
start_app
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_load.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
name = ARGV.shift || '.default'
load_db(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_reset.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
load_db('.default')
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_reset_hard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
FileUtils.rm db_image_path('.default') if File.exist?(db_image_path('.default'))
setup_db
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/db_save.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
name = ARGV.shift || '.default'
save_db(name)
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/deinit.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
down
Config.config[:envs].delete(envname)
Config.config[:envnames].delete(Config.work_dir)
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/down.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
down
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/init.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
return Optimist.die "Already initialized as #{envname}" if envname

name = ARGV.shift
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/login.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
cmd = (ARGV || []).join(' ')
exec "docker exec -ti #{app_container_name} #{cmd}"
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/logs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
exec "docker logs -f #{app_container_name}"
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
cmd = ARGV.shift
if cmd == 'cert-url'
Config.config[:cert_source] = {
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/show.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
ensure_setup
cmd = ARGV.shift
valid_cmds = 'ports cert-source http-suffix'
Expand Down
2 changes: 1 addition & 1 deletion lib/kaiser/cmds/shutdown.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def usage
EOS
end

def execute(opts)
def execute(_opts)
Config.config[:shared_names].each do |_, container_name|
killrm container_name
end
Expand Down
7 changes: 4 additions & 3 deletions lib/kaiser/command_runner.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
# frozen_string_literal: true

require 'English'

# This is the command runner
Expand Down Expand Up @@ -32,7 +33,7 @@ def print_lines(lines)
@out.flush
yield line.chomp if block_given?
end
rescue Errno::EIO # rubocop:disable Lint/HandleExceptions
rescue Errno::EIO
# Happens when `lines` stream is closed
end

Expand All @@ -42,8 +43,8 @@ def run_command(&block)
Process.wait(pid)
end
print_and_return_status $CHILD_STATUS.exitstatus
rescue PTY::ChildExited => ex
print_and_return_status(ex.status)
rescue PTY::ChildExited => e
print_and_return_status(e.status)
end
end
end
2 changes: 2 additions & 0 deletions lib/kaiser/error.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Kaiser
# Base class for Kaiser-related errors.
class Error < StandardError
Expand Down

0 comments on commit 11afb9b

Please sign in to comment.