Add Litestream->R2 replication + start.sh + Dockerfile for AWS Fargate (#1)

pull/688/head
Omar Shaarawi 3 weeks ago committed by GitHub
parent ca9e6cedbf
commit 24816341db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -40,6 +40,8 @@ COPY ./app/views ./app/views
RUN echo "gem 'shakapacker'" > Gemfile && ./bin/shakapacker RUN echo "gem 'shakapacker'" > Gemfile && ./bin/shakapacker
FROM litestream/litestream:0.5.11 AS litestream
FROM ruby:4.0.1-alpine AS app FROM ruby:4.0.1-alpine AS app
ENV RAILS_ENV=production ENV RAILS_ENV=production
@ -95,5 +97,11 @@ ENV HOME=/home/docuseal
ENV WORKDIR=/data/docuseal ENV WORKDIR=/data/docuseal
ENV VIPS_MAX_COORD=17000 ENV VIPS_MAX_COORD=17000
# Litestream: restore-on-boot + continuous replication of the SQLite db to R2.
COPY --from=litestream /usr/local/bin/litestream /usr/local/bin/litestream
COPY litestream.yml /etc/litestream.yml
COPY scripts/start.sh /usr/local/bin/start.sh
RUN chmod +x /usr/local/bin/start.sh
EXPOSE 3000 EXPOSE 3000
CMD ["/app/bin/bundle", "exec", "puma", "-C", "/app/config/puma.rb", "--dir", "/app"] CMD ["/usr/local/bin/start.sh"]

@ -0,0 +1,13 @@
# Litestream: replicate docuseal's SQLite db to R2 (same creds/bucket as attachments).
dbs:
- path: /data/docuseal/db.sqlite3
replicas:
- type: s3
bucket: ${S3_ATTACHMENTS_BUCKET}
path: litestream/docuseal
endpoint: ${S3_ENDPOINT}
region: auto
access-key-id: ${AWS_ACCESS_KEY_ID}
secret-access-key: ${AWS_SECRET_ACCESS_KEY}
sync-interval: 60s
retention: 168h

@ -0,0 +1,9 @@
#!/bin/sh
set -e
DB=/data/docuseal/db.sqlite3
mkdir -p /data/docuseal
if [ ! -f "$DB" ]; then
echo "[start.sh] DB missing — restoring from R2 via litestream..."
litestream restore -if-replica-exists -config /etc/litestream.yml "$DB" || echo "[start.sh] WARN: restore failed; starting empty."
fi
exec litestream replicate -config /etc/litestream.yml -exec "/app/bin/bundle exec puma -C /app/config/puma.rb --dir /app"
Loading…
Cancel
Save