Digital Ocean Spaces .ENV configuration

Hi,

I’m using Trellis with Bedrock to deploy to Kinsta. I’m trying to configure WP Offload Media to upload to Digital Ocean Spaces. The plugin asks me to configure sth like this on wp-config.php:

define( 'AS3CF_SETTINGS', serialize( array(
    'provider' => 'do',
    'access-key-id' => '********************',
    'secret-access-key' => '**************************************',
) ) );

I don’t know how to put this on my .env file every time I deploy to Kinsta. I was thinking of modifying a bit site/config/application.php but maybe this should be done in a Vault file in trellis/group_vars/production/vault.yml. I don’t know how to do the serialization of an array in a YAML file.

Can you show me your approach to this config?

Thank you!!

I handled this issue by dynamically generating an mu-plugin on deploy:

# trellis/deploy-hooks/build-before.yml
- name: Create Offload Media configuation
  template:
    src: "{{ playbook_dir }}/deploy-hooks/offload-media-config.php.j2"
    dest: "{{ deploy_helper.new_release_path }}/web/app/mu-plugins/offload-media-config.php"
    mode: "0600"
// trellis/deploy-hooks/offload-media-config.php.j2
<?php
define('AS3CF_SETTINGS', serialize(array(
    'provider'          => 'do',
    'access-key-id'     => '{{ vault_do_spaces_key_id }}',
    'secret-access-key' => '{{ vault_do_space_secret_key }}',
)));

Then I just define the individual values in my vault; no need for serialization.

2 Likes

Seems the best approach!! I wouldn’t have thought about doing it that way in a million years

Thank you very much Ben ;D

@alwaysblank’s solution is really creative (and works!).

Here’s another solution that should work without any additional tasks. If you define the vault values separately under env, you can define the constant and reference each one like this:

# in vault.yml
vault_wordpress_sites:
  example.com:
    env:
      db_password: example_dbpassword
      s3_access_key_id: "whatever"
      s3_secret_access_key: "whatever"
      # rest of salts etc
define( 'AS3CF_SETTINGS', serialize( array(
    'provider' => 'do',
    'access-key-id' => env('S3_ACCESS_KEY_ID'),
    'secret-access-key' => env('S3_SECRET_ACCESS_KEY'),
) ) );
2 Likes

That was the first approach I thought of, but, where do you put the definition code?

define( 'AS3CF_SETTINGS', serialize( array(
    'provider' => 'do',
    'access-key-id' => env('S3_ACCESS_KEY_ID'),
    'secret-access-key' => env('S3_SECRET_ACCESS_KEY'),
) ) );

I thought I should put it on site/config/application.php but I don’t know if I can use de Config::define method to declare the serialized array…

Sth like this site/config/application.php would work?

Config::define( 'AS3CF_SETTINGS', serialize( array(
    'provider' => 'do',
    'access-key-id' => env('S3_ACCESS_KEY_ID'),
    'secret-access-key' => env('S3_SECRET_ACCESS_KEY'),
) ) );

Thank you @swalkinshaw

2 Likes

Your last snippet should work. Keep in mind Config::define isn’t defining an array; it’s defining a serialized array which is just a string like the other normal constants :slight_smile:

2 Likes

This topic was automatically closed after 42 days. New replies are no longer allowed.