Skip to content

Commit

Permalink
restore litefs test
Browse files Browse the repository at this point in the history
  • Loading branch information
rubys committed Jan 5, 2025
1 parent a276650 commit 6dfc362
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 8 deletions.
22 changes: 15 additions & 7 deletions test/results/litefs/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,13 @@ RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
# Final stage for app image
FROM base

# Install, configure litefs
COPY --from=flyio/litefs:0.5 /usr/local/bin/litefs /usr/local/bin/litefs
COPY config/litefs.yml /etc/litefs.yml

# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl libsqlite3-0 && \
apt-get install --no-install-recommends -y ca-certificates curl fuse3 libsqlite3-0 sudo && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
Expand All @@ -56,17 +60,21 @@ COPY --from=build /rails /rails
# Run and own only the runtime files as a non-root user for security
RUN groupadd --system --gid 1000 rails && \
useradd rails --uid 1000 --gid 1000 --create-home --shell /bin/bash && \
mkdir /data && \
chown -R 1000:1000 db log storage tmp /data
USER 1000:1000
mkdir /data /litefs && \
chown -R 1000:1000 db log storage tmp /data /litefs

# Authorize rails user to launch litefs
COPY <<-"EOF" /etc/sudoers.d/rails
rails ALL=(root) /usr/local/bin/litefs
EOF

# Deployment options
ENV DATABASE_URL="sqlite3:///data/production.sqlite3"
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 80
VOLUME /data
CMD ["./bin/thrust", "./bin/rails", "server"]
5 changes: 4 additions & 1 deletion test/results/litefs/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
#!/bin/bash -e

# mount litefs
sudo -E litefs mount &

# If running the rails server then create or migrate existing database
if [ "${@: -1:1}" == "./bin/rails server" ]; then
if [ "${@: -2:1}" == "./bin/rails" ] && [ "${@: -1:1}" == "server" ] && [ "$FLY_REGION" == "$PRIMARY_REGION" ]; then
./bin/rails db:prepare
fi

Expand Down

0 comments on commit 6dfc362

Please sign in to comment.