#!/bin/bash # 简化的Rails应用启动脚本 set -e echo "🚀 启动Rails应用..." # 如果没有Rails应用,创建一个 if [ ! -f config/database.yml ]; then echo "📝 创建新的Rails应用..." rails new . --force --database=sqlite3 --skip-git --skip-bundle fi # 安装依赖 echo "📦 安装依赖..." bundle install # 创建数据库 echo "🗄️ 创建数据库..." rails db:create db:migrate || true # 创建示例控制器 if [ ! -f app/controllers/welcome_controller.rb ]; then echo "📝 创建示例页面..." cat > app/controllers/welcome_controller.rb <<'RUBY' class WelcomeController < ApplicationController def index @hostname = Socket.gethostname @rails_version = Rails.version @ruby_version = RUBY_VERSION end end RUBY mkdir -p app/views/welcome cat > app/views/welcome/index.html.erb <<'HTML' Rails 8.1 on K3s
💎

Rails <%= @rails_version %> on K3s

✅ 运行正常

Ruby版本: <%= @ruby_version %>

Rails版本: <%= @rails_version %>

数据库: SQLite3

Pod主机名: <%= @hostname %>

访问域名: r1.jpd.net3w.com

部署方式: GitOps (Gitea + ArgoCD)

集群: JPD K3s Cluster

<%= Time.now.strftime("%Y-%m-%d %H:%M:%S") %>

HTML # 配置路由 if ! grep -q "root.*welcome#index" config/routes.rb 2>/dev/null; then cat > config/routes.rb <<'RUBY' Rails.application.routes.draw do root "welcome#index" get "up" => "rails/health#show", as: :rails_health_check end RUBY fi fi # 启动服务器 echo "🌐 启动Rails服务器..." exec rails server -b 0.0.0.0 -p 3000