环境特定的 ebextensions Beanstalk 命令 [英] Environment specific ebextensions Beanstalk commands

本文介绍了环境特定的 ebextensions Beanstalk 命令的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 spring-boot 应用程序,我需要为其指定石墨服务器和端口(以发送指标).为此,我必须安装和配置 statsd.我使用 ebextensions 文件来做到这一点.

I have a spring-boot application for which I need to specify graphite server and port (to send metrics). For that to work, I have to install and configure statsd. I do that using the ebextensions file.

commands:
  01_nodejs_install:
    command: sudo yum -y install nodejs npm --enablerepo=epel
    ignoreErrors: true

  02_mkdir_statsd:
    command: mkdir /home/ec2-user/statsd
    ignoreErrors: true

  03_fetch_statsd:
    command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
    ignoreErrors: true

  04_change_example_config:
    command: "cat exampleConfig.js | sed 's/2003/<graphite-port>/g' | sed 's/graphite.example.com/<my-graphite-server>/g' > config.js"
    cwd: /home/ec2-user/statsd

  05_run_statsd:
    command: setsid node stats.js config.js >/dev/null 2>&1 < /dev/null &
    cwd: /home/ec2-user/statsd

这种配置的问题是我只能在此处为所有环境指定 1 个石墨服务器.

The problem with this configuration is that I can specify only 1 graphite server here for all environments.

所以我决定将命令 04 和 05 移到 container_commands 中.我正在考虑使用 beanstalk 控制台/UI 定义一个名为 ENV_NAME 的环境变量,并将其设置为 devqaprod 取决于环境.然后我可以使用 container_commandstest 选项仅针对基于此 ENV_NAME 的特定环境运行 04 和 05 命令.

So I decided to move commands 04 and 05 into container_commands. I am thinking of defining an environment variable called ENV_NAME using the beanstalk console/UI, and set it to dev, qa, or prod according to the environment. Then I can use test option of container_commands to run 04 and 05 commands only for specific environment based on this ENV_NAME.

所以我的问题是 - 我如何使用 AWS 控制台来定义环境变量?我尝试使用 Beanstalk 控制台来定义我的变量,如文档 here 但它不起作用.我也找到了(请参阅 5 个赞成的答案)此方法仅设置 JVM 属性而不设置 ENV 变量.

So my problem is - how can I use AWS console to define environment variable? I tried using Beanstalk console to define my variable as explained in the documentation here but it did not work. I also found (see the answer with 5 upvotes) that this method sets only JVM properties and not ENV variables.

我无法使用 ebextensions 定义环境变量,因为那样我会遇到同样的问题 - 无法为不同的环境定义不同的环境变量 :)

I cannot define environment variable using ebextensions because then I'll have the same problem - can't define different env vars for different envs :)

所以我需要帮助:

  • 使用 beanstalk UI 设置 ENV_NAME 环境变量.
  • Set the ENV_NAME environment variable using beanstalk UI.

或者

  • 建议一种方法,使用 container_commands 中的 ENV_NAME 系统属性来根据 ENV_NAME 的值判断是否运行命令.
  • Suggest a way to use ENV_NAME system property in container_commands to condition whether or not to run the command based on the value of ENV_NAME.

如果您知道为不同环境指定不同 Graphite 服务器的更简单/更好的方法,请随时参与.

And in case you know a simpler/better way to specify different Graphite servers for different environments, please feel free to pitch in.

推荐答案

我解决这个问题的方法是将 ENV_NAME 定义为 devprod 分别在 dev 和 prod 环境中,并使用以下 ebextensions 配置.

The way I resolved this was to define ENV_NAME as dev and prod in dev and prod environments respectively and use the following ebextensions configuration.

commands:
  01_nodejs_install:
    command: sudo yum -y install nodejs npm --enablerepo=epel
    ignoreErrors: true

  02_mkdir_statsd:
    command: mkdir /home/ec2-user/statsd
    ignoreErrors: true

  03_fetch_statsd:
    command: git clone https://github.com/etsy/statsd.git /home/ec2-user/statsd
    ignoreErrors: true

container_commands:
  04a_container_change_example_config:
    command: "cat exampleConfig.js | sed 's/2003/<graphite-dev-port>/g' | sed 's/graphite.example.com/<graphite-dev-host>/g' > config.js"
    cwd: /home/ec2-user/statsd
    test: '[ "${ENV_NAME}" == "dev" ]'

  04b_container_change_example_config:
    command: "cat exampleConfig.js | sed 's/2003/<graphite-prod-port>/g' | sed 's/graphite.example.com/<graphite-prod-host>/g' > config.js"
    cwd: /home/ec2-user/statsd
    test: '[ "${ENV_NAME}" == "prod" ]'

  05_run_statsd:
    command: setsid node stats.js config.js >/dev/null 2>&1 < /dev/null &
    cwd: /home/ec2-user/statsd

使用 test 我可以在 ENV_NAME 属性上设置 container command 的执行条件,该属性已在 beanstalk 环境中定义.

Using test I can condition the execution of the container command on the ENV_NAME property which I have already defined in the beanstalk environment.

这篇关于环境特定的 ebextensions Beanstalk 命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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