简体   繁体   中英

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

I've recently started using AdonisJS for API development. I'm using AWS Elastic Beanstalk together with AWS CodeCommit and AWS CodePipeline to deploy new code on each git push . Since .env file is not present in git repository, I've added env variables through Elastic Beanstalk web console. But deployment failed when I tried to run node ace migration:run command.

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. But that did not help.

So then, I've tried to upload .env file on S3 bucket, and copy its contents during deployment. But it seems it does not work, since I'm getting the same error (no .env file).

These are my 2 config files from .ebextensions folder

01_copy_env.config (I'm using x-xxxxxxxxxxxx here for security)

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"

The only time the whole thing works is when I add .env file to git and deploy it with the rest of the code. 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)

Adonis documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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