Skip to content

Commit

Permalink
Revive the live demo
Browse files Browse the repository at this point in the history
Closes #3537, Refs. #3635
  • Loading branch information
mshibuya committed Aug 6, 2023
1 parent 2379583 commit 5ca8ccb
Show file tree
Hide file tree
Showing 12 changed files with 185 additions and 7 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ RailsAdmin is a Rails engine that provides an easy-to-use interface for managing
- Check out [the docs][docs].
- Try the [live demo][demo]. ([Source code][dummy_app])

[demo]: http://rails-admin-tb.herokuapp.com/
[dummy_app]: https://github.com/bbenezech/dummy_app
[demo]: https://rails-admin.fly.dev/admin/
[dummy_app]: https://github.com/railsadminteam/rails_admin/tree/master/spec/dummy_app
[docs]: https://github.com/railsadminteam/rails_admin/wiki

## Features
Expand Down
39 changes: 39 additions & 0 deletions spec/dummy_app/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# See https://docs.docker.com/engine/reference/builder/#dockerignore-file for more about ignoring files.

# Ignore git directory.
/.git/

# Ignore bundler config.
/.bundle

# Ignore all default key files.
/config/master.key
/config/credentials/*.key

# Ignore all environment files.
/.env*
!/.env.example

# Ignore all logfiles and tempfiles.
/log/*
/tmp/*
!/log/.keep
!/tmp/.keep

# Ignore pidfiles, but keep the directory.
/tmp/pids/*
!/tmp/pids/
!/tmp/pids/.keep

# Ignore storage (uploaded files in development and any SQLite databases).
/storage/*
!/storage/.keep
/tmp/storage/*
!/tmp/storage/
!/tmp/storage/.keep

# Ignore assets.
/node_modules/
/app/assets/builds/*
!/app/assets/builds/.keep
/public/assets
1 change: 1 addition & 0 deletions spec/dummy_app/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

/public/system

/public/assets
/public/packs
/public/packs-test
/node_modules
Expand Down
87 changes: 87 additions & 0 deletions spec/dummy_app/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# syntax = docker/dockerfile:1

# Make sure RUBY_VERSION matches the Ruby version in .ruby-version and Gemfile
ARG RUBY_VERSION=3.1.2
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"

# Update gems and bundler
RUN gem update --system --no-document && \
gem install -N bundler

# Install packages needed to install nodejs
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y curl && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Install Node.js
# ARG NODE_VERSION=18.16.0
# ENV PATH=/usr/local/node/bin:$PATH
# RUN curl -sL https://github.com/nodenv/node-build/archive/master.tar.gz | tar xz -C /tmp/ && \
# /tmp/node-build-master/bin/node-build "${NODE_VERSION}" /usr/local/node && \
# rm -rf /tmp/node-build-master

# Throw-away build stage to reduce size of final image
FROM base as build

# Install packages needed to build gems and node modules
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y build-essential default-libmysqlclient-dev git libpq-dev libvips node-gyp pkg-config python-is-python3

# Build options
ENV PATH="/usr/local/node/bin:$PATH"

# Install application gems
COPY --link Gemfile ./
RUN sed -i "s/, path: '..\/..\/'//" Gemfile
RUN bundle install && \
rm -rf ~/.bundle/ $BUNDLE_PATH/ruby/*/cache $BUNDLE_PATH/ruby/*/bundler/gems/*/.git

# Install node modules
# COPY --link package.json ./
# RUN npm install

# Copy application code
COPY --link . .
RUN sed -i "s/, path: '..\/..\/'//" Gemfile

# Precompiling assets for production without requiring secret RAILS_MASTER_KEY
RUN sed -i "/link_tree ..\/..\/..\//d" app/assets/config/manifest.js
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 curl default-mysql-client imagemagick libsqlite3-0 libvips postgresql-client && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives

# Copy built artifacts: gems, application
COPY --from=build /usr/local/bundle /usr/local/bundle
COPY --from=build /rails /rails

# Run and own only the runtime files as a non-root user for security
RUN useradd rails --create-home --shell /bin/bash && \
chown -R rails:rails db log tmp public/system public/uploads
USER rails:rails

# Deployment options
ENV RAILS_LOG_TO_STDOUT="1" \
RAILS_SERVE_STATIC_FILES="true"

# 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"]
2 changes: 1 addition & 1 deletion spec/dummy_app/Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ group :active_record do
end

gem 'carrierwave', '>= 2.0.0.rc', '< 3.0'
gem 'cssbundling-rails'
gem 'cssbundling-rails', require: false
gem 'devise', '>= 3.2'
gem 'dragonfly', '~> 1.0'
gem 'importmap-rails', require: false
Expand Down
8 changes: 8 additions & 0 deletions spec/dummy_app/bin/docker-entrypoint
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash -e

# If running the rails server then create or migrate existing database
if [ "${*}" == "./bin/rails server" ]; then
./bin/rails db:create db:migrate db:seed
fi

exec "${@}"
4 changes: 4 additions & 0 deletions spec/dummy_app/config/database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,7 @@ development:
test:
<<: *sqlite
database: db/test.sqlite3

production:
<<: *sqlite
database: db/production.sqlite3
6 changes: 6 additions & 0 deletions spec/dummy_app/config/dockerfile.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# generated by dockerfile-rails
---
options:
label:
fly_launch_runtime: rails
sentry: false
2 changes: 1 addition & 1 deletion spec/dummy_app/config/environments/production.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
config.static_cache_control = 'public, max-age=31536000'

# Compress JavaScripts and CSS.
config.assets.js_compressor = :uglifier
# config.assets.js_compressor = :uglifier
# config.assets.css_compressor = :sass

# Do not fallback to assets pipeline if a precompiled asset is missed.
Expand Down
6 changes: 3 additions & 3 deletions spec/dummy_app/config/initializers/dragonfly.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

require 'dragonfly'

# Logger
Dragonfly.logger = Rails.logger

# Configure
Dragonfly.app.configure do
plugin :imagemagick
Expand All @@ -16,8 +19,5 @@
server_root: Rails.root.join('public'))
end

# Logger
Dragonfly.logger = Rails.logger

# Mount as middleware
Rails.application.middleware.use Dragonfly::Middleware
11 changes: 11 additions & 0 deletions spec/dummy_app/config/initializers/rails_admin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,15 @@
include_all_fields
field :color, :hidden
end

if Rails.env.production?
# Live demo configuration
c.main_app_name = ['RailsAdmin', 'Live Demo']
c.included_models = %w[Comment Division Draft Fan FieldTest League NestedFieldTest Player Team User]
c.model 'FieldTest' do
configure :paperclip_asset do
visible false
end
end
end
end
22 changes: 22 additions & 0 deletions spec/dummy_app/fly.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# fly.toml app configuration file generated for rails-admin on 2023-08-06T18:22:31+09:00
#
# See https://fly.io/docs/reference/configuration/ for information about how to use this file.
#

app = "rails-admin"
primary_region = "iad"
console_command = "/rails/bin/rails console"

[build]

[http_service]
internal_port = 3000
force_https = true
auto_stop_machines = true
auto_start_machines = true
min_machines_running = 0
processes = ["app"]

[[statics]]
guest_path = "/rails/public"
url_prefix = "/"

0 comments on commit 5ca8ccb

Please sign in to comment.