litestream 0.1.0-arm64-darwin → 0.2.0-arm64-darwin

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: ba3d41e45459ea5427ad79a6bbbc78cbae7408eb2685df02f96eae492a449def
4
- data.tar.gz: 920101e69bc187bfda96c3affd0b9606ee13f01dacc767143b66a7cef00ee058
3
+ metadata.gz: cbc4b2b3270f8d3bacc5955d079070b38d187072236da0518179c6bf01bbcba2
4
+ data.tar.gz: f2404ce88dc567c8939084d0c669b7a98de2345d8cc86ba567b201fa589cdea5
5
5
  SHA512:
6
- metadata.gz: b88fa89f49f6a55113c15690e465d75b28e0a940085bc3964409f0d52f6b3a5037727e9d02641f9ecb0a6ad248ce6dd5e99e509210adf2000a34cde3f1eb5822
7
- data.tar.gz: 1bd391d152a8652bd5ab1e22dac577e1936e2fc22bb36ef2f84d02250483add296092b3214fbc4e581959b4930830610eb001cd7e6a323ba965da7caab265da1
6
+ metadata.gz: cb2dc8fffdaf734d950f2e4302ce0ddfe39812d83128c6d90ec07a9da0a4b6b0449684ad9d1bd004c0dc084411b14b4db75f070fd736a526cf00489714b47b3e
7
+ data.tar.gz: c9d09c933a53684d46ac99e7b446394ce98b3c2c859bc984b9653513882bd6bf6d07d9e9766075b13e7c6e1cee665dc26bbecca8e5b0e4b2ead75e14f205a5e7
data/README.md CHANGED
@@ -1,34 +1,98 @@
1
- # Litestream
1
+ # litestream-ruby
2
2
 
3
- TODO: Delete this and the text below, and describe your gem
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 UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
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 UPDATE_WITH_YOUR_GEM_NAME_PRIOR_TO_RELEASE_TO_RUBYGEMS_ORG
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
- TODO: Write usage instructions here
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`. 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).
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/[USERNAME]/litestream. 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/[USERNAME]/litestream/blob/main/CODE_OF_CONDUCT.md).
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/[USERNAME]/litestream/blob/main/CODE_OF_CONDUCT.md).
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
@@ -8,6 +8,6 @@ begin
8
8
  puts command.inspect
9
9
  exec(*command)
10
10
  rescue Litestream::Commands::UnsupportedPlatformException, Litestream::Commands::ExecutableNotFoundException => e
11
- STDERR.puts("ERROR: " + e.message)
11
+ warn("ERROR: " + e.message)
12
12
  exit 1
13
13
  end
@@ -17,61 +17,70 @@ module Litestream
17
17
  class DirectoryNotFoundException < StandardError
18
18
  end
19
19
 
20
- class << self
21
- def platform
22
- [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
23
- end
20
+ def self.platform
21
+ [:cpu, :os].map { |m| Gem::Platform.local.send(m) }.join("-")
22
+ end
24
23
 
25
- def executable(exe_path: DEFAULT_DIR)
26
- litestream_install_dir = ENV["LITESTREAM_INSTALL_DIR"]
27
- if litestream_install_dir
28
- if File.directory?(litestream_install_dir)
29
- warn "NOTE: using LITESTREAM_INSTALL_DIR to find litestream executable: #{litestream_install_dir}"
30
- exe_path = litestream_install_dir
31
- exe_file = File.expand_path(File.join(litestream_install_dir, "litestream"))
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
- if Litestream::Upstream::NATIVE_PLATFORMS.keys.none? { |p| Gem::Platform.match_gem?(Gem::Platform.new(p), GEM_NAME) }
39
- raise UnsupportedPlatformException, <<~MESSAGE
40
- litestream-ruby does not support the #{platform} platform
41
- Please install litestream following instructions at https://litestream.io/install
42
- MESSAGE
43
- end
44
-
45
- exe_file = Dir.glob(File.expand_path(File.join(exe_path, "*", "litestream"))).find do |f|
46
- Gem::Platform.match_gem?(Gem::Platform.new(File.basename(File.dirname(f))), GEM_NAME)
47
- end
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
- if exe_file.nil? || !File.exist?(exe_file)
51
- raise ExecutableNotFoundException, <<~MESSAGE
52
- Cannot find the litestream executable for #{platform} in #{exe_path}
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
- If you're using bundler, please make sure you're on the latest bundler version:
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
- gem install bundler
57
- bundle update --bundler
53
+ If you're using bundler, please make sure you're on the latest bundler version:
58
54
 
59
- Then make sure your lock file includes this platform by running:
55
+ gem install bundler
56
+ bundle update --bundler
60
57
 
61
- bundle lock --add-platform #{platform}
62
- bundle install
58
+ Then make sure your lock file includes this platform by running:
63
59
 
64
- See `bundle lock --help` output for details.
60
+ bundle lock --add-platform #{platform}
61
+ bundle install
65
62
 
66
- If you're still seeing this message after taking those steps, try running
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
- exe_file
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,6 @@
1
+ dbs:
2
+ - path: $LITESTREAM_DATABASE_PATH
3
+ replicas:
4
+ - url: $LITESTREAM_REPLICA_URL
5
+ access-key-id: $LITESTREAM_ACCESS_KEY_ID
6
+ secret-access-key: $LITESTREAM_SECRET_ACCESS_KEY
@@ -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
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Litestream
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
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 Error < StandardError; end
7
- # Your code goes here...
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.1.0
4
+ version: 0.2.0
5
5
  platform: arm64-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/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