使用 AWS CodePipeline 在 AWS ElasticBeanstalk 上部署 AdonisJS 应用程序失败 - 缺少 .env

AdonisJS app deployment on AWS ElasticBeanstalk using AWS CodePipeline fails - missing .env

我最近开始使用 AdonisJS 进行 API 开发。 我将 AWS Elastic BeanstalkAWS CodeCommitAWS CodePipeline 一起使用,以在每个上部署新代码git push。 由于 .env 文件不存在于 git 存储库中,我通过 Elastic Beanstalk 网络控制台添加了环境变量。 但是当我尝试 运行 node ace migration:run 命令时部署失败。

Activity execution failed, because: 
  Error: ENOENT: no such file or directory, open '/tmp/deployment/application/.env'


  1 Env.load
  /tmp/deployment/application/node_modules/@adonisjs/framework/src/Env/index.js:110

  2 new Env
  /tmp/deployment/application/node_modules/@adonisjs/framework/src/Env/index.js:42

  3 Object.app.singleton [as closure]
  /tmp/deployment/application/node_modules/@adonisjs/framework/providers/AppProvider.js:29

  4 Ioc._resolveBinding
  /tmp/deployment/application/node_modules/@adonisjs/fold/src/Ioc/index.js:231

  5 Ioc.use
  /tmp/deployment/application/node_modules/@adonisjs/fold/src/Ioc/index.js:731

  6 AppProvider.boot
  /tmp/deployment/application/node_modules/@adonisjs/framework/providers/AppProvider.js:337

  7 _.filter.map
  /tmp/deployment/application/node_modules/@adonisjs/fold/src/Registrar/index.js:147

  8 arrayMap
  /tmp/deployment/application/node_modules/lodash/lodash.js:639

   (ElasticBeanstalk::ExternalInvocationError)

然后我尝试在每个命令前添加 ENV_SILENT=true 标志,如 AdonisJS 文档中所述。但这并没有帮助。

那么,我尝试将 .env 文件上传到 S3 存储桶,并在部署期间复制其内容。 但它似乎不起作用,因为我遇到了同样的错误(没有 .env 文件)。

这些是 .ebextensions 文件夹中的 2 个配置文件

01_copy_env.config(为了安全起见,我在这里使用 x-xxxxxxxxxxxx)

Resources:
  AWSEBAutoScalingGroup:
    Metadata:
      AWS::CloudFormation::Authentication:
        S3Auth:
          type: "s3"
          buckets: ["elasticbeanstalk-us-east-x-xxxxxxxxxxxx"]
          roleName:
            "Fn::GetOptionSetting":
              Namespace: "aws:autoscaling:launchconfiguration"
              OptionName: "IamInstanceProfile"
              DefaultValue: "aws-elasticbeanstalk-ec2-role"
files:
  "/tmp/deployment/application/.env":
    mode: "000755"
    owner: root
    group: root
    authentication: "S3Auth"
    source: https://elasticbeanstalk-us-east-x-xxxxxxxxxxxx.s3.us-east-2.amazonaws.com/variables.txt

02_init.config

container_commands:
    01_node_binary:
        command: "ln -sf `ls -td /opt/elasticbeanstalk/node-install/node-v10* | head -1`/bin/node /bin/node"
        leader_only: true
    02_migration:
        command: "node ace migration:run"
    03_init_seed:
        command: "node ace seed"

整个过程唯一有效的时间是我将 .env 文件添加到 git 并将其与其余代码一起部署。但这不是要走的路,所以如果有人知道我的问题的解决方案,我将不胜感激。谢谢!

在您的全局变量 (Elastic Beanstalk) 上添加新变量 ENV_SILENT = true

Adonis documentation