Skip to content

Commit

Permalink
Initial gem code (#1)
Browse files Browse the repository at this point in the history
Read the README for the best overview of this gem. The entry point is `minio_runner.rb` and there are rake tasks you can see with `rake -T -a`.
  • Loading branch information
martin-brennan committed Aug 15, 2023
1 parent f650e88 commit da102d3
Show file tree
Hide file tree
Showing 29 changed files with 1,466 additions and 1 deletion.
49 changes: 49 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: CI

on:
pull_request:
push:
branches:
- main

jobs:
build:
runs-on: ubuntu-latest

strategy:
matrix:
ruby:
- 2.7
- 3.0
- 3.1
- 3.2

steps:
- uses: actions/checkout@v2

- name: Setup ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- name: Rubocop
run: bundle exec rubocop

- name: MiniTest
run: bundle exec rake test

publish:
if: github.event_name == 'push' && (github.ref == 'refs/heads/main')
needs: build
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Release Gem
uses: discourse/publish-rubygems-action@v2
env:
RUBYGEMS_API_KEY: ${{ secrets.RUBYGEMS_API_KEY }}
GIT_EMAIL: team@discourse.org
GIT_NAME: discoursebot
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/
2 changes: 2 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
inherit_gem:
rubocop-discourse: stree-compat.yml
2 changes: 2 additions & 0 deletions .streerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
--print-width=100
--plugins=plugin/trailing_comma,disable_ternary
10 changes: 10 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

source "https://rubygems.org"

# Specify your gem's dependencies in minio_runner.gemspec
gemspec

gem "rake", "~> 13.0"

gem "minitest", "~> 5.0"
93 changes: 93 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
PATH
remote: .
specs:
minio_runner (0.1.0)

GEM
remote: https://rubygems.org/
specs:
ansi (1.5.0)
ast (2.4.2)
builder (3.2.4)
byebug (11.1.3)
coderay (1.1.3)
json (2.6.3)
language_server-protocol (3.17.0.3)
method_source (1.0.0)
minitest (5.19.0)
minitest-color (0.0.2)
minitest (~> 5)
minitest-line (0.6.5)
minitest (~> 5.0)
minitest-reporters (1.6.1)
ansi
builder
minitest (>= 5.0)
ruby-progressbar
parallel (1.23.0)
parser (3.2.2.3)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
pry (0.14.2)
coderay (~> 1.1)
method_source (~> 1.0)
pry-byebug (3.10.1)
byebug (~> 11.0)
pry (>= 0.13, < 0.15)
racc (1.7.1)
rainbow (3.1.1)
rake (13.0.6)
regexp_parser (2.8.1)
rexml (3.2.6)
rubocop (1.55.1)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.2.2.3)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.28.1, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.29.0)
parser (>= 3.2.1.0)
rubocop-capybara (2.18.0)
rubocop (~> 1.41)
rubocop-discourse (3.3.0)
rubocop (>= 1.1.0)
rubocop-rspec (>= 2.0.0)
rubocop-factory_bot (2.23.1)
rubocop (~> 1.33)
rubocop-rspec (2.23.0)
rubocop (~> 1.33)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
ruby-progressbar (1.13.0)
spy (1.0.5)
syntax_tree (6.1.1)
prettier_print (>= 1.2.0)
syntax_tree-disable_ternary (1.0.0)
unicode-display_width (2.4.2)

PLATFORMS
arm64-darwin-21
x86_64-linux

DEPENDENCIES
minio_runner!
minitest (~> 5.0)
minitest-color
minitest-line
minitest-reporters
pry
pry-byebug
rake (~> 13.0)
rubocop-discourse
spy
syntax_tree
syntax_tree-disable_ternary

BUNDLED WITH
2.4.13
21 changes: 21 additions & 0 deletions LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2023 Martin Brennan

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
162 changes: 161 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,163 @@
# MinioRunner

