简体   繁体   English

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

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

I've recently started using AdonisJS for API development.我最近开始使用AdonisJS进行 API 开发。 I'm using AWS Elastic Beanstalk together with AWS CodeCommit and AWS CodePipeline to deploy new code on each git push .我将AWS Elastic BeanstalkAWS CodeCommitAWS CodePipeline一起使用,在每个git push上部署新代码。 Since .env file is not present in git repository, I've added env variables through Elastic Beanstalk web console.由于 .env 文件不存在于 git 存储库中,我已通过Elastic Beanstalk Web 控制台添加了 env 变量。 But deployment failed when I tried to run node ace migration:run command.但是当我尝试运行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)

Then I've tried to add ENV_SILENT=true flag before each command as stated in AdonisJS documentation.然后我尝试在每个命令之前添加ENV_SILENT=true标志,如 AdonisJS 文档中所述。 But that did not help.但这并没有帮助。

So then, I've tried to upload .env file on S3 bucket, and copy its contents during deployment.那么,我尝试在 S3 存储桶上上传 .env 文件,并在部署期间复制其内容。 But it seems it does not work, since I'm getting the same error (no .env file).但它似乎不起作用,因为我遇到了同样的错误(没有 .env 文件)。

These are my 2 config files from .ebextensions folder这些是我来自 .ebextensions 文件夹的 2 个配置文件

01_copy_env.config (I'm using x-xxxxxxxxxxxx here for security) 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 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"

The only time the whole thing works is when I add .env file to git and deploy it with the rest of the code.只有当我将 .env 文件添加到 git 并将其与其余代码一起部署时,整个事情才起作用。 But that is not the way to go, so if anyone knows a solution to my problem I would really appreciate it.但这不是要走的路,所以如果有人知道我的问题的解决方案,我将不胜感激。 Thanks!谢谢!

Add new variable ENV_SILENT = true on your global variables (Elastic Beanstalk)在全局变量上添加新变量ENV_SILENT = true (Elastic Beanstalk)

Adonis documentation 阿多尼斯文档

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM