Skip to content

Commit

Permalink
Support Litefs database migrations with multiple machines in primary
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Apr 9, 2024
1 parent 42e716c commit d15301e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 3 deletions.
6 changes: 5 additions & 1 deletion lib/generators/templates/Dockerfile.erb
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,11 @@ ENV <%= deploy_env.join(" \\\n ") %>
<% else -%>
# Entrypoint sets up the container.
<% end -%>
<% if using_litefs? -%>
ENTRYPOINT ["litefs", "mount"]
<% else -%>
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
<% end -%>
<% if procfile.size > 1 -%>
# Build a Procfile for production use
Expand All @@ -307,7 +311,7 @@ VOLUME /data
CMD ["foreman", "start", "--procfile=<%= options.procfile %>"]
<% elsif procfile.size > 1 -%>
CMD ["foreman", "start", "--procfile=Procfile.prod"]
<% else -%>
<% elsif !using_litefs? -%>
CMD <%= procfile.values.first.split(" ").inspect %>
<% end -%>
<% end -%>
18 changes: 18 additions & 0 deletions lib/generators/templates/litefs.yml.erb
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ proxy:
# "static" which assigns a single node to be the primary and does
# not failover.
lease:
promote: true

# Required. Must be either "consul" or "static".
type: "consul"

Expand Down Expand Up @@ -114,3 +116,19 @@ lease:
# can become leader. This buffer is intended to prevent
# overlap in leadership due to clock skew or in-flight calls.
lock-delay: "1s"

exec:
# Only run migrations on candidate nodes.
- cmd: "./bin/rails db:prepare"
if-candidate: true

# Then run the application server on all nodes.
<% if !options.procfile.blank? -%>
- cmd: "foreman start --procfile=<%= options.procfile %>"
<% elsif procfile.size > 1 -%>
- cmd: "foreman start --procfile=Procfile.prod"
<% elsif !using_litefs? -%>
- cmd: <%= procfile.values.first.split(" ").inspect %>
<% else -%>
- cmd: "./bin/rails server"
<% end -%>
3 changes: 1 addition & 2 deletions test/results/litefs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,8 @@ ENV DATABASE_URL="sqlite3:///litefs/production.sqlite3" \
PORT="3001"

# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
ENTRYPOINT ["litefs", "mount"]

# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
VOLUME /data
CMD ["./bin/rails", "server"]
11 changes: 11 additions & 0 deletions test/results/litefs/config/litefs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ proxy:
# "static" which assigns a single node to be the primary and does
# not failover.
lease:
promote: true

# Required. Must be either "consul" or "static".
type: "consul"

Expand Down Expand Up @@ -114,3 +116,12 @@ lease:
# can become leader. This buffer is intended to prevent
# overlap in leadership due to clock skew or in-flight calls.
lock-delay: "1s"

exec:
# Only run migrations on candidate nodes.
- cmd: "./bin/rails db:prepare"
if-candidate: true

# Then run the application server on all nodes.
- cmd: "./bin/rails server"

0 comments on commit d15301e

Please sign in to comment.