0
我熟悉Rails,但這是我第一次上傳到生產環境。我能夠成功將我的應用上傳到AWS並進行部署。但是,每次我這樣做,我都必須進入我的服務器並運行必要的rake任務來清理我的模型並完全準備好我的網站。是否有像production.rb這樣的文件,您可以在其中編寫腳本以在每個生產上傳中運行。例如運行所有測試和耙測試?有一個簡單的腳本例子嗎?這是我的rake文件的例子。上傳到生產時始終運行rake任務
注意:我正在使用AWS Beanstalk,超級簡單部署,只是想運行一些後期製作就緒腳本。
這是我想運行部署後命令的rake文件。
require "#{Rails.root}/app/helpers/application_helper"
include ApplicationHelper
namespace :db do
desc "Generate a new blog post markdown"
task new_article: :environment do
cp 'lib/assets/articles/template.md', "lib/assets/articles/NEW_ARTICLE#{Time.now.strftime("%s")}.md"
puts 'new article created!'
end
task populate: :environment do
Article.destroy_all
if User.count == 0
User.create!(name: "AJ", email: "[email protected]")
end
puts Dir.pwd
a = File.join("lib", "assets", "articles", "*.md")
Dir.glob(a).reject { |name| /.*(template|NEW_ARTICLE).*/ =~ name }.each do |file|
File.open(file, "r") do |f|
contents = f.read
mkdown = Metadown.render(contents)
md = mkdown.metadata
unrendered_content = contents.sub(/^---(\n|.)*---/, '')
#puts unrendered_content
article = Article.create!(title: md["title"],
content: markdown(unrendered_content),
header_image: md["header_image"],
published: md["published"],
useful_links: md["useful_links"],
people_mentioned: md["people_mentioned"],
written_at_date: md["written_at_date"],
timestamp: md["timestamp"],
embedded_link: md["embedded_link"],
user: User.first)
article.add_tag(md["tags"])
puts article.useful_links
puts article.people_mentioned
puts article.header_image
puts article.tags
end
end
puts "Article Count: #{Article.count}"
end
end