- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我在 Google Cloud Run 中有一个可用的 Rails 应用程序,使用:
Redis::CannotConnectError (Error connecting to Redis on 127.0.0.1:6379 (Errno::ECONNREFUSED)):
steps:
# Decrypt Rails Master key file
- name: gcr.io/cloud-builders/gcloud
args: ["kms", "decrypt", "--ciphertext-file=./config/master.key.enc",
"--plaintext-file=./config/master.key",
"--location=us-central1","--keyring=project_name",
"--key=rails_master_key"]
# Decrypt Whale on Rails service account credentials
- name: gcr.io/cloud-builders/gcloud
args: ["kms", "decrypt", "--ciphertext-file=./config/project_name_runner.key.enc",
"--plaintext-file=./config/project_name_runner.key",
"--location=us-central1","--keyring=project_name",
"--key=project_name_runner_key"]
# Build image with tag 'latest' and pass decrypted Rails DB password as argument
- name: 'gcr.io/cloud-builders/docker'
args: [ 'build',
'--tag', 'gcr.io/$PROJECT_ID/project_name:latest',
'--build-arg', 'DB_PWD',
'--build-arg', 'RUBY_VERSION=${_RUBY_VERSION}',
'--build-arg', 'PG_MAJOR=${_PG_MAJOR}',
'--build-arg', 'NODE_MAJOR=${_NODE_MAJOR}',
'--build-arg', 'BUNDLER_VERSION=${_BUNDLER_VERSION}',
'--build-arg', 'RAILS_ENV=${_RAILS_ENV}',
'--build-arg', 'REDIS_URL=${_REDIS_URL}',
'--build-arg', 'DATABASE_HOST=${_DATABASE_HOST}',
'--build-arg', 'DATABASE_USER=${_DATABASE_USER}',
'--build-arg', 'DATABASE_NAME=${_DATABASE_NAME}',
'.'
]
secretEnv: ['DB_PWD']
# Push new image to Google Cloud Registry
- name: 'gcr.io/cloud-builders/docker'
args: ['push', 'gcr.io/$PROJECT_ID/project_name:latest']
secrets:
- kmsKeyName: projects/project_name/locations/us-central1/keyRings/project_name/cryptoKeys/db_pwd_key
secretEnv:
DB_PWD: "db_password"
substitutions:
_RUBY_VERSION: '2.7.0'
_PG_MAJOR: '11'
_NODE_MAJOR: '12'
_BUNDLER_VERSION: '2.1.2'
_RAILS_ENV: production
_REDIS_URL: redis://redis:6379/
_DATABASE_HOST: /cloudsql/project_name:us-central1:project_name-production
_DATABASE_USER: production_user
_DATABASE_NAME: project_name-production
#!/usr/bin/env bash
cd /usr/src/app
# Create the Rails production DB on first run
bundle exec rake db:prepare
# Do some protective cleanup
> log/production.log
rm -f tmp/pids/server.pid
# Run the web service on container startup
# $PORT is provided as an environment variable by Cloud Run
bundle exec rails server -b 0.0.0.0 -p $PORT
# Run sidekiq in production
bundle exec sidekiq -C config/sidekiq.yml
# Leverage the official Ruby image from Docker Hub
# https://hub.docker.com/_/ruby
ARG RUBY_VERSION
FROM ruby:$RUBY_VERSION
LABEL maintainer="myemail@gmail.com"
ARG PG_MAJOR
ARG NODE_MAJOR
ARG BUNDLER_VERSION
ARG RAILS_ENV
# Add PostgreSQL to sources list
RUN curl -sSL https://www.postgresql.org/media/keys/ACCC4CF8.asc | apt-key add - \
&& echo 'deb http://apt.postgresql.org/pub/repos/apt/ stretch-pgdg main' $PG_MAJOR > /etc/apt/sources.list.d/pgdg.list
# Install recent versions of nodejs (10.x) and yarn pkg manager
# Needed to properly pre-compile Rails assets
RUN (curl -sL https://deb.nodesource.com/setup_$NODE_MAJOR.x | bash -) && apt-get update && apt-get install -y nodejs
# Add Yarn to the sources list
RUN (curl -sS https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -) && \
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list && \
apt-get update && apt-get install -y yarn
# Install production dependencies (Gems installation in
# local vendor directory)
WORKDIR /usr/src/app
COPY Gemfile Gemfile.lock ./
ENV BUNDLE_FROZEN=true
RUN gem update --system && \
gem install bundler:$BUNDLER_VERSION
RUN bundle install
# Copy application code to the container image.
# Note: files listed in .gitignore are not copied
# (e.g.secret files)
COPY . .
# Pre-compile Rails assets (master key needed)
RUN yarn install
RUN RAILS_ENV=production bundle exec rake assets:precompile
# Set Google App Credentials environment variable with Service Account
ENV GOOGLE_APPLICATION_CREDENTIALS=/usr/src/app/config/sunne_cms_api_runner.key
# Setup Rails DB password passed on docker command line (see Cloud Build file)
ARG DATABASE_NAME
ARG DATABASE_HOST
ARG DATABASE_USER
ARG DB_PWD
ENV DATABASE_PASSWORD=${DB_PWD}
ENV DATABASE_NAME=${DATABASE_NAME}
ENV DATABASE_HOST=${DATABASE_HOST}
ENV DATABASE_USER=${DATABASE_USER}
# Setting up Rails environment
ENV RAILS_ENV=${RAILS_ENV}
# For now we don't have a Nginx/Apache frontend so tell
# the Puma HTTP server to serve static content
# (e.g. CSS and Javascript files)
ENV RAILS_SERVE_STATIC_FILES=true
# Redirect Rails log to STDOUT for Cloud Run to capture
ENV RAILS_LOG_TO_STDOUT=true
# Designate the initial sript to run on container startup
RUN chmod +x /usr/src/app/entrypoint.sh
ENTRYPOINT ["/usr/src/app/entrypoint.sh"]
最佳答案
如John Hanley提到,Cloud Run 不支持后台处理。不过,根据您的要求,您有几个选择。
选项1
使用单独的服务来运行您的后台作业,可能使用 Cloud Pub/Sub作业准备好时广播的服务到服务消息订阅。您的 Web 服务可以向订阅返回句柄/ID,调用者可以使用它来监听更新。
如果合适,后台服务本身可以在其自己的 Cloud Run 容器中运行,或者由于您似乎在使用 NodeJS,您可以将其打包为 Cloud Function .
选项 2
将您的容器移至支持后台处理的解决方案,例如 App Engine 或 Kubernetes Engine (GKE)。然而,这两者与 Cloud Run 有非常不同的定价模型,并且根据您的使用模式,最终可能会变得更加昂贵。 (此 Google blog post 分解了 GKE 和 Cloud Run 之间的差异。)
GKE 可以处理单容器设置,而无需您直接学习或弄乱 Kubernetes。但是,如果您的项目架构发生变化,或者您需要进行任何配置或故障排除,则可能会涉及大量的学习曲线。
选项 3
改写代码以使用同步处理,保持请求直到作业完成。这只有在您的工作肯定总是在超时(60 秒?)之前完成并且您的最终用例允许的情况下才可行。这是最简单的解决方案,但限制性最强且容易出现面向用户的错误。
关于ruby-on-rails - 在 Google Cloud Run 中使用 Sidekiq 的 Rails 作业不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60297681/
sanitize 是什么意思在 Rails 中是什么意思? 我正在阅读 CanCanCan 的文档.它说: When using strong_parameters or Rails 4+, you
在过去的几个月里,我感觉自己对 Ruby on Rails (RoR) 开发的了解达到了极限。我为大/小客户和 friend /爱好项目开发了大大小小的应用程序。我知道如何开发这些应用程序,但开始感觉
我昨天参加了一个关于扩展 Rails 的聚会,其中一个主题是 Hexagonal Rails。然而,我只做了一年的 Rails,对 MVC 结构非常满意(也许太舒服了),所以我不太了解适配器和消息队列
我使用多个 Rails 应用程序,一些在 Rails 3.2/Ruby 2.0 上,一些在 Rails 2.3/Ruby 1.8.7 上。 他们的共同点是,随着他们的成长和添加更多的依赖项/ gem
这个问题在这里已经有了答案: Using Rails-UJS in JS modules (Rails 6 with webpacker) (5 个答案) 关闭 3 年前。 我正在尝试使用 UJS
我正在开发一个当前使用 Rails 1.2 的 Rails 应用程序,所以我现在离最新的稳定版本(Rails 2.3)还有很长的路要走。 我应该如何进行迁移到更新版本的 Rails 的过程? 我应该一
尝试按照 Ryan Bates Backbone.js 教程构建抽奖应用程序,但我已经遇到了第一段代码的问题。在 application.js 的 init 函数中,他初始化了 Raffler 路由的
我正在使用 Rails 3.2 并且我有一个数据库表,我想在其中找到符合以下条件的所有行: a = true and b = true and ( 0 true, :b =>
我有一个用户类和一个联系人,其中联系人是用户的子类。这两个类都存储在用户表中。 我的联系人可能有也可能没有电子邮件地址,而我的用户需要一个电子邮件地址(我的用户模型定义中有 validates_pre
我正在编写一个教程,我在其中演示了一些 rails 命令。在我的机器上 rails和 script/rails两者都同样有效。有“首选”形式吗?两者中哪一个更普遍? 最佳答案 当您运行 rails 时
我正在寻找有关通过我的应用程序前进的最佳方式的建议,这是我首次开始集成Elasticsearch。我是一名初学者,但是热衷于深入研究,以便原谅任何明显的错误! 我遵循了http://www.sitep
我刚刚用 Rails new 启动了一个新的 Rails 应用程序,将默认数据库设置更改为 PostgresSQL。我用 bin/rails s 启动服务器,结果很奇怪 2016-04-21 05:0
我收到一个参数并希望它是这样的字符串: "abc,efg" 或者像这样的数组 ["abc","efg"] 在第一种情况下,我想将它转换成一个数组,什么是好的方法? 这是我的想法 if params[:
我刚刚用 Rails new 启动了一个新的 Rails 应用程序,将默认数据库设置更改为 PostgresSQL。我用 bin/rails s 启动服务器,结果很奇怪 2016-04-21 05:0
我收到一个参数并希望它是这样的字符串: "abc,efg" 或者像这样的数组 ["abc","efg"] 在第一种情况下,我想将它转换成一个数组,什么是好的方法? 这是我的想法 if params[:
我有 Rails 4,这是我的默认版本(我仍然希望它是)。但我不想在我的电脑上添加 rails 3.2。在以下命令中:gem install rails -v 3.2.16 我有这个警告: railt
您好,我想使用 Sheevaplug 构建一个“Rails Brick”来自 Marvell(操作系统是开箱即用的 Ubuntu,但您可以在其上安装其他发行版)。它将成为家庭服务器和静音、低成本(99
我需要能够从 Rails 控制台发送我的 Rails 应用程序的 Postgres 数据库中所有未接受的邀请。 (我有一个名为 Invitations 的表,其中包含一个名为 accepted 的 b
validate :cannot_modify_if_locked, on: :update def cannot_modify_if_locked if self.locked erro
我正在学习教程(学习 Rails 播客),需要更改以下路由语法,以便它与 Rails 3.0 兼容。谁能帮忙? map.view_page ':name', :controller => 'viewe
我是一名优秀的程序员,十分优秀!