diff --git a/.rubocop.yml b/.rubocop.yml new file mode 100644 index 0000000..f126235 --- /dev/null +++ b/.rubocop.yml @@ -0,0 +1,2 @@ +Style/SpecialGlobalVars: + Enabled: false \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 4df6ae8..aa74fe2 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,42 @@ cookbook-minio CHANGELOG =============== +## 1.0.0 + + - malvads + - [ced168d] Fix lint issues + - [29209bf] Check service start + - [f484014] better check for s3 ready + - [f115ab6] Check s3 ready + - [6a3a6c6] First enable then start + - [cf68256] Fix minio solo check + - [cdd0ab9] Check if im solo + - [49ea797] Check for databag for setting ak and sk + - [8810089] Add template for configure solo + - [f40ac6e] Fix lint issues + - [1e405cb] Add helpers + - [0e5d307] Configure minio load balancer + - [12fb1ea] Rename bucket name to bucket + - [4f601f3] Fix bucket endpoint + - [cea7c23] Add def s3 user and s3 password + - [3d65942] Fix undefined resource + - [20495e3] Change the name of the bucket to bucket + - [190cf9a] Configure S3 Solo + - [428dafb] Update config.rb + - [3cc2db9] Update minio_helpers.rb + - [33a237b] Update config.rb + - [3cf592e] Remove whitespaces + - [06c9b95] Run out of weird interpreted langs issues + - [af59f8d] Update config.rb + - [428dafb] Update config.rb + - [3cc2db9] Update minio_helpers.rb + - [33a237b] Update config.rb + - [3cf592e] Remove whitespaces + - [06c9b95] Run out of weird interpreted langs issues + - [af59f8d] Update config.rb + - [dd7bfb9] Clean empty spaces + - [832ddb4] Update README.md + ## 0.0.5 - Miguel Negrón diff --git a/README.md b/README.md index a8be52e..e8e620d 100644 --- a/README.md +++ b/README.md @@ -1,15 +1,15 @@ # cookbook-minio [![Build Status][build-shield]][build-url] [![Linters][linters-shield]][linters-url] -[![All Contributors][contributors-shield]][contributors-url] +[![License][license-shield]][license-url] [build-shield]: https://github.com/redBorder/cookbook-minio/actions/workflows/rpm.yml/badge.svg?branch=master [build-url]: https://github.com/redBorder/cookbook-minio/actions/workflows/rpm.yml?query=branch%3Amaster [linters-shield]: https://github.com/redBorder/cookbook-minio/actions/workflows/lint.yml/badge.svg?event=push [linters-url]: https://github.com/redBorder/cookbook-minio/actions/workflows/lint.yml -[contributors-shield]: https://img.shields.io/badge/all_contributors-grey.svg -[contributors-url]: https://github.com/redBorder/cookbook-minio/graphs/contributors +[license-shield]: https://img.shields.io/badge/license-AGPLv3-blue.svg +[license-url]: https://github.com/cookbook-minio/blob/HEAD/LICENSE Chef cookbook to install and configure minio in redborder diff --git a/resources/attributes/default.rb b/resources/attributes/default.rb index 25a9728..b41a828 100644 --- a/resources/attributes/default.rb +++ b/resources/attributes/default.rb @@ -1,6 +1,13 @@ default['minio']['user'] = 'minio' default['minio']['group'] = 'minio' default['minio']['port'] = 9000 +default['minio']['access_key_id'] = 'redborder' +default['minio']['secret_key_id'] = 'redborder' +default['minio']['s3_user'] = ['redborder'] +default['minio']['s3_password'] = ['redborder'] +default['minio']['s3_hosts'] = ['localhost:9000'] +default['minio']['s3_bucket'] = 'bucket' +default['minio']['s3_endpoint'] = 's3.service' # Flags default['minio']['registered'] = false diff --git a/resources/libraries/minio_helpers.rb b/resources/libraries/minio_helpers.rb new file mode 100644 index 0000000..8055250 --- /dev/null +++ b/resources/libraries/minio_helpers.rb @@ -0,0 +1,44 @@ +module Minio + module Helpers + def self.check_remote_port(host, port) + `nc -zv #{host} #{port} 2>&1` + + process_status = $? + + process_status.exitstatus == 0 + end + + def self.generate_random_key(len) + chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789' + key = '' + len.times { key << chars[rand(chars.size)] } + key + end + + def self.check_remote_hosts(hosts) + all_alive = true + hosts.each do |host| + host, port = host.split(':') + all_alive = false unless Minio::Helpers.check_remote_port(host, port) + end + all_alive + end + + def self.exists_minio_conf? + File.exist?('/etc/default/minio') + end + + def self.s3_ready? + command_output = `serf members list` + + nodes = command_output.split("\n") + leader_node = nodes.find { |node| node.include?('s3=ready') } + + if leader_node + true + else + false + end + end + end +end diff --git a/resources/metadata.rb b/resources/metadata.rb index 7ea9215..c1df86a 100644 --- a/resources/metadata.rb +++ b/resources/metadata.rb @@ -3,4 +3,4 @@ maintainer_email 'git@redborder.com' license 'AGPL-3.0' description 'Installs/Configures Minio' -version '0.0.5' +version '1.0.0' diff --git a/resources/providers/config.rb b/resources/providers/config.rb index 1f266b5..c3b58f4 100644 --- a/resources/providers/config.rb +++ b/resources/providers/config.rb @@ -2,6 +2,16 @@ begin user = new_resource.user + s3_bucket = new_resource.s3_bucket + s3_endpoint = new_resource.s3_endpoint + + if !Minio::Helpers.s3_ready? + s3_user = Minio::Helpers.generate_random_key(20) + s3_password = Minio::Helpers.generate_random_key(40) + else + s3_user = new_resource.access_key_id + s3_password = new_resource.secret_key_id + end dnf_package 'minio' do action :upgrade @@ -27,7 +37,38 @@ service_name 'minio' ignore_failure true supports status: true, reload: true, restart: true, enable: true - action [:start, :enable] + action [:enable, :start] + only_if { Minio::Helpers.exists_minio_conf? } + end + + template '/etc/default/minio' do + source 'minio.erb' + variables( + s3_user: s3_user, + s3_password: s3_password + ) + notifies :restart, 'service[minio]', :delayed + end + + unless Minio::Helpers.s3_ready? + template '/etc/redborder/s3_init_conf.yml' do + source 's3_init_conf.yml.erb' + variables( + s3_user: s3_user, + s3_password: s3_password, + s3_bucket: s3_bucket, + s3_endpoint: s3_endpoint + ) + end + + template '/root/.s3cfg_initial' do + source 's3cfg_initial.erb' + variables( + s3_user: s3_user, + s3_password: s3_password, + s3_endpoint: s3_endpoint + ) + end end Chef::Log.info('Minio cookbook has been processed') @@ -36,6 +77,34 @@ end end +action :add_s3_conf_nginx do + service 'nginx' do + service_name 'nginx' + ignore_failure true + supports status: true, reload: true, restart: true, enable: true + action [:nothing] + end + + execute 'rb_sync_minio_cluster' do + command '/usr/lib/redborder/bin/rb_sync_minio_cluster.sh' + action :nothing + end + + s3_hosts = new_resource.s3_hosts + template '/etc/nginx/conf.d/s3.conf' do + ignore_failure true + source 's3.conf.erb' + owner 'nginx' + group 'nginx' + mode '0644' + cookbook 'nginx' + variables(s3_hosts: s3_hosts) + notifies :restart, 'service[nginx]', :delayed + notifies :run, 'execute[rb_sync_minio_cluster]', :delayed + only_if { Minio::Helpers.check_remote_hosts(s3_hosts) } + end +end + action :remove do begin @@ -51,6 +120,7 @@ Chef::Log.error(e.message) end end + action :register do ipaddress = new_resource.ipaddress diff --git a/resources/resources/config.rb b/resources/resources/config.rb index 72fba91..948280e 100644 --- a/resources/resources/config.rb +++ b/resources/resources/config.rb @@ -1,8 +1,12 @@ -actions :add, :remove, :register, :deregister +actions :add, :remove, :register, :deregister, :add_s3_conf_nginx default_action :add attribute :user, kind_of: String, default: 'minio' attribute :group, kind_of: String, default: 'minio' attribute :port, kind_of: Integer, default: 9000 - +attribute :access_key_id, kind_of: String, default: 'redborder' +attribute :secret_key_id, kind_of: String, default: 'redborder' +attribute :s3_bucket, kind_of: String, default: 'bucket' +attribute :s3_endpoint, kind_of: String, default: 's3.service' attribute :ipaddress, kind_of: String, default: '127.0.0.1' +attribute :s3_hosts, kind_of: Array, default: ['localhost:9000'] diff --git a/resources/templates/default/minio.erb b/resources/templates/default/minio.erb new file mode 100644 index 0000000..4973ec5 --- /dev/null +++ b/resources/templates/default/minio.erb @@ -0,0 +1,4 @@ +MINIO_OPTS="--address :9000 --console-address :9001 --config-dir /etc/minio" +MINIO_VOLUMES=/var/minio/data +MINIO_ROOT_USER=<%= @s3_user %> +MINIO_ROOT_PASSWORD=<%= @s3_password %> \ No newline at end of file diff --git a/resources/templates/default/s3_init_conf.yml.erb b/resources/templates/default/s3_init_conf.yml.erb new file mode 100644 index 0000000..aeb9a54 --- /dev/null +++ b/resources/templates/default/s3_init_conf.yml.erb @@ -0,0 +1,6 @@ +--- +s3: + access_key: <%=@s3_user%> + secret_key: <%=@s3_password%> + bucket: <%=@s3_bucket%> + endpoint: <%=@s3_endpoint%> \ No newline at end of file diff --git a/resources/templates/default/s3cfg_initial.erb b/resources/templates/default/s3cfg_initial.erb new file mode 100644 index 0000000..c86b588 --- /dev/null +++ b/resources/templates/default/s3cfg_initial.erb @@ -0,0 +1,8 @@ +[default] +access_key = <%=@s3_user%> +secret_key = <%=@s3_password%> +check_ssl_certificate = False +check_ssl_hostname = False +host_base = <%=@s3_endpoint%> +host_bucket = <%=@s3_endpoint%> +use_https = True \ No newline at end of file