gpt4 book ai didi

ruby-on-rails - Github Action 和RAILS_MASTER_KEY

转载 作者:行者123 更新时间:2023-12-03 16:35:22 40 4
gpt4 key购买 nike

我一直在尝试使用Rails设置GitHub Action ,但是RAILS_MASTER_KEY(我的假设)遇到了问题。

这是我在最后一步# Build and run tests中得到的错误消息:

rails aborted!
ActiveSupport::MessageEncryptor::InvalidMessage: ActiveSupport::MessageEncryptor::InvalidMessage
/home/runner/work/my-project/my-project/config/environment.rb:5:in `<main>'
/home/runner/work/my-project/my-project/bin/rails:9:in `<top (required)>'
/home/runner/work/my-project/my-project/bin/spring:15:in `require'
/home/runner/work/my-project/my-project/bin/spring:15:in `<top (required)>'
bin/rails:3:in `load'
bin/rails:3:in `<main>'

Caused by:
ArgumentError: key must be 16 bytes
.github/workflows/main.yml:

name: CI
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
services:
db:
image: postgres:11
env:
POSTGRES_PASSWORD: xxxxxx
ports: ['5432:5432']
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
# Download a copy of the code in the repository before running CI tests
- name: Checkout repository
uses: actions/checkout@v2

# Setup Ruby
- name: Setup Ruby
uses: actions/setup-ruby@v1
with:
ruby-version: 2.6.6

# NPM install
- name: NPM install with caching
uses: bahmutov/npm-install@v1.1.0
# with:
# cmd: install

# Build and run tests
- name: Build and run tests
env:
DATABASE_URL: postgres://postgres:@localhost:5432/test
RAILS_ENV: test
RAILS_MASTER_KEY: ${{ secrets.RAILS_MASTER_KEY }}
run: |
sudo apt-get -yqq install libpq-dev
gem install bundler
bundle install --jobs 4 --retry 3
bundle exec rails db:prepare
bundle exec rails test


我推断这与我的RAILS_MASTER_KEY变量有关。

我检查了存储在项目的ENV变量中的 key ,它恰好是32个字节。我不确定如何最好地进行操作,并且由于担心会破坏应用程序的其他部分而犹豫不决地删除 key 。在我的书中,更可取的是将 key 设置为32字节的合法 key ,因为我不知道如何在何处……

关于如何解决这个问题有什么想法吗?

最佳答案

我遇到了同样的问题,并通过为测试环境创建凭据找到了解决方案。
EDITOR=vim rails credentials:edit --environment --test
您可能需要将测试 key 文件上传到存储库,以便可以解密凭据文件。请注意仅维护测试信息。

我在这里找到了解释:https://blog.saeloun.com/2019/10/10/rails-6-adds-support-for-multi-environment-credentials.html

我在这里上传了我的配置:https://tello.io/ruby-rails-github-actions-mysql

关于ruby-on-rails - Github Action 和RAILS_MASTER_KEY,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61444542/

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com