litestream 0.3.2 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +4 -4
- data/lib/litestream/commands.rb +7 -3
- data/lib/litestream/generators/litestream/install_generator.rb +11 -1
- data/lib/litestream/generators/litestream/templates/{config.yml → config.yml.erb} +6 -2
- data/lib/litestream/generators/litestream/templates/initializer.rb +9 -14
- data/lib/litestream/version.rb +1 -1
- data/lib/litestream.rb +1 -1
- data/lib/tasks/litestream_tasks.rake +1 -2
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3437fcda9be45b8f50a4fcae89e6cc07d3ea590d7e3f0d2f10e50c9f8c6058b6
|
4
|
+
data.tar.gz: f53e83796ed362491b50929d2924d070b6efa166830f7de6195e39300121be81
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d8731b80f97dee5bc512e4f4acd58aebb63a435379736d281edc8bd2b42e6cc524c2eb7a55fefc2cf93218b91b2fb12c4fe180685031c9924dacd73a918fe344
|
7
|
+
data.tar.gz: 209fec5c3e355675feeee661ca64194cae370b85cbe90e162aaa2df059b2ccc5806b44e94daf706c29140e106e716eb1d3505a5efeeec65dfecbe4ee763ece09
|
data/README.md
CHANGED
@@ -49,13 +49,13 @@ LITESTREAM_INSTALL_DIR=.bin
|
|
49
49
|
|
50
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
51
|
|
52
|
-
The gem streamlines the configuration process by providing a default configuration file for you. This configuration file will backup
|
52
|
+
The gem streamlines the configuration process by providing a default configuration file for you. This configuration file will backup all SQLite databases defined in your `config/database.yml` file 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 if you only have one SQLite database:
|
53
53
|
|
54
54
|
```yaml
|
55
55
|
dbs:
|
56
56
|
- path: $LITESTREAM_DATABASE_PATH
|
57
57
|
replicas:
|
58
|
-
- url: $
|
58
|
+
- url: $LITESTREAM_REPLICA_BUCKET
|
59
59
|
access-key-id: $LITESTREAM_ACCESS_KEY_ID
|
60
60
|
secret-access-key: $LITESTREAM_SECRET_ACCESS_KEY
|
61
61
|
```
|
@@ -66,7 +66,7 @@ The gem also provides a default initializer file at `config/initializers/litestr
|
|
66
66
|
litestream_credentials = Rails.application.credentials.litestream
|
67
67
|
Litestream.configure do |config|
|
68
68
|
config.database_path = ActiveRecord::Base.connection_db_config.database
|
69
|
-
config.
|
69
|
+
config.replica_bucket = litestream_credentials.replica_bucket
|
70
70
|
config.replica_key_id = litestream_credentials.replica_key_id
|
71
71
|
config.replica_access_key = litestream_credentials.replica_access_key
|
72
72
|
end
|
@@ -113,7 +113,7 @@ Once you have a MinIO server running, you can create a bucket for Litestream to
|
|
113
113
|
```ruby
|
114
114
|
Litestream.configure do |config|
|
115
115
|
config.database_path = ActiveRecord::Base.connection_db_config.database
|
116
|
-
config.
|
116
|
+
config.replica_bucket = "s3://mybkt.localhost:9000/"
|
117
117
|
config.replica_key_id = "minioadmin"
|
118
118
|
config.replica_access_key = "minioadmin"
|
119
119
|
end
|
data/lib/litestream/commands.rb
CHANGED
@@ -74,8 +74,7 @@ module Litestream
|
|
74
74
|
|
75
75
|
def self.replicate(argv = {})
|
76
76
|
if Litestream.configuration
|
77
|
-
ENV["
|
78
|
-
ENV["LITESTREAM_REPLICA_URL"] = Litestream.configuration.replica_url
|
77
|
+
ENV["LITESTREAM_REPLICA_BUCKET"] = Litestream.configuration.replica_bucket
|
79
78
|
ENV["LITESTREAM_ACCESS_KEY_ID"] = Litestream.configuration.replica_key_id
|
80
79
|
ENV["LITESTREAM_SECRET_ACCESS_KEY"] = Litestream.configuration.replica_access_key
|
81
80
|
end
|
@@ -86,7 +85,12 @@ module Litestream
|
|
86
85
|
|
87
86
|
command = [executable, "replicate", *args]
|
88
87
|
puts command.inspect
|
89
|
-
|
88
|
+
|
89
|
+
# To release the resources of the Ruby process, just fork and exit.
|
90
|
+
# The forked process executes litestream and replaces itself.
|
91
|
+
if fork.nil?
|
92
|
+
exec(*command)
|
93
|
+
end
|
90
94
|
end
|
91
95
|
end
|
92
96
|
end
|
@@ -8,7 +8,7 @@ module Litestream
|
|
8
8
|
source_root File.expand_path("templates", __dir__)
|
9
9
|
|
10
10
|
def copy_config_file
|
11
|
-
template "config.yml", "config/litestream.yml"
|
11
|
+
template "config.yml.erb", "config/litestream.yml"
|
12
12
|
end
|
13
13
|
|
14
14
|
def copy_initializer_file
|
@@ -27,6 +27,16 @@ module Litestream
|
|
27
27
|
end
|
28
28
|
end
|
29
29
|
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def production_sqlite_databases
|
34
|
+
ActiveRecord::Base
|
35
|
+
.configurations
|
36
|
+
.configs_for(env_name: "production", include_hidden: true)
|
37
|
+
.select { |config| ["sqlite3", "litedb"].include? config.adapter }
|
38
|
+
.map(&:database)
|
39
|
+
end
|
30
40
|
end
|
31
41
|
end
|
32
42
|
end
|
@@ -10,8 +10,12 @@
|
|
10
10
|
#
|
11
11
|
# For more details, see: https://litestream.io/reference/config/
|
12
12
|
dbs:
|
13
|
-
|
13
|
+
<%- production_sqlite_databases.each do |database| -%>
|
14
|
+
- path: <%= database %>
|
14
15
|
replicas:
|
15
|
-
-
|
16
|
+
- type: s3
|
17
|
+
bucket: $LITESTREAM_REPLICA_BUCKET
|
18
|
+
path: <%= database %>
|
16
19
|
access-key-id: $LITESTREAM_ACCESS_KEY_ID
|
17
20
|
secret-access-key: $LITESTREAM_SECRET_ACCESS_KEY
|
21
|
+
<%- end -%>
|
@@ -1,30 +1,25 @@
|
|
1
1
|
# Use this hook to configure the litestream-ruby gem.
|
2
2
|
# All configuration options will be available as environment variables, e.g.
|
3
|
-
# config.
|
3
|
+
# config.replica_bucket becomes LITESTREAM_REPLICA_BUCKET
|
4
4
|
# This allows you to configure Litestream using Rails encrypted credentials,
|
5
5
|
# or some other mechanism where the values are only avaialble at runtime.
|
6
6
|
|
7
7
|
Litestream.configure do |config|
|
8
8
|
# An example of using Rails encrypted credentials to configure Litestream.
|
9
9
|
# litestream_credentials = Rails.application.credentials.litestream
|
10
|
-
#
|
11
|
-
# The absolute or relative path to a SQLite database file.
|
12
|
-
# Litestream will monitor this file for changes and replicate them to the
|
13
|
-
# any of the configured replicas specified for this database in the
|
14
|
-
# `litestream.yml` configuration file.
|
15
|
-
# When using SQLite as your database engine for ActiveRecord, you should always
|
16
|
-
# set this to the path of your SQLite database file. You can do so using Rails'
|
17
|
-
# existing knowledge of the database path.
|
18
|
-
# config.database_path = ActiveRecord::Base.connection_db_config.database
|
19
10
|
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
11
|
+
# Replica-specific bucket location.
|
12
|
+
# This will be your bucket's URL without the `https://` prefix.
|
13
|
+
# For example, if you used DigitalOcean Spaces, your bucket URL could look like:
|
14
|
+
# https://myapp.fra1.digitaloceanspaces.com
|
15
|
+
# And so you should set your `replica_bucket` to:
|
16
|
+
# myapp.fra1.digitaloceanspaces.com
|
17
|
+
# Litestream supports Azure Blog Storage, Backblaze B2, DigitalOcean Spaces,
|
23
18
|
# Scaleway Object Storage, Google Cloud Storage, Linode Object Storage, and
|
24
19
|
# any SFTP server.
|
25
20
|
# In this example, we are using Rails encrypted credentials to store the URL to
|
26
21
|
# our storage provider bucket.
|
27
|
-
# config.
|
22
|
+
# config.replica_bucket = litestream_credentials.replica_bucket
|
28
23
|
|
29
24
|
# Replica-specific authentication key.
|
30
25
|
# Litestream needs authentication credentials to access your storage provider bucket.
|
data/lib/litestream/version.rb
CHANGED
data/lib/litestream.rb
CHANGED
@@ -11,7 +11,7 @@ module Litestream
|
|
11
11
|
end
|
12
12
|
|
13
13
|
class Configuration
|
14
|
-
attr_accessor :database_path, :
|
14
|
+
attr_accessor :database_path, :replica_bucket, :replica_key_id, :replica_access_key
|
15
15
|
|
16
16
|
def initialize
|
17
17
|
@mailer_sender = "donotreply@example.com"
|
@@ -6,8 +6,7 @@ namespace :litestream do
|
|
6
6
|
next
|
7
7
|
end
|
8
8
|
|
9
|
-
puts "
|
10
|
-
puts "LITESTREAM_REPLICA_URL=#{Litestream.configuration.replica_url}"
|
9
|
+
puts "LITESTREAM_REPLICA_BUCKET=#{Litestream.configuration.replica_bucket}"
|
11
10
|
puts "LITESTREAM_ACCESS_KEY_ID=#{Litestream.configuration.replica_key_id}"
|
12
11
|
puts "LITESTREAM_SECRET_ACCESS_KEY=#{Litestream.configuration.replica_access_key}"
|
13
12
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: litestream
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Stephen Margheim
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-04-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rubyzip
|
@@ -67,7 +67,7 @@ files:
|
|
67
67
|
- lib/litestream.rb
|
68
68
|
- lib/litestream/commands.rb
|
69
69
|
- lib/litestream/generators/litestream/install_generator.rb
|
70
|
-
- lib/litestream/generators/litestream/templates/config.yml
|
70
|
+
- lib/litestream/generators/litestream/templates/config.yml.erb
|
71
71
|
- lib/litestream/generators/litestream/templates/initializer.rb
|
72
72
|
- lib/litestream/railtie.rb
|
73
73
|
- lib/litestream/upstream.rb
|