Rails mina 部署 rails 项目,求 secret_key_base 有关的配置流程,技术背景,求大神们指点迷津。

fengfans · 2023年10月23日 · 最后由 fengfans 回复于 2023年10月26日 · 320 次阅读

开发主机,项目目录下,执行 mina deploy --trace,运行到 Migrating database rake aborted! 提示:ArgumentError: Missing secret_key_base for 'production' environment, set this string with bin/rails credentials:edit 使用 rails 6.1.7.6,ruby 3.0.0。

deploy.rb 配置文件如下

frozen_string_literal: true

require 'mina/rails' require 'mina/git' require 'mina/rbenv' require 'mina/bundler'

require 'mina/rbenv' # for rbenv support. (https://rbenv.org)

require 'mina/rvm' # for rvm support. (https://rvm.io)

Basic settings:

domain - The hostname to SSH to.

deploy_to - Path to deploy into.

repository - Git repo to clone from. (needed by mina/git)

branch - Branch name to deploy. (needed by mina/git)

set :application_name, 'cool' set :domain, '127.0.0.1'

set :deploy_to, '/var/www/html' set :repository, '[email protected]:PP_heroGrow/cool.git' set :branch, 'main'

Optional settings:

set :user, 'f' # Username in the server to SSH to. set :port, '8022' # SSH port number. set :forward_agent, false # SSH forward_agent.

Some plugins already add folders to shared_dirs like mina/rails add public/assets, vendor/bundle and many more

run mina -d to see all folders and files already included in shared_dirs and shared_files

set :shared_dirs, fetch(:shared_dirs, []).push('public/assets')

set :shared_files, fetch(:shared_files, []).push('config/database.yml', 'config/secrets.yml')

This task is the environment that is loaded for all remote run commands, such as

mina deploy or mina rake.

task :remote_environment do # If you're using rbenv, use this to load the rbenv environment. # Be sure to commit your .ruby-version or .rbenv-version to your repository. invoke :'rbenv:load'

# For those using RVM, use this to load an RVM version@gemset. # invoke :'rvm:use', 'ruby-2.5.3@default' end

Put any custom commands you need to run at setup

All paths in shared_dirs and shared_paths will be created on their own.

task :setup do # command %{rbenv install 2.5.3 --skip-existing} # command %{rvm install ruby-2.5.3} # command %{gem install bundler} end

desc 'Deploys the current version to the server.' task :deploy do # uncomment this line to make sure you pushed your local branch to the remote origin # invoke :'git:ensure_pushed' deploy do # Put things that will set up an empty directory into a fully set-up # instance of your project. invoke :'git:clone' invoke :'deploy:link_shared_paths' invoke :'bundle:install' invoke :'rails:db_migrate' invoke :'rails:assets_precompile' invoke :'deploy:cleanup'

on :launch do in_path(fetch(:current_path)) do command %(mkdir -p tmp/) command %(touch tmp/restart.txt) end end end

# you can use run :local to run tasks on local machine before or after the deploy scripts # run(:local){ say 'done' } end

For help in making your deploy script, see the Mina documentation:

#

- https://github.com/mina-deploy/mina/tree/master/docs

请问使用 mina 部署 rails 项目时,生产环境下的 secret_key_base 如何配置?基本流程是什么?求专家指点迷津。

想简单就直接设置在环境变量里面

感谢指点,后来排查是缺少一个指令:append :linked_files, 'config/database.yml', 'config/master.key'

需要 登录 后方可回复, 如果你还没有账号请 注册新账号