Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
vpereira committed Mar 31, 2020
0 parents commit d7bfb25
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

# rspec failure tracking
.rspec_status
3 changes: 3 additions & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
--format documentation
--color
--require spec_helper
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
sudo: false
language: ruby
cache: bundler
rvm:
- 2.6.3
before_install: gem install bundler -v 2.0.2
6 changes: 6 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in obs_deploy.gemspec
gemspec
63 changes: 63 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
PATH
remote: .
specs:
obs_deploy (0.1.0)
cheetah
net-ssh
nokogiri

GEM
remote: https://rubygems.org/
specs:
abstract_method (1.2.1)
ast (2.4.0)
cheetah (0.5.2)
abstract_method (~> 1.2)
diff-lcs (1.3)
jaro_winkler (1.5.4)
mini_portile2 (2.4.0)
net-ssh (5.2.0)
nokogiri (1.10.9)
mini_portile2 (~> 2.4.0)
parallel (1.19.1)
parser (2.7.0.5)
ast (~> 2.4.0)
rainbow (3.0.0)
rake (10.5.0)
rexml (3.2.4)
rspec (3.9.0)
rspec-core (~> 3.9.0)
rspec-expectations (~> 3.9.0)
rspec-mocks (~> 3.9.0)
rspec-core (3.9.1)
rspec-support (~> 3.9.1)
rspec-expectations (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-mocks (3.9.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.9.0)
rspec-support (3.9.2)
rubocop (0.80.1)
jaro_winkler (~> 1.5.1)
parallel (~> 1.10)
parser (>= 2.7.0.1)
rainbow (>= 2.2.2, < 4.0)
rexml
ruby-progressbar (~> 1.7)
unicode-display_width (>= 1.4.0, < 1.7)
ruby-progressbar (1.10.1)
unicode-display_width (1.6.1)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 2.0)
obs_deploy!
rake (~> 10.0)
rspec (~> 3.0)
rubocop

BUNDLED WITH
2.0.2
38 changes: 38 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# OBS Deploy tool

Simple tool to deploy OBS via zypper to our reference server

## Installation

Just run:

```ruby
gem 'obs_deploy'
```

## Usage

To be able to use it you will need an env file like:

```
ssh_server: xxx
user: xxx
product_version: yyyy
```

give this env file as parameter to `obs_deploy` and you are good to go:

`obs_deploy deploy -f env_file`
`obs_deploy running`
`obs_deploy available -f env_file`
`obs_deploy deploy -f env_file --dry-run`

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).

## Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/vpereira/obs_deploy.
8 changes: 8 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'
require 'rspec/core/rake_task'

RSpec::Core::RakeTask.new(:spec)

task default: :spec
15 changes: 15 additions & 0 deletions bin/console
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'obs_deploy'

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require "pry"
# Pry.start

require 'irb'
IRB.start(__FILE__)
8 changes: 8 additions & 0 deletions bin/setup
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
set -vx

bundle install

# Do any other automated setup that you need to do here
92 changes: 92 additions & 0 deletions lib/obs_deploy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
# frozen_string_literal: true

require 'obs_deploy/version'
require 'open-uri'
require 'net/http'
require 'nokogiri'

module ObsDeploy
class Error < StandardError; end

class CheckDiff
def initialize(server: 'https://api.opensuse.org', product: 'SLE_12_SP4')
@server = server
@product = product
end

def package_version
doc = Nokogiri::XML(open(package_url))
doc.xpath("//binary[starts-with(@filename, 'obs-api')]/@filename").to_s
end

def package_commit
package_version.match(/obs-api-.*\..*\..*\.(.*)-.*\.rpm/).captures.first
end

def obs_running_commit
doc = Nokogiri::XML(about_url)
doc.xpath('//commit/text()').to_s
end

def github_diff
Net::HTTP.get(URI("https://github.com/openSUSE/open-build-service/compare/#{obs_running_commit}...#{package_commit}.diff"))
end

def migration?
!!github_diff.match(%r{db/migrate})
end

private

def package_url
URI("#{@server}/public/build/OBS:Server:Unstable/#{@product}/x86_64/obs-server")
end

def about_url
URI("#{@server}/about")
end
end
class Systemctl
class << self
def status
system('systemctl status obs-api-support.target')
end

def list_dependencies
system('systemctl list-dependencies obs-api-support.target')
end
end
end

class Zypper
def update(dry_run: true)
if dry_run
run ['zypper'] + update_params + dry_run_params + package_name
else
run ['zypper'] + update_params + package_name
end
end

def refresh
run ['zypper', '--non-interactive', '--gpg-auto-import-keys', 'refresh']
end

private

def run(params)
# ...
end

def package_name
['obs-api']
end

def update_params
['--non-interactive', 'update', '--best-effort', '--details']
end

def dry_run_params
['--dry-run --download-only']
end
end
end
5 changes: 5 additions & 0 deletions lib/obs_deploy/version.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

module ObsDeploy
VERSION = '0.1.0'
end
37 changes: 37 additions & 0 deletions obs_deploy.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# frozen_string_literal: true

lib = File.expand_path('lib', __dir__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'obs_deploy/version'

Gem::Specification.new do |spec|
spec.name = 'obs_deploy'
spec.version = ObsDeploy::VERSION
spec.authors = ['Victor Pereira']
spec.email = ['[email protected]']

spec.summary = 'OBS Deployment tool'
spec.homepage = 'https://openbuildservice.org'

spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"

spec.metadata['homepage_uri'] = spec.homepage
spec.metadata['source_code_uri'] = 'https://github.com/vpereira/obs_deploy.git'

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path(__dir__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = 'exe'
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
spec.require_paths = ['lib']

spec.add_development_dependency 'bundler', '~> 2.0'
spec.add_development_dependency 'rake', '~> 10.0'
spec.add_development_dependency 'rspec', '~> 3.0'
spec.add_development_dependency 'rubocop'
spec.add_dependency 'cheetah'
spec.add_dependency 'net-ssh'
spec.add_dependency 'nokogiri'
end
17 changes: 17 additions & 0 deletions spec/check_diff_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

RSpec.describe ObsDeploy::CheckDiff do
let(:check_diff) { described_class.new }

it { expect(check_diff).not_to be_nil }

describe '#package_version' do
subject { check_diff.package_version }
it { expect(subject).not_to be_nil }
end

describe '#package_commit' do
subject { check_diff.package_commit }
it { expect(subject).not_to be_nil }
end
end
7 changes: 7 additions & 0 deletions spec/obs_deploy_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

RSpec.describe ObsDeploy do
it 'has a version number' do
expect(ObsDeploy::VERSION).not_to be nil
end
end
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

require 'bundler/setup'
require 'obs_deploy'

RSpec.configure do |config|
# Enable flags like --only-failures and --next-failure
config.example_status_persistence_file_path = '.rspec_status'

# Disable RSpec exposing methods globally on `Module` and `main`
config.disable_monkey_patching!

config.expect_with :rspec do |c|
c.syntax = :expect
end
end

0 comments on commit d7bfb25

Please sign in to comment.