Skip to content

Commit 79df635

Browse files
committed
Default setup, fix assets
1 parent 77f3650 commit 79df635

File tree

10 files changed

+57
-7
lines changed

10 files changed

+57
-7
lines changed

Dockerfile

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ RUN if [ -f "package.json" ]; then \
4646
yarn install; \
4747
fi
4848

49+
# Build assets (CSS and JavaScript)
50+
RUN if [ -f "package.json" ]; then \
51+
yarn build:css && \
52+
yarn build; \
53+
fi
54+
55+
# Precompile assets with Propshaft
56+
RUN SECRET_KEY_BASE_DUMMY=1 ./bin/rails assets:precompile
57+
4958
# Precompile bootsnap code for faster boot times
5059
RUN bundle exec bootsnap precompile app/ lib/
5160

Gemfile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ gem "cssbundling-rails"
2929
# Bundle and transpile JavaScript
3030
gem "jsbundling-rails"
3131

32+
# Asset pipeline
33+
gem "propshaft"
34+
3235
# Use Kredis to get higher-level data types in Redis [https://github.com/rails/kredis]
3336
# gem "kredis"
3437

Gemfile.lock

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,11 @@ GEM
236236
prettyprint
237237
prettyprint (0.2.0)
238238
prism (1.4.0)
239+
propshaft (1.1.0)
240+
actionpack (>= 7.0.0)
241+
activesupport (>= 7.0.0)
242+
rack
243+
railties (>= 7.0.0)
239244
psych (5.2.6)
240245
date
241246
stringio
@@ -445,6 +450,7 @@ DEPENDENCIES
445450
lograge (~> 0.14)
446451
pagy (~> 6.2)
447452
pg (~> 1.1)
453+
propshaft
448454
puma (>= 5.0)
449455
pundit (~> 2.3)
450456
rack-attack (~> 6.7)

app/assets/config/manifest.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
//= link_tree ../builds

app/controllers/admin/sessions_controller.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
module Admin
2-
class SessionsController < ApplicationController
3-
protect_from_forgery with: :exception
2+
class SessionsController < Admin::BaseController
3+
skip_before_action :authenticate_admin!, only: [:new, :create]
4+
skip_before_action :check_maintenance_mode, only: [:new, :create]
45
layout "admin_login"
56

67
def new

app/views/layouts/admin.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
<%= csp_meta_tag %>
88
<%= action_cable_meta_tag %>
99

10-
<%= stylesheet_link_tag "/assets/application", "data-turbo-track": "reload" %>
11-
<%= javascript_include_tag "/assets/application", "data-turbo-track": "reload", type: "module" %>
10+
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
11+
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
1212
</head>
1313

1414
<body class="bg-gray-50" data-controller="mobile-menu">

app/views/layouts/admin_login.html.erb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
<%= csrf_meta_tags %>
77
<%= csp_meta_tag %>
88

9-
<%= stylesheet_link_tag "/assets/application", "data-turbo-track": "reload" %>
10-
<%= javascript_include_tag "/assets/application", "data-turbo-track": "reload", type: "module" %>
9+
<%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
10+
<%= javascript_include_tag "application", "data-turbo-track": "reload", type: "module" %>
1111
</head>
1212

1313
<body class="bg-gray-50">

bin/docker-entrypoint

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,23 @@
22

33
# If running the rails server then create or migrate existing database
44
if [ "${1}" == "./bin/rails" ] && [ "${2}" == "server" ]; then
5-
bundle exec rails db:prepare
5+
echo "Setting up database..."
6+
7+
# First ensure database exists
8+
bundle exec rails db:create 2>/dev/null || true
9+
10+
# Check if schema has been loaded (by checking if any tables exist)
11+
if bundle exec rails runner "exit ActiveRecord::Base.connection.tables.empty? ? 1 : 0" 2>/dev/null; then
12+
# Tables exist, just migrate
13+
echo "Database already initialized, running migrations..."
14+
bundle exec rails db:migrate
15+
else
16+
# No tables, need to load schema
17+
echo "Loading database schema..."
18+
bundle exec rails db:schema:load
19+
echo "Seeding database..."
20+
bundle exec rails db:seed
21+
fi
622
fi
723

824
# If running rspec, automatically set RAILS_ENV=test

config/initializers/assets.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# Be sure to restart your server when you modify this file.
2+
3+
# Version of assets, change this if you want to expire all your assets.
4+
Rails.application.config.assets.version = "1.0"
5+
6+
# Configure propshaft to use the correct asset path
7+
Rails.application.config.assets.prefix = '/assets'
8+
9+
# Since we're using jsbundling-rails and cssbundling-rails,
10+
# we need to ensure the asset helpers use the correct paths
11+
if Rails.env.development? || Rails.env.test?
12+
# In development, assets are served directly from the builds directory
13+
Rails.application.config.assets.debug = true
14+
end
File renamed without changes.

0 commit comments

Comments
 (0)