How to update config based on envronment for middleman s3_sync?

75 Views Asked by At

I'm trying to push slate docs to 2 different S3 buckets based on the environment. But it's complaining that s3_sync is not a parameter for middleman.

I have mentioned the S3 bucket in the environment using config.rb but still I'm getting the above issue when I run 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

Error:

bundler: failed to load command: middleman (/usr/local/bundle/bin/middleman) NameError: undefined local variable or method `s3_sync' for #Middleman::ConfigContext:0x0000561eca099a40

1

There are 1 best solutions below

0
bbenno On

s3_sync is only defined within the block of activate :s3_sync. It is undefined within the configure :internal block.

A solution might look like the following, using environment? or 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