Skip to content

Commit

Permalink
Merge pull request #25 from redBorder/development
Browse files Browse the repository at this point in the history
release 1.0.0
  • Loading branch information
davidredborder authored Jun 13, 2024
2 parents 5ba9685 + d83d090 commit ad3a03c
Show file tree
Hide file tree
Showing 11 changed files with 188 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Style/SpecialGlobalVars:
Enabled: false
36 changes: 36 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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]

<!-- Badges -->
[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

Expand Down
7 changes: 7 additions & 0 deletions resources/attributes/default.rb
Original file line number Diff line number Diff line change
@@ -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
44 changes: 44 additions & 0 deletions resources/libraries/minio_helpers.rb
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion resources/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
maintainer_email '[email protected]'
license 'AGPL-3.0'
description 'Installs/Configures Minio'
version '0.0.5'
version '1.0.0'
72 changes: 71 additions & 1 deletion resources/providers/config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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')
Expand All @@ -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

Expand All @@ -51,6 +120,7 @@
Chef::Log.error(e.message)
end
end

action :register do
ipaddress = new_resource.ipaddress

Expand Down
8 changes: 6 additions & 2 deletions resources/resources/config.rb
Original file line number Diff line number Diff line change
@@ -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']
4 changes: 4 additions & 0 deletions resources/templates/default/minio.erb
Original file line number Diff line number Diff line change
@@ -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 %>
6 changes: 6 additions & 0 deletions resources/templates/default/s3_init_conf.yml.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
s3:
access_key: <%=@s3_user%>
secret_key: <%=@s3_password%>
bucket: <%=@s3_bucket%>
endpoint: <%=@s3_endpoint%>
8 changes: 8 additions & 0 deletions resources/templates/default/s3cfg_initial.erb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit ad3a03c

Please sign in to comment.