Ember Deploy CLI - not reading .env files

2019-08-16 06:01发布

问题:

Trying to deploy to an AWS S3 deployment target using the ember-cli-deploy plugin.

Have tested deploying using AWS key and secrets hardcoded in the /config/deploy.js file, which worked fine, so can confirm that it is something to do with my environment file setup.

The files are stored in the root of the directory (as per docs). Have tested .env and target-specific variables such as .env.deploy.develop. These files contain the AWS in the following format:

AWS_KEY​=ABC
AWS_SECRET​=ABC123

Running the deployment process (i.e. ember deploy develop --activate --verbose) with the environment file setup results in the errors detailed in my previous question on the matter.

Fairly sure that there is only need for the .env file, since the AWS keys and secrets are simply referenced in the deploy.js file in the following manner (w/o any target conditions):

let credsConfig = {
  accessKeyId: process.env.AWS_KEY,
  secretAccessKey: process.env.AWS_SECRET,
};

Any clues as to what's going on here would be much appreciated!


Edit 1:

As per request, here is the /config/deploy.js file determining the ENV object used by environment.js:

/* jshint node: true */
/* eslint-env node */
const fs = require('fs');

// All targets that are available for deployment
let deployTargetConfig = {
  'develop': {
    code: 'D',
    region: 'ap-southeast-2',
    bucket: 'develop-bucket-name',

    // For S3 Index Addon. (Note that you shouldn't really be overwritting
    // revisions, as a revision represents a build in time. Thats why we
    // only allow it for develop, to avoid having to commit).
    allowOverwrite: true,
  },
  'demo': {
    code: 'DE',
    region: 'ap-southeast-2',
    bucket: 'demo-bucket-name',
  },
  'test': {
    code: 'T',
    region: 'ap-southeast-2',
    bucket: 'test-bucket-name',
  },
  'production': {
    code: 'P',
    region: 'ap-southeast-2',
    bucket: 'production-bucket-name',
  },
};

module.exports = function(deployTarget) {
  let ENV = {

    pipeline: {
      alias: {
        s3: { as: ['s3-all', 's3-apple-app-site-association'] },
      },

      runOrder: {
        's3-all': { before: 's3-apple-app-site-association' },
        's3-apple-app-site-association': { after: 's3-all' },
      },
    },

    build: {
      environment: 'production',
    },
    'revision-data': {
      type: 'version-commit',
    },
    'git-tag': {
      deployTag(context) {
        let revisionKey  = this.readConfig('revisionKey');
        let deployTarget = context.config.deployTargetCode;

        return ['versions', deployTarget, revisionKey].join('/');
      },
    },
    deployTargetCode: deployTargetConfig[deployTarget].code,
    // include other plugin configuration that applies to all deploy targets here
  };

  let credsConfig = {
    accessKeyId: process.env.AWS_KEY,
    secretAccessKey: process.env.AWS_SECRET,
  };

  let deploymentTargetConfig = deployTargetConfig[deployTarget];
  let baseConfig = Object.assign({}, deploymentTargetConfig, credsConfig);

  ENV['s3-all'] = Object.assign({}, baseConfig);

  ENV['s3-apple-app-site-association'] = Object.assign({
    filePattern: '**/apple-app-site-association',
    defaultMimeType: 'application/json',
    cacheControl: 'no-cache, no-store, must-revalidate',
    expires: 0,
  }, baseConfig);

  ENV['s3-index'] = Object.assign({}, baseConfig);

  try {
    let deepLinkFileRead = fs.createReadStream(`${__dirname}/../deep-linking/${deployTarget}/apple-app-site-association`);

    if (deepLinkFileRead) {
      let deepLinkFileWrite = fs.createWriteStream(`${__dirname}/../public/apple-app-site-association`);
      deepLinkFileRead.pipe(deepLinkFileWrite);
    }
  } catch (e) {
    window.console.log('Error trying to copy the file: ', e);
  }

  return ENV;
};