obs_deploy 0.2.3 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0c30ef3de78c4686ec7f27a73e2824653a845b86156c5c35d0d3458896195116
4
- data.tar.gz: 93d7393cb93c865a4a87e11cfa24eb4df35cfff12f5b3921da639adbee14b29d
3
+ metadata.gz: f5b16b77225b642cdcc26e723e6c9d6b97615dbf23c898e24ce6ddb35c728761
4
+ data.tar.gz: 37ec0c9e13a348103d0049c619da0f774d39ff73f1d7daa69b29148b3500a36a
5
5
  SHA512:
6
- metadata.gz: f4b1b7da0b1112e5ac195f8fdcb5a373db76c2fa79fe10ba76753fbd0933ae834d23c4a2575f88e3ca52540c2ca9cc81464be0eb954c3a6ffd46b5f43895ce87
7
- data.tar.gz: 01dd7034cb873265620005cc2a6cd00e616ffa2c364397aa4a8be3358998831b5e7c8e4e354e17db165165b02e80a742e74227cb58050471f6b1b9e19c4c120d
6
+ metadata.gz: 36bcb33b807e433fdb19f8a5cfaf73dc5e9b98dd5b8152e4e2aa8de0dffd2d1e4ee4001b99c1b97b2155f79e1e3cad0f3af71c7a28915d7719a63e052a1044ff
7
+ data.tar.gz: 8a463bf31c90f57034bbcb7599a378c3494f33543f4273077b565a0250949ba342578dfbc597ff41224c59d59af1baa22456e035eb6da30ae104224b6109ef5b
@@ -0,0 +1,8 @@
1
+ FROM opensuse/tumbleweed
2
+
3
+ RUN zypper --gpg-auto-import-keys refresh
4
+ RUN zypper install -y openssh vim iputils
5
+
6
+ COPY entrypoint.sh /entrypoint.sh
7
+ RUN chmod +x /entrypoint.sh
8
+ ENTRYPOINT ["/entrypoint.sh"]
File without changes
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- obs_deploy (0.2.3)
4
+ obs_deploy (0.3.2)
5
5
  cheetah
6
6
  dry-cli
7
7
  nokogiri
@@ -16,7 +16,7 @@ GEM
16
16
  cheetah (0.5.2)
17
17
  abstract_method (~> 1.2)
18
18
  coderay (1.1.2)
19
- concurrent-ruby (1.1.6)
19
+ concurrent-ruby (1.1.7)
20
20
  crack (0.4.3)
21
21
  safe_yaml (~> 1.0.0)
22
22
  diff-lcs (1.3)
@@ -25,9 +25,10 @@ GEM
25
25
  hashdiff (1.0.1)
26
26
  jaro_winkler (1.5.4)
27
27
  method_source (1.0.0)
28
- mini_portile2 (2.4.0)
29
- nokogiri (1.10.9)
30
- mini_portile2 (~> 2.4.0)
28
+ mini_portile2 (2.5.0)
29
+ nokogiri (1.11.0)
30
+ mini_portile2 (~> 2.5.0)
31
+ racc (~> 1.4)
31
32
  parallel (1.19.1)
32
33
  parser (2.7.0.5)
33
34
  ast (~> 2.4.0)
@@ -35,6 +36,7 @@ GEM
35
36
  coderay (~> 1.1)
36
37
  method_source (~> 1.0)
37
38
  public_suffix (4.0.3)
39
+ racc (1.5.2)
38
40
  rainbow (3.0.0)
39
41
  rake (13.0.1)
40
42
  rexml (3.2.4)
@@ -0,0 +1,9 @@
1
+ docker-dev:
2
+ docker build -f Dockerfile.dev -t $(USER)/obs_deploy_dev .
3
+ docker run --rm -it -v "$(HOME)/.ssh:/tmp/.ssh:ro" -v "$(PWD):/obs_deploy" $(USER)/obs_deploy_dev bash
4
+
5
+ docker-rpm:
6
+ docker build -f Dockerfile.rpm -t $(USER)/obs_deploy_dev .
7
+ docker run --rm -it -v "$(HOME)/.ssh:/tmp/.ssh:ro" -v "$(PWD):/obs_deploy" $(USER)/obs_deploy_dev bash
8
+
9
+
data/README.md CHANGED
@@ -5,6 +5,9 @@ Simple tool to deploy OBS via zypper to our reference server
5
5
  ## Build Status
