在ElasticBeanstalk上运行Grunt [英] Run Grunt on ElasticBeanstalk

查看:72
本文介绍了在ElasticBeanstalk上运行Grunt的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个节点应用程序,需要先用grunt进行构建,然后才能成功执行该应用程序。 (运行concat / minification / revving源代码等)。我已经在具有SSH访问权限的EC2实例上运行了该程序,因为我可以通过SSH进入目录并在部署过程中运行Grunt。但是,要使其自动化,我现在将应用程序移至ElasticBeanstalk,并且很难使应用程序成功运行。迁移到EB的原因是将SSH密钥保持在实时服务器之外,因此这些EB实例的设置没有ssh访问权限。

I have a node application that requires grunt to do a "build" before the application can be executed successfully. (runs concat/minification/revving of source code etc). I've got this running on an EC2 instance with SSH access as I can just SSH into the directory and run Grunt as part of the deployment process. However to automate this I'm now moving the application to ElasticBeanstalk and I'm having difficulty getting the application to run grunt successfully. The reason for the move to EB is to keep SSH keys OFF live servers so these EB instances are setup with no ssh access.

似乎没有官方文档,有人可以指出我的正确方向以实现上述目标吗?我需要在应用程序启动之前先执行一下,以便应用程序具有可用的文件(否则将有404)。

There seems to be no official documentation available, could anybody point me in a good direction to be able to achieve the above? I need grunt to execute before the application is started so that the application has the files available (otherwise there'll be a 404).

推荐答案

运行咕unt声与运行gulp非常相似,因此,我将在下面包含我的配置。

Running grunt would be very similar to running gulp, so, i'll include my config below.

这位于 .ebextensions 文件夹,位于我项目的根目录,名为 01run.config 。您可以有多个配置文件,它们将按字母顺序运行(因此开头是 01 。)

This is inside a .ebextensions folder at the root of my project, named 01run.config. You can have multiple config files, they will run in alphabetical order (hence the 01 at the beginning.)

这基本上只是指示过程再次按顺序运行这些命令,它是按字母顺序完成的,所以我相应地命名了它们。

This basically just instructs the process to run these commands in order, again, it's done in alphabetical order, so I named them accordingly.

commands:
  01get_sudo:
    command: echo Defaults:root \!requiretty >> /etc/sudoers
  02npm_install:
    command: sudo yum -y --enablerepo=epel install nodejs npm
  03npm_install_bower:
    command: sudo npm install -g bower
  04npm_install_gulp:
    command: sudo npm install -g gulp
  05yum_install_git:
    command: sudo yum -y --enablerepo=epel install git
container_commands:
  01bower_install:
    command: sudo bower install --allow-root
  02gulp_sass:
    command: sudo gulp sass




  1. 获取sudo访问权限

  2. 使用yum安装node.js和npm

  3. install bower(我的gulp进程需要Bower)

  4. 安装gulp

  5. 安装git(需要bower)

  6. 然后运行两个容器命令,它们在npm安装之后和npm启动之前发生:

  1. Get sudo access
  2. install node.js and npm with yum
  3. install bower (my gulp process needed bower)
  4. install gulp
  5. install git (needed by bower)
  6. i then run two container commands, which happen after npm install and before npm start:

  1. bower install

  2. gulp sass


在您的情况下,您只需删除bower和git安装,安装gr unt-cli,然后运行grunt。

In your case, you'd simply remove bower and git installs, install grunt-cli, and then run grunt.

这样做以来,我已经不再需要上述过程了在将生成的文件部署并提交到git存储库之前,请先进行所有操作。至少这是一次良好的学习经历,使我对beantalk部署的ec2实例有了更多的控制。

Since doing this, I've removed the need for the above process by doing it all up front before deploying and committing the built files to the git repository. It was at least a good learning experience that gives me much more control over my ec2 instances deployed by beanstalk.

这篇关于在ElasticBeanstalk上运行Grunt的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