环境特定的ebextensions命令 [英] Environment specific ebextensions commands
问题描述
statsd
。我使用 ebextensions
文件。 命令:
01_nodejs_install:
命令:sudo yum -y install nodejs npm --enablerepo = epel
ignoreErrors:true
02_mkdir_statsd:
命令:mkdir / home / ec2- user / statsd
ignoreErrors:true
03_fetch_statsd:
命令:git clone https://github.com/etsy/statsd.git / home / ec2-user / statsd
ignoreErrors:true
04_change_example_config:
命令:cat exampleConfig.js | sed'/ 2003 /< graphite-port> / g'| sed / s / graphite。 example.com/<my-graphite-server>/g'> config.js
cwd:/ home / ec2-user / statsd
05_run_statsd:
命令:setsid node stats.js config.js> / dev / null 2>& 1< / dev / null&
cwd:/ home / ec2-user / statsd
此配置的问题是我可以在这里为所有环境指定一个石墨服务器。
所以我决定将命令04和05移动到 container_commands
。我正在考虑使用beanstalk控制台/ UI 定义一个名为 ENV_NAME
的环境变量,并将其设置为 dev 根据环境,code>,
qa
或 prod
然后我可以使用 test
选项 container_commands
来运行04和05命令仅针对特定的环境,基于这个 ENV_NAME
。
所以我的问题是 - 如何使用AWS控制台定义环境变量?我尝试使用Benastalk控制台来定义我的变量,如文档 here 但它没有工作。我也发现
我无法使用 ebextensions定义环境变量
因为那时我会有同样的问题 - 不能为不同的envs定义不同的env var:)
所以我需要帮助:
- 使用beanstalk UI设置
ENV_NAME
环境变量。
或
- 建议使用
ENV_NAME c>系统属性
container_commands
中的系统属性,以判断是否根据ENV_NAME $的值运行命令c $ c>。
如果您知道为不同环境指定不同的Graphite服务器的更简单/更好的方法,请随时在/ >
我解决方法是将 ENV_NAME
定义为 ebextensions
配置的dev/> code>和 prod
命令:
01_nodejs_install:
命令:sudo yum -y install nodejs npm --enablerepo = epel
ignoreErrors:true
02_mkdir_statsd:
命令:mkdir / home / ec2-user / statsd
ignoreErrors:true
03_fetch_statsd:
命令:git clone https://github.com/etsy/statsd.git / home / ec2-user / statsd
ignoreErrors:true
container_commands:
04a_container_change_example_config :
命令: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:
命令: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:
命令:setsid node stats.js config.js> / dev / null 2>& 1< / dev / null&
cwd:/ home / ec2-user / statsd
使用 test
我可以调整 container命令
在我已经在beanstalk环境中定义的 ENV_NAME
属性。
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
The problem with this configuration is that I can specify only 1 graphite server here for all environments.
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
.
So my problem is - how can I use AWS console to define environment variable? I tried using Benastalk 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.
I cannot define environment variable using ebextensions
because then I'll have the same problem - can't define different env vars for different envs :)
So I need help with either:
- Set the
ENV_NAME
environment variable using beanstalk UI.
Or
- Suggest a way to use
ENV_NAME
system property incontainer_commands
to condition whether or not to run the command based on the value ofENV_NAME
.
And in case you know a simpler/better way to specify different Graphite servers for different environments, please feel free to pitch in.
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
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命令的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!