litestream 0.1.0-x86_64-darwin → 0.2.0-x86_64-darwin
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +76 -12
- data/exe/litestream +1 -1
- data/lib/litestream/commands.rb +52 -43
- data/lib/litestream/generators/litestream/install_generator.rb +32 -0
- data/lib/litestream/generators/litestream/templates/litestream.rb +8 -0
- data/lib/litestream/generators/litestream/templates/litestream.yml +6 -0
- data/lib/litestream/railtie.rb +17 -0
- data/lib/litestream/upstream.rb +1 -1
- data/lib/litestream/version.rb +1 -1
- data/lib/litestream.rb +21 -4
- data/lib/tasks/litestream_tasks.rake +21 -0
- metadata +34 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b23ace1583cc1f70cb4e86d05762dedd415530f8f2d6e8725730a6602fe3582e
|
4
|
+
data.tar.gz: 3628916497bfc379f6a54df34b2979c67077bb1e2bf43a1a62dc3222d2cdc372
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e44dee7e00de45d94f04ec7939387a070c8ce94b9c0509c5456efc080620f3d19f8abcaaec4afc202110f3e010249a7eb6c6142ae47219762fc2410b417652
|
7
|
+
data.tar.gz: b439d6594e7ae2069b7b6119018377a6bed320a60225d9bf49ee3c6a6261e9efa2b63d8561867f2274d09b58c7e90b9929aef3bd7d2b056b2a55fae3c316ce30
|
data/README.md
CHANGED
@@ -1,34 +1,98 @@
|
|
1
|
-
#
|
1
|
+
# litestream-ruby
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/litestream`. To experiment with that code, run `bin/console` for an interactive prompt.
|
3
|
+
[Litestream](https://litestream.io/) is a standalone streaming replication tool for SQLite. This gem provides a Ruby interface to Litestream.
|
6
4
|
|
7
5
|
## Installation
|
8
6
|
|
9
|
-
TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
|
10
|
-
|
11
7
|
Install the gem and add to the application's Gemfile by executing:
|
12
8
|
|
13
|
-
$ bundle add
|
9
|
+
$ bundle add litestream
|
14
10
|
|
15
11
|
If bundler is not being used to manage dependencies, install the gem by executing:
|
16
12
|
|
17
|
-
$ gem install
|
13
|
+
$ gem install litestream
|
14
|
+
|
15
|
+
After installing the gem, run the installer:
|
16
|
+
|
17
|
+
$ rails generate litestream:install
|
18
|
+
|
19
|
+
The installer will create a configuration file at `config/litestream.yml`, an initializer file for configuring the gem at `config/initializers/litestream.rb`, as well as a `Procfile` so that you can run the Litestream replication process alongside your Rails application in production.
|
20
|
+
|
21
|
+
This gem wraps the standalone executable version of the [Litestream](https://litestream.io/install/source/) utility. These executables are platform specific, so there are actually separate underlying gems per platform, but the correct gem will automatically be picked for your platform. Litestream itself doesn't support Windows, so this gem doesn't either.
|
22
|
+
|
23
|
+
Supported platforms are:
|
24
|
+
|
25
|
+
* arm64-darwin (macos-arm64)
|
26
|
+
* x86_64-darwin (macos-x64)
|
27
|
+
* arm64-linux (linux-arm64)
|
28
|
+
* x86_64-linux (linux-x64)
|
29
|
+
|
30
|
+
### Using a local installation of `litestream`
|
31
|
+
|
32
|
+
If you are not able to use the vendored standalone executables (for example, if you're on an unsupported platform), you can use a local installation of the `litestream` executable by setting an environment variable named `LITESTREAM_INSTALL_DIR` to the directory containing the executable.
|
33
|
+
|
34
|
+
For example, if you've installed `litestream` so that the executable is found at `/usr/local/bin/litestream`, then you should set your environment variable like so:
|
35
|
+
|
36
|
+
``` sh
|
37
|
+
LITESTREAM_INSTALL_DIR=/usr/local/bin
|
38
|
+
```
|
39
|
+
|
40
|
+
This also works with relative paths. If you've installed into your app's directory at `./.bin/litestream`:
|
41
|
+
|
42
|
+
``` sh
|
43
|
+
LITESTREAM_INSTALL_DIR=.bin
|
44
|
+
```
|
18
45
|
|
19
46
|
## Usage
|
20
47
|
|
21
|
-
|
48
|
+
### Configuration
|
49
|
+
|
50
|
+
You configure the Litestream executable through the [`config/litestream.yml` file](https://litestream.io/reference/config/), which is a standard Litestream configuration file as if Litestream was running in a traditional installation.
|
51
|
+
|
52
|
+
The gem streamlines the configuration process by providing a default configuration file for you. This configuration file will backup one application database to one replication bucket. In order to ensure that no secrets are stored in plain-text in your repository, this configuration file leverages Litestream's support for environment variables. The default configuration file looks like this:
|
53
|
+
|
54
|
+
```yaml
|
55
|
+
dbs:
|
56
|
+
- path: $LITESTREAM_DATABASE_PATH
|
57
|
+
replicas:
|
58
|
+
- url: $LITESTREAM_REPLICA_URL
|
59
|
+
access-key-id: $LITESTREAM_ACCESS_KEY_ID
|
60
|
+
secret-access-key: $LITESTREAM_SECRET_ACCESS_KEY
|
61
|
+
```
|
62
|
+
|
63
|
+
The gem also provides a default initializer file at `config/initializers/litestream.rb` that allows you to configure these four environment variables referenced in the configuration file in Ruby. By providing a Ruby interface to these environment variables, you can use any method of storing secrets that you prefer. For example, the default generated file uses Rails' encrypted credentials to store your secrets:
|
64
|
+
|
65
|
+
```ruby
|
66
|
+
litestream_credentials = Rails.application.credentials.litestream
|
67
|
+
Litestream.configure do |config|
|
68
|
+
config.database_path = ActiveRecord::Base.connection_db_config.database
|
69
|
+
config.replica_url = litestream_credentials.replica_url
|
70
|
+
config.replica_key_id = litestream_credentials.replica_key_id
|
71
|
+
config.replica_access_key = litestream_credentials.replica_access_key
|
72
|
+
end
|
73
|
+
```
|
74
|
+
|
75
|
+
However, if you need manual control over the Litestream configuration, you can manually edit the `config/litestream.yml` file. The full range of possible configurations are covered in Litestream's [configuration reference](https://litestream.io/reference/config/).
|
76
|
+
|
77
|
+
### Replication
|
78
|
+
|
79
|
+
By default, the gem will create or append to a `Procfile` to start the Litestream process via the gem's provided `litestream:replicate` rake task. This rake task will automatically load the configuration file and set the environment variables before starting the Litestream process.
|
80
|
+
|
81
|
+
Again, however, you can take full manual control over the replication process and simply run the `litestream replicate --config config/litestream.yml` command to start the Litestream process. Since the gem installs the native executable via Bundler, the `litestream` command will be available in your `PATH`.
|
82
|
+
|
83
|
+
The full set of commands available to the `litestream` executable are covered in Litestream's [command reference](https://litestream.io/reference/). Currently, only the `replicate` command is provided as a rake task by the gem.
|
22
84
|
|
23
85
|
## Development
|
24
86
|
|
25
87
|
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.
|
26
88
|
|
27
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
89
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
90
|
+
|
91
|
+
For maintainers, to release a new version, run `bin/release $VERSION`, which will create a git tag for the version, push git commits and tags, and push all of the platform-specific `.gem` files to [rubygems.org](https://rubygems.org).
|
28
92
|
|
29
93
|
## Contributing
|
30
94
|
|
31
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
95
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/fractaledmind/litestream-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/fractaledmind/litestream-ruby/blob/main/CODE_OF_CONDUCT.md).
|
32
96
|
|
33
97
|
## License
|
34
98
|
|
@@ -36,4 +100,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
|
|
36
100
|
|
37
101
|
## Code of Conduct
|
38
102
|
|
39
|
-
Everyone interacting in the Litestream project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/
|
103
|
+
Everyone interacting in the Litestream project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/fractaledmind/litestream-ruby/blob/main/CODE_OF_CONDUCT.md).
|
data/exe/litestream
CHANGED
data/lib/litestream/commands.rb
CHANGED
@@ -17,61 +17,70 @@ module Litestream
|
|
17
17
|
class DirectoryNotFoundException < StandardError
|
18
18
|
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
end
|
20
|
+
def self.platform
|
21
|
+
[:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
|
22
|
+
end
|
24
23
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
else
|
33
|
-
raise DirectoryNotFoundException, <<~MESSAGE
|
34
|
-
LITESTREAM_INSTALL_DIR is set to #{litestream_install_dir}, but that directory does not exist.
|
35
|
-
MESSAGE
|
36
|
-
end
|
24
|
+
def self.executable(exe_path: DEFAULT_DIR)
|
25
|
+
litestream_install_dir = ENV["LITESTREAM_INSTALL_DIR"]
|
26
|
+
if litestream_install_dir
|
27
|
+
if File.directory?(litestream_install_dir)
|
28
|
+
warn "NOTE: using LITESTREAM_INSTALL_DIR to find litestream executable: #{litestream_install_dir}"
|
29
|
+
exe_path = litestream_install_dir
|
30
|
+
exe_file = File.expand_path(File.join(litestream_install_dir, "litestream"))
|
37
31
|
else
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
32
|
+
raise DirectoryNotFoundException, <<~MESSAGE
|
33
|
+
LITESTREAM_INSTALL_DIR is set to #{litestream_install_dir}, but that directory does not exist.
|
34
|
+
MESSAGE
|
35
|
+
end
|
36
|
+
else
|
37
|
+
if Litestream::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
|
38
|
+
raise UnsupportedPlatformException, <<~MESSAGE
|
39
|
+
litestream-ruby does not support the #{platform} platform
|
40
|
+
Please install litestream following instructions at https://litestream.io/install
|
41
|
+
MESSAGE
|
48
42
|
end
|
49
43
|
|
50
|
-
|
51
|
-
|
52
|
-
|
44
|
+
exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "litestream"))).find do |f|
|
45
|
+
Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
|
46
|
+
end
|
47
|
+
end
|
53
48
|
|
54
|
-
|
49
|
+
if exe_file.nil? || !File.exist?(exe_file)
|
50
|
+
raise ExecutableNotFoundException, <<~MESSAGE
|
51
|
+
Cannot find the litestream executable for #{platform} in #{exe_path}
|
55
52
|
|
56
|
-
|
57
|
-
bundle update --bundler
|
53
|
+
If you're using bundler, please make sure you're on the latest bundler version:
|
58
54
|
|
59
|
-
|
55
|
+
gem install bundler
|
56
|
+
bundle update --bundler
|
60
57
|
|
61
|
-
|
62
|
-
bundle install
|
58
|
+
Then make sure your lock file includes this platform by running:
|
63
59
|
|
64
|
-
|
60
|
+
bundle lock --add-platform #{platform}
|
61
|
+
bundle install
|
65
62
|
|
66
|
-
|
67
|
-
`bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
|
68
|
-
https://github.com/fractaledmind/litestream-ruby#check-bundle_force_ruby_platform
|
69
|
-
for more details.
|
70
|
-
MESSAGE
|
71
|
-
end
|
63
|
+
See `bundle lock --help` output for details.
|
72
64
|
|
73
|
-
|
65
|
+
If you're still seeing this message after taking those steps, try running
|
66
|
+
`bundle config` and ensure `force_ruby_platform` isn't set to `true`. See
|
67
|
+
https://github.com/fractaledmind/litestream-ruby#check-bundle_force_ruby_platform
|
68
|
+
for more details.
|
69
|
+
MESSAGE
|
74
70
|
end
|
71
|
+
|
72
|
+
exe_file
|
73
|
+
end
|
74
|
+
|
75
|
+
def self.replicate
|
76
|
+
return if Litestream.configuration.nil?
|
77
|
+
|
78
|
+
ENV["LITESTREAM_DATABASE_PATH"] = Litestream.configuration.database_path
|
79
|
+
ENV["LITESTREAM_REPLICA_URL"] = Litestream.configuration.replica_url
|
80
|
+
ENV["LITESTREAM_ACCESS_KEY_ID"] = Litestream.configuration.replica_key_id
|
81
|
+
ENV["LITESTREAM_SECRET_ACCESS_KEY"] = Litestream.configuration.replica_access_key
|
82
|
+
|
83
|
+
system(executable, "replicate", "--config", Rails.root.join("config", "litestream.yml").to_s)
|
75
84
|
end
|
76
85
|
end
|
77
86
|
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/generators/base"
|
4
|
+
|
5
|
+
module Litestream
|
6
|
+
module Generators
|
7
|
+
class InstallGenerator < ::Rails::Generators::Base
|
8
|
+
source_root File.expand_path("templates", __dir__)
|
9
|
+
|
10
|
+
def copy_config_file
|
11
|
+
template "litestream.yml", "config/litestream.yml"
|
12
|
+
end
|
13
|
+
|
14
|
+
def copy_initializer_file
|
15
|
+
template "litestream.rb", "config/initializers/litestream.rb"
|
16
|
+
end
|
17
|
+
|
18
|
+
def create_or_update_procfile
|
19
|
+
if File.exist?("Procfile")
|
20
|
+
append_to_file "Procfile", "litestream: bin/rails litestream:replicate"
|
21
|
+
else
|
22
|
+
create_file "Procfile" do
|
23
|
+
<<~PROCFILE
|
24
|
+
rails: bundle exec rails server --port $PORT
|
25
|
+
litestream: bin/rails litestream:replicate
|
26
|
+
PROCFILE
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
litestream_credentials = Rails.application.credentials.litestream
|
2
|
+
|
3
|
+
Litestream.configure do |config|
|
4
|
+
config.database_path = ActiveRecord::Base.connection_db_config.database
|
5
|
+
config.replica_url = litestream_credentials.replica_url
|
6
|
+
config.replica_key_id = litestream_credentials.replica_key_id
|
7
|
+
config.replica_access_key = litestream_credentials.replica_access_key
|
8
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "rails/railtie"
|
4
|
+
|
5
|
+
module Litestream
|
6
|
+
class Railtie < ::Rails::Railtie
|
7
|
+
# Load the `litestream:install` generator into the host Rails app
|
8
|
+
generators do
|
9
|
+
require_relative "generators/litestream/install_generator"
|
10
|
+
end
|
11
|
+
|
12
|
+
# Load the `litestream:env` Rake task into the host Rails app
|
13
|
+
rake_tasks do
|
14
|
+
load "tasks/litestream_tasks.rake"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/litestream/upstream.rb
CHANGED
@@ -8,7 +8,7 @@ module Litestream
|
|
8
8
|
"arm64-darwin" => "litestream-#{VERSION}-darwin-arm64.zip",
|
9
9
|
"arm64-linux" => "litestream-#{VERSION}-linux-arm64.tar.gz",
|
10
10
|
"x86_64-darwin" => "litestream-#{VERSION}-darwin-amd64.zip",
|
11
|
-
"x86_64-linux" => "litestream-#{VERSION}-linux-amd64.tar.gz"
|
11
|
+
"x86_64-linux" => "litestream-#{VERSION}-linux-amd64.tar.gz"
|
12
12
|
}
|
13
13
|
end
|
14
14
|
end
|
data/lib/litestream/version.rb
CHANGED
data/lib/litestream.rb
CHANGED
@@ -1,8 +1,25 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative "litestream/version"
|
4
|
-
|
5
3
|
module Litestream
|
6
|
-
class
|
7
|
-
|
4
|
+
class << self
|
5
|
+
attr_accessor :configuration
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.configure
|
9
|
+
self.configuration ||= Configuration.new
|
10
|
+
yield(configuration)
|
11
|
+
end
|
12
|
+
|
13
|
+
class Configuration
|
14
|
+
attr_accessor :database_path, :replica_url, :replica_key_id, :replica_access_key
|
15
|
+
|
16
|
+
def initialize
|
17
|
+
@mailer_sender = "donotreply@example.com"
|
18
|
+
end
|
19
|
+
end
|
8
20
|
end
|
21
|
+
|
22
|
+
require_relative "litestream/version"
|
23
|
+
require_relative "litestream/upstream"
|
24
|
+
require_relative "litestream/commands"
|
25
|
+
require_relative "litestream/railtie" if defined?(::Rails::Railtie)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
namespace :litestream do
|
2
|
+
desc "Print the ENV variables needed for the Litestream config file"
|
3
|
+
task env: :environment do
|
4
|
+
if Litestream.configuration.nil?
|
5
|
+
warn "You have not configured the Litestream gem with any values to generate ENV variables"
|
6
|
+
next
|
7
|
+
end
|
8
|
+
|
9
|
+
puts "LITESTREAM_DATABASE_PATH=#{Litestream.configuration.database_path}"
|
10
|
+
puts "LITESTREAM_REPLICA_URL=#{Litestream.configuration.replica_url}"
|
11
|
+
puts "LITESTREAM_ACCESS_KEY_ID=#{Litestream.configuration.replica_key_id}"
|
12
|
+
puts "LITESTREAM_SECRET_ACCESS_KEY=#{Litestream.configuration.replica_access_key}"
|
13
|
+
|
14
|
+
true
|
15
|
+
end
|
16
|
+
|
17
|
+
desc ""
|
18
|
+
task replicate: :environment do
|
19
|
+
Litestream::Commands.replicate
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litestream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: x86_64-darwin
|
6
6
|
authors:
|
7
7
|
- Stephen Margheim
|
@@ -24,6 +24,34 @@ dependencies:
|
|
24
24
|
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sqlite3
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
27
55
|
description:
|
28
56
|
email:
|
29
57
|
- stephen.margheim@gmail.com
|
@@ -40,8 +68,13 @@ files:
|
|
40
68
|
- exe/x86_64-darwin/litestream
|
41
69
|
- lib/litestream.rb
|
42
70
|
- lib/litestream/commands.rb
|
71
|
+
- lib/litestream/generators/litestream/install_generator.rb
|
72
|
+
- lib/litestream/generators/litestream/templates/litestream.rb
|
73
|
+
- lib/litestream/generators/litestream/templates/litestream.yml
|
74
|
+
- lib/litestream/railtie.rb
|
43
75
|
- lib/litestream/upstream.rb
|
44
76
|
- lib/litestream/version.rb
|
77
|
+
- lib/tasks/litestream_tasks.rake
|
45
78
|
homepage: https://github.com/fractaledmind/litestream-ruby
|
46
79
|
licenses:
|
47
80
|
- MIT
|