I’m running litestack + sqlite on a rails app, and my production data appears to be different from data I can query when sshing into my server and checking in the Rails console. I’ve even gone so far as to delete my production db directories from /data and /db, but when I check my production app there is still persistent data there that I can’t seem to access or modify. I’m a little puzzled as to how I can modify or reset my prod db.
Here’s my dockerfile:
# syntax = docker/dockerfile:1
# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.3.0
FROM ruby:$RUBY_VERSION-slim as base
LABEL fly_launch_runtime="rails"
# Rails app lives here
WORKDIR /rails
# Set production environment
ENV RAILS_ENV="production" \
BUNDLE_WITHOUT="development:test" \
BUNDLE_DEPLOYMENT="1"
# Update gems and bundler
RUN gem update --system --no-document && \
gem install -N bundler
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build gems
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential git pkg-config
# Install application gems
COPY --link Gemfile Gemfile.lock ./
RUN bundle install && \
bundle exec bootsnap precompile --gemfile && \
rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git
# Copy application code
COPY --link . .
# Precompile bootsnap code for faster boot times
RUN bundle exec bootsnap precompile app/ lib/
# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN SECRET_KEY_BASE=DUMMY ./bin/rails assets:precompile
# Final stage for app image
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y libsqlite3-0 && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Run and own the application files as a non-root user for security
RUN useradd rails --home /rails --shell /bin/bash
USER rails:rails
# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build --chown=rails:rails /rails /rails
# Create /data directory and set permissions
USER root
RUN mkdir -p /data && chown -R rails:rails /data
USER rails:rails
# Sqlite data will be stored in data.
VOLUME /data
# Deployment options
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true" \
LITESTACK_DATA_PATH="/data"
# Entrypoint prepares the database.
ENTRYPOINT ["/rails/bin/docker-entrypoint"]
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD ["./bin/rails", "server"]
fly config:
# fly.toml app configuration file generated for music-assistant-dev-bold-surf-3433 on 2024-08-05T09:17:48-06:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#
app = 'music-assistant-dev'
primary_region = 'sjc'
console_command = '/rails/bin/rails console'
[build]
[deploy]
release_command = './bin/rails db:prepare'
[[restart]]
policy = "on-failure"
retries = 10
processes = ["app"]
[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = 'off'
auto_start_machines = true
min_machines_running = 1
processes = ['app']
[[vm]]
memory = '1gb'
cpu_kind = 'shared'
cpus = 1
[[statics]]
guest_path = '/rails/public'
url_prefix = '/'
[mounts]
source="litestack_data"
destination="/data"
database.yml:
# SQLite. Versions 3.8.0 and up are supported.
# gem install sqlite3
#
# Ensure the SQLite 3 gem is defined in your Gemfile
# gem "sqlite3"
#
# `Litesupport.root.join("data.sqlite3")` stores
# application data in the path `./db/#{Rails.env}/data.sqlite3`
#
# `Litesupport.root(env).join(path)` stores
# application data in the path `./db/#{env}/#{path}`
#
# idle_timeout should be set to zero, to avoid recycling sqlite connections
# and losing the page cache
#
default: &default
adapter: litedb
pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
idle_timeout: 0
development:
<<: *default
database: <%= Litesupport.root("development").join("data.sqlite3") %>
# Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake".
# Do not set this db to the same as development or production.
test:
<<: *default
database: <%= Litesupport.root("test").join("data.sqlite3") %>
# Warning: Make sure your production database path is on a persistent
# volume, otherwise your application data could be deleted between deploys.
#
# You may also set the Litesupport.root in production via the
# `LITESTACK_DATA_PATH` environment variable.
production:
<<: *default
database: <%= Litesupport.root("production").join("data.sqlite3") %>