【问题标题】:How to update config based on envronment for middleman s3_sync?如何根据中间人 s3_sync 的环境更新配置?
【发布时间】:2021-12-12 16:48:23
【问题描述】:

我正在尝试根据环境将 slate 文档推送到 2 个不同的 S3 存储桶。 但它抱怨 s3_sync 不是中间人的参数。

我已经使用 config.rb 提到了环境中的 S3 存储桶,但是当我运行 bundle exec middleman s3_sync --verbose --environment=internal 时仍然遇到上述问题

config.rb:

configure :internal do
  s3_sync.bucket                     = ENV['INTERNAL_DOCS_AWS_BUCKET'] # The name of the internal docs S3 bucket you are targeting. This is globally unique.
end

activate :s3_sync do |s3_sync|
  s3_sync.bucket                     = ENV['DOCS_AWS_BUCKET'] # The name of the S3 bucket you are targeting. This is globally unique.
  s3_sync.region                     = ENV['DOCS_AWS_REGION']     # The AWS region for your bucket.
  s3_sync.aws_access_key_id          = ENV['DOCS_AWS_ACCESS_KEY_ID']
  s3_sync.aws_secret_access_key      = ENV['DOCS_AWS_SECRET_ACCESS_KEY']
  s3_sync.prefer_gzip                = true
  s3_sync.path_style                 = true
  s3_sync.reduced_redundancy_storage = false
  s3_sync.acl                        = 'public-read'
  s3_sync.encryption                 = false
  s3_sync.prefix                     = ''
  s3_sync.version_bucket             = false
  s3_sync.index_document             = 'index.html'
  s3_sync.error_document             = '404.html'
end

错误:

捆绑器:加载失败命令:中间人 (/usr/local/bundle/bin/middleman) NameError: undefined local variable 或 #Middleman::ConfigContext:0x0000561eca099a40 的方法 `s3_sync'

【问题讨论】:

    标签: ruby amazon-s3 bundler middleman


    【解决方案1】:

    s3_sync 仅在 activate :s3_sync 块内定义。 它在 configure :internal 块中未定义。

    解决方案可能如下所示,使用 environment?environment

    activate :s3_sync do |s3_sync|
      s3_sync.bucket = if environment?(:internal)
                         ENV['INTERNAL_DOCS_AWS_BUCKET']
                       else
                         ENV['DOCS_AWS_BUCKET']
                       end
      s3_sync.region = ENV['DOCS_AWS_REGION']
      # ...
    end
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-19
      • 2018-11-11
      • 1970-01-01
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      相关资源
      最近更新 更多