6
6
  [![CircleCI](https://circleci.com/gh/vpereira/obs_deploy.svg?style=svg)](https://app.circleci.com/pipelines/github/vpereira/obs_deploy)
7
7
 
8
+ ## Codebeat
9
+ [![codebeat badge](https://codebeat.co/badges/767d7e65-0364-4386-a26e-99ad228dfe31)](https://codebeat.co/projects/github-com-vpereira-obs_deploy-master)
10
+
8
11
 
9
12
  ## Installation
10
13
 
@@ -61,6 +64,10 @@ After checking out the repo, run `bin/setup` to install dependencies. Then, run
61
64
 
62
65
  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).
63
66
 
67
+ ### Fixtures
68
+
69
+ To generate the fixtures (located under `spec/fixtures`), we are using `curl -si $URL > $FIXTURE`
70
+
64
71
  ### Run the `bin/obs_deploy` on development:
65
72
 
66
73
  On the checked out source, run the following:
@@ -80,7 +87,7 @@ if you want to run it against the OBS appliance running on VirtualBox:
80
87
  - then run the container as:
81
88
 
82
89
  ```
83
- docker run --rm -it -v "$HOME/.ssh:/tmp/.ssh:ro" $USER/obs_deploy bash
90
+ make docker-dev
84
91
  ```
85
92
  Now you are inside the container and should be able to ping the obs appliance.
86
93
 
@@ -97,6 +104,15 @@ If you want to add new command to the cli, please read the `dry-cli` documentati
97
104
 
98
105
  The commands are being sent via ssh and ssh is being called via `cheetah` https://github.com/openSUSE/cheetah. Please Read the `ssh.rb` file, specially the `SSH#run` method
99
106
 
107
+ ## RPM Building
108
+
109
+ Under dist/ we have the necessary files to use to build the gem as rpm. The
110
+ `_service` still not used. Mainly because we need either to build the rubygem
111
+ dependencies or use https://github.com/openSUSE/obs-service-bundle_gems
112
+
113
+ Today as it is, you have to push the gem to rubygems and then generate the spec
114
+ and push it to build service
115
+
100
116
  ## Contributing
101
117
 
102
118
  Bug reports and pull requests are welcome on GitHub at https://github.com/vpereira/obs_deploy.
@@ -1,6 +1,6 @@
1
1
  spec:
2
2
  gem2rpm --fetch obs_deploy > rubygem-obs_deploy.spec
3
3
  rm *.gem
4
- clean:
4
+ spec-clean:
5
5
  spec-cleaner rubygem-obs_deploy.spec > x.spec
6
6
  mv x.spec rubygem-obs_deploy.spec
@@ -1,4 +1,12 @@
1
1
  <services>
2
- <service name="download_files">
2
+ <service name="tar_scm">
3
+ <param name="scm">git</param>
4
+ <param name="url">git://github.com/vpereira/obs_deploy.git</param>
5
+ <param name="revision">master</param>
6
+ <param name="version">0.2.0</param>
3
7
  </service>
8
+ <service name="recompress">
9
+ <param name="file">*.tar</param>
10
+ <param name="compression">xz</param>
11
+ </service>
4
12
  </services>
@@ -18,23 +18,21 @@
18
18
 
19
19
  %define mod_name obs_deploy
20
20
  %define mod_full_name %{mod_name}-%{version}
21
- %define rb_suffix ruby2.6
22
21
  Name: rubygem-obs_deploy
23
- Version: 0.2.0
22
+ Version: 0.3.0
24
23
  Release: 0
25
24
  Summary: OBS Deployment tool
26
- License: MIT
25
+ License:
27
26
  Group: Development/Languages/Ruby
28
27
  URL: https://openbuildservice.org
29
28
  Source: https://rubygems.org/gems/%{mod_full_name}.gem
30
29
  BuildRequires: %{rubygem gem2rpm}
31
30
  BuildRequires: %{ruby}
32
31
  BuildRequires: ruby-macros >= 5
33
- BuildRequires: ruby-common-rails
32
+ BuildRequires: update-alternatives
34
33
  # FIXME: use proper Requires(pre/post/preun/...)
35
34
  PreReq: update-alternatives
36
35
 
37
-
38
36
  %description
39
37
  OBS Deployment tool.
40
38
 
@@ -43,7 +41,6 @@ OBS Deployment tool.
43
41
  %build
44
42
 
45
43
  %install
46
- %rails_fix_ruby_shebang bin/
47
44
  %gem_install \
48
45
  --symlink-binaries \
49
46
  --doc-files="README.md" \
@@ -12,6 +12,7 @@ require 'obs_deploy/ssh'
12
12
  require 'obs_deploy/zypper'
13
13
  require 'obs_deploy/systemctl'
14
14
  require 'obs_deploy/apache_sysconfig'
15
+ require 'tempfile'
15
16
 
16
17
  module ObsDeploy
17
18
  class Error < StandardError; end
@@ -2,29 +2,64 @@
2
2
 
3
3
  module ObsDeploy
4
4
  class ApacheSysconfig
5
- attr_reader :apache_sysconfig
5
+ attr_reader :path
6
6
 
7
7
  def initialize
8
- @apache_sysconfig = '/etc/sysconfig/apache2'
8
+ @path = '/etc/sysconfig/apache2'
9
9
  end
10
10
 
11
11
  def enable_maintenance_mode
12
- write_apache_sysconfig('APACHE_SERVER_FLAGS="STATUS MAINTENANCE"')
12
+ unless maintenance_mode?
13
+ content = File.read(path).gsub(/^#{server_flags}=\"STATUS\"$/,
14
+ apache_status_line(maintenance))
15
+ write_apache_sysconfig(content)
16
+ end
13
17
  end
14
18
 
15
19
  def disable_maintenance_mode
16
- write_apache_sysconfig('APACHE_SERVER_FLAGS="STATUS"')
20
+ if maintenance_mode?
21
+ content = File.read(path).gsub(/^#{server_flags}=\"STATUS MAINTENANCE\"/,
22
+ apache_status_line(no_maintenance))
23
+ write_apache_sysconfig(content)
24
+ end
17
25
  end
18
26
 
19
27
  def maintenance_mode?
20
- File.open(apache_sysconfig).read.include?('MAINTENANCE')
28
+ find_server_flags.all? { |r| r.include?('MAINTENANCE') }
21
29
  end
22
30
 
23
31
  private
24
32
 
25
- def write_apache_sysconfig(line)
26
- File.open(apache_sysconfig, 'w') do |file|
27
- file.write(line)
33
+ def no_maintenance
34
+ 'STATUS'
35
+ end
36
+
37
+ def maintenance
38
+ 'STATUS MAINTENANCE'
39
+ end
40
+
41
+ def server_flags
42
+ 'APACHE_SERVER_FLAGS'
43
+ end
44
+
45
+ def apache_status_line(status)
46
+ "#{server_flags}=\"#{status}\""
47
+ end
48
+
49
+ def find_server_flags
50
+ File.readlines(path).grep(/^#{server_flags}=/)
51
+ end
52
+
53
+ def write_apache_sysconfig(content)
54
+ f = Tempfile.new
55
+ f.write(content)
56
+ begin
57
+ File.rename(f.path, path)
58
+ rescue SystemCallError => e
59
+ puts e.inspect
60
+ ensure
61
+ f.unlink
62
+ f.close
28
63
  end
29
64
  end
30
65
  end
@@ -2,9 +2,11 @@
2
2
 
3
3
  module ObsDeploy
4
4
  class CheckDiff
5
- def initialize(server: 'https://api.opensuse.org', product: 'SLE_12_SP4')
5
+ def initialize(server: 'https://api.opensuse.org', product: 'SLE_12_SP4', project: 'OBS:Server:Unstable', target_server: 'https://api.opensuse.org')
6
6
  @server = server
7
7
  @product = product
8
+ @project = project
9
+ @target_server = target_server
8
10
  end
9
11
 
10
12
  def package_version
@@ -25,10 +27,26 @@ module ObsDeploy
25
27
  Net::HTTP.get(URI("https://github.com/openSUSE/open-build-service/compare/#{obs_running_commit}...#{package_commit}.diff"))
26
28
  end
27
29
 
30
+ def new_version_available?
31
+ obs_running_commit != package_commit
32
+ end
33
+
28
34
  def has_migration?
29
35
  return true if github_diff.nil? || github_diff.empty?
30
36
 
31
- !!github_diff.match(%r{db/migrate})
37
+ github_diff.match?(%r{db/migrate})
38
+ end
39
+
40
+ def has_data_migration?
41
+ return true if github_diff.nil? || github_diff.empty?
42
+
43
+ github_diff.match(%r{db/data})
44
+ end
45
+
46
+ def data_migrations
47
+ return [] unless has_data_migration?
48
+
49
+ github_diff.match(%r{db/data/.*\.rb}).to_a
32
50
  end
33
51
 
34
52
  def migrations
@@ -38,11 +56,11 @@ module ObsDeploy
38
56
  end
39
57
 
40
58
  def package_url
41
- URI("#{@server}/public/build/OBS:Server:Unstable/#{@product}/x86_64/obs-server")
59
+ URI("#{@server}/public/build/#{@project}/#{@product}/x86_64/obs-server")
42
60
  end
43
61
 
44
62
  def about_url
45
- URI("#{@server}/about")
63
+ URI("#{@target_server}/about")
46
64
  end
47
65
  end
48
66
  end
@@ -11,6 +11,7 @@ module ObsDeploy
11
11
  autoload :GetDeployedVersion, File.join(__dir__, 'commands/get_deployed_version.rb')
12
12
  autoload :Systemctl, File.join(__dir__, 'commands/systemctl.rb')
13
13
  autoload :GetPendingMigration, File.join(__dir__, 'commands/get_pending_migration.rb')
14
+ autoload :GetDiff, File.join(__dir__, 'commands/get_diff.rb')
14
15
 
15
16
  # register the commands and its command line
16
17
  register 'available-package', GetPackageVersion
@@ -20,6 +21,7 @@ module ObsDeploy
20
21
  register 'refresh-repositories', RefreshRepositories
21
22
  register 'systemctl', Systemctl
22
23
  register 'pending-migrations', GetPendingMigration
24
+ register 'check-diff', GetDiff
23
25
  end
24
26
  end
25
27
  end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ObsDeploy
4
+ module CLI
5
+ module Commands
6
+ class GetDiff < Dry::CLI::Command
7
+ desc 'Get diff between deployed package and available package'
8
+ option :url, type: :string, default: 'https://api.opensuse.org', desc: 'API url'
9
+ option :package, type: :string, default: 'obs-api', desc: 'Package name'
10
+ option :project, type: :string, default: 'OBS:Server:Unstable', desc: 'Project name'
11
+ option :product, type: :string, default: 'SLE_12_SP4', desc: 'Product name'
12
+ option :architecture, type: :string, default: 'x86_64', desc: 'Architecture'
13
+
14
+ def call(url:, product:, project:, **)
15
+ puts "diff : #{ObsDeploy::CheckDiff.new(server: url, project: project, product: product).github_diff}"
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -12,7 +12,7 @@ module ObsDeploy
12
12
 
13
13
  def call(user:, dry_run:, host:, port:, **)
14
14
  ssh_driver = ObsDeploy::SSH.new(user: user, server: host, port: port)
15
- zypper = ObsDeploy::Zypper.new
15
+ zypper = ObsDeploy::Zypper.new(dry_run: dry_run)
16
16
  ssh_driver.run(zypper.refresh)
17
17
  end
18
18
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ObsDeploy
4
- VERSION = '0.2.3'
4
+ VERSION = '0.3.2'
5
5
  end
@@ -6,17 +6,33 @@ module ObsDeploy
6
6
 
7
7
  def initialize(dry_run: true, package_name: 'obs-api')
8
8
  @dry_run = dry_run
9
+ @package_name = package_name
9
10
  end
10
11
 
11
12
  def update
12
- run ['zypper'] + update_string + package_name
13
+ run %w[zypper] + update_string + package_name
13
14
  end
14
15
 
15
16
  def refresh
16
- run ['zypper', '--non-interactive', '--gpg-auto-import-keys', 'refresh']
17
+ run %w[zypper --non-interactive --gpg-auto-import-keys refresh]
17
18
  end
18
19
 
19
- private
20
+ # TODO
21
+ # check if we want to lock from specific repositories
22
+ def add_lock
23
+ run %w[zypper addlock] + package_name
24
+ end
25
+
26
+ def remove_lock
27
+ run %w[zypper removelock] + package_name
28
+ end
29
+
30
+ def locked?
31
+ # check the return value
32
+ run %w[zypper locks] + package_name
33
+ end
34
+
35
+ private
20
36
 
21
37
  def run(params)
22
38
  params
@@ -31,15 +47,15 @@ module ObsDeploy
31
47
  end
32
48
 
33
49
  def package_name
34
- ['obs-api']
50
+ [@package_name]
35
51
  end
36
52
 
37
53
  def update_params
38
- ['--non-interactive', 'update', '--best-effort', '--details']
54
+ %w[--non-interactive update --best-effort --details]
39
55
  end
40
56
 
41
57
  def dry_run_params
42
- ['--dry-run --download-only']
58
+ %w[--dry-run --download-only]
43
59
  end
44
- end
60
+ end
45
61
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: obs_deploy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.3
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Victor Pereira
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-20 00:00:00.000000000 Z
11
+ date: 2021-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -136,7 +136,7 @@ dependencies:
136
136
  - - ">="
137
137
  - !ruby/object:Gem::Version
138
138
  version: '0'
139
- description:
139
+ description:
140
140
  email:
141
141
  - vpereira@suse.de
142
142
  executables:
@@ -151,9 +151,11 @@ files:
151
151
  - ".rspec"
152
152
  - ".rubocop.yml"
153
153
  - ".travis.yml"
154
- - Dockerfile
154
+ - Dockerfile.dev
155
+ - Dockerfile.rpm
155
156
  - Gemfile
156
157
  - Gemfile.lock
158
+ - Makefile
157
159
  - README.md
158
160
  - Rakefile
159
161
  - bin/console
@@ -169,6 +171,7 @@ files:
169
171
  - lib/obs_deploy/cli/commands.rb
170
172
  - lib/obs_deploy/cli/commands/deploy.rb
171
173
  - lib/obs_deploy/cli/commands/get_deployed_version.rb
174
+ - lib/obs_deploy/cli/commands/get_diff.rb
172
175
  - lib/obs_deploy/cli/commands/get_package_version.rb
173
176
  - lib/obs_deploy/cli/commands/get_pending_migration.rb
174
177
  - lib/obs_deploy/cli/commands/refresh_repositories.rb
@@ -185,7 +188,7 @@ metadata:
185
188
  allowed_push_host: https://rubygems.org
186
189
  homepage_uri: https://openbuildservice.org
187
190
  source_code_uri: https://github.com/vpereira/obs_deploy.git
188
- post_install_message:
191
+ post_install_message:
189
192
  rdoc_options: []
190
193
  require_paths:
191
194
  - lib
@@ -201,7 +204,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
201
204
  version: '0'
202
205
  requirements: []
203
206
  rubygems_version: 3.0.6
204
- signing_key:
207
+ signing_key:
205
208
  specification_version: 4
206
209
  summary: OBS Deployment tool
207
210
  test_files: []