如何根据中间商s3_sync的环境更新配置?



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

我已经使用config提到了环境中的S3桶。rb但当我运行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

错误:

bundler: failed to load command: middleman(/usr/local/bundle/bin/middleman) NameError: undefined local variable或方法' s3_sync'为#Middleman::ConfigContext:0x0000561eca099a40

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

最新更新