Manages the installed minio binary and handles setup and teardown of the minio server.
Manages the installed [minio](https://min.io/) binary and handles setup and
teardown of the minio server.

## Description

This is a simple way of managing the locally installed minio server using an
installed binary. This can be used to start/stop the server when running
automated tests or developing locally against an S3 alternative. It also
installs the [`mc` (minio client)](https://min.io/docs/minio/linux/reference/minio-mc.html) CLI
tool to make interacting with the server easier.

This an extremely focused gem and will not focus on all possible different
configurations and binaries of minio. Only Linux and macOS platforms are
supported at this time.

This gem was inspired by the [webdrivers](https://github.com/titusfortner/webdrivers)
project.

## Usage

In your Gemfile:

```ruby
gem 'minio_runner', require: false
```

In your project:

```ruby
require 'minio_runner'
```

The minio runner will not automatically locate, download, and start minio. You
will need to use the following calls; for example in your before/after suite
setup and teardown for rspec.

```ruby
# Locate and download the minio binary if it does not exist, and start the server with provided configuration.
# The binary will be updated if the new version (which is checked every time `MinioRunner.cache_time` expires)
# is greater than the installed version.
MinioRunner.start

# Stop the currently running server.
MinioRunner.stop
```

### Download Location

The default download location is `~/.minio_runner` directory, and this is configurable:

```ruby
MinioRunner.config.install_dir = '/minio_runner/install/dir'
```

Alternatively, you can define the path via the `MINIO_RUNNER_INSTALL_DIR` environment variable.
The environment variable will take precedence.

### Caching minio version

You can set Minio Runner to only look for updates if the previous check
was longer ago than a specified number of seconds.

```ruby
MinioRunner.config.cache_time = 86_400 # Default: 86,400 Seconds (24 hours)
```

Alternatively, you can define the time via the `MINIO_RUNNER_CACHE_TIME` environment variable.
The environment variable will take precedence.

### Rake tasks

You can run `bundle exec rake -T -a` to see all the rake tasks. The ones specifically related to
minio runner will be namespaced into minio_runner.

### Logging

The logging level can be configured for debugging purpose via the `MINIO_RUNNER_LOG_LEVEL` environment variable.

The available values are found in https://ruby-doc.org/stdlib-2.4.0/libdoc/logger/rdoc/Logger/Severity.html.

The minio server will log to the `install_dir` in a `minio.log` file.

## Minio configuration

Only a small subset of minio configuration (defined at https://min.io/docs/minio/linux/reference/minio-server/minio-server.html#environment-variables)
is supported. The subset of configuration options can be found from running the `list_configurable_env`
rake task.

All minio configuration can also be specified via `MinioRunner.config`, and anything
set in this way will override environment variables. Environment variables should
be in the format `MINIO_RUNNER_MINIO_X`:

```ruby
MinioRunner.config do |config|
config.minio_port = 9000 # MINIO_RUNNER_MINIO_PORT
config.minio_console_address = 9001 # MINIO_RUNNER_MINO_CONSOLE_ADDRESS
config.minio_domain = 'minio.local' # MINIO_RUNNER_MINIO_DOMAIN
end
```

The configuration in ruby will use the exact same names as the environment
variables for minio.

### Aliases

By default a `local` alias is automatically created via the `mc` tool, which will point
to `localhost` at the configured `MINIO_RUNNER_MINIO_PORT`. No other aliases are supported
at this time.

### Buckets

You can specify the buckets that will be created (if they do not exist) when the minio server
starts using the `MinioRunner.config` call above or using the `MINIO_RUNNER_BUCKETS` environment
variable with a comma-separated list. Only S3-compatible buckets will be made.

```ruby
MinioRunner.config.buckets = ["testbucket", "media"]

# MINIO_RUNNER_BUCKETS="testbucket,media"
```

Buckets will be made public to anonymous users if they are specified in the `public_buckets` configuration,
which can also be set with the `MINIO_RUNNER_PUBLIC_BUCKETS` environment variable.

### Hosts file

**An important step** that you must manually do yourself is to modify your `/etc/hosts` file to add an
entry for your minio server defined by `MINIO_RUNNER_MINIO_DOMAIN` and also for any bucket defined
via `MINIO_RUNNER_BUCKETS`, since they will be used as virtual-host style buckets.

For example:

```
127.0.0.1 minio.local
127.0.0.1 testbucket.minio.local
```

For macOS, there are some issues which cause large delays for .local domain names. See
https://superuser.com/a/1297335/245469 and https://stackoverflow.com/a/17982964/875941. To
resolve this, you need to add IPV6 lookup addresses to the hosts file, and it helps to put
all the entries on one line.

```
::1 minio.local testbucket.minio.local
fe80::1%lo0 minio.local testbucket.minio.local
127.0.0.1 minio.local testbucket.minio.local
```

## Development

After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` 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 the created tag, 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/discourse/minio_runner.

## License

The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
Loading

0 comments on commit da102d3

Please sign in to comment.