【发布时间】:2020-06-05 06:00:41
【问题描述】:
我似乎无法找到为 Ruby on Rails 6 - AWS Elastic Beanstalk - Docker 部署设置 secret_key_base 的正确方法。因此,部署不断失败。我一直在尝试遵循本教程:https://dev.to/fdoxyz/elastic-beanstalk-apps-using-docker-containers-56l8
系统:
- Ubuntu 18.04
- ruby 2.6.5p114(2019-10-01 修订版 67812)[x86_64-linux]
- 捆绑器版本 2.1.4
- Rails 6.0.2.1
- Docker 版本 18.09.7,构建 2d0083d
- 节点 v12.16.1
以下是我从空目录到部署的步骤:
mkdir new_project && cd new_project
eb init
2) us-west-1 : US West (N. California)
2) [ Create new Application ]
(default is "new_project")
8) Docker
Do you want to set up SSH for your instances? Y
Select a keypair.
eb create
Enter Environment Name (default is new-project-dev)
Enter DNS CNAME prefix (default is new-project-dev)
Select a load balancer type: 2) application
enable Spot Fleet? n
download the sample application into the current directory? n
eb setenv SECRET_KEY_BASE=$(ruby -e "require 'securerandom';puts SecureRandom.hex(64)")
eb setenv RAILS_ENV=production
cat .gitignore
rails new .
vim .gitignore (paste old contents of gitignore)
touch Dockerfile
vim Dockerfile
===============
FROM ruby:2.6.5
# Install NodeJS & Yarn
RUN apt-get update && \
apt-get install apt-transport-https && \
curl -sL https://deb.nodesource.com/setup_12.x | bash - && \
apt-get purge nodejs && \
apt-get update && \
apt-get install nodejs -y && \
npm install yarn -g && \
gem install bundler -v 2.1.4
# Workdir and add dependencies
WORKDIR /app/
ADD Gemfile Gemfile.lock /app/
# Throw errors if Gemfile has been modified since Gemfile.lock
RUN bundle config --global frozen 1
# Install dependencies
ARG RAILS_MASTER_KEY
ENV RAILS_ENV=production NODE_ENV=production RAILS_SERVE_STATIC_FILES=1
RUN bundle install --without development test
# Add the app code, precompile assets and use non-root user
ADD . /app/
RUN rake assets:precompile DISABLE_SPRING=1 && \
chown -R nobody:nogroup /app
USER nobody
ENV HOME /app
# Make sure to explicitly bind to port & interface
CMD ["bundle", "exec", "rails s -p 3000 -b 0.0.0.0"]
===============
vim config/environments/production.rb
insert at the top of the file:
config.secret_key_base = ENV["SECRET_KEY_BASE"]
git add . && git commit -m "Initial commit"
eb use new_project-dev
eb deploy
这是从 ssh 到 '/var/log/eb-activity.log' 实例的完整日志:
https://raw.githubusercontent.com/maxtocarev/eb-log/master/eb-activity.log
【问题讨论】:
标签: ruby-on-rails docker amazon-elastic-beanstalk