I need to set it in the eb option settings file, not the console. I don't understand why the following code from .elasticbeanstalk/optionsettings.myappEnv doesn't work. I've poured over the aws doc and stack overflow to no avail.
[aws:elasticbeanstalk:application:environment]
PARAM1=
PARAM2=
PARAM3=
PARAM4=
PARAM5=
NODE_ENV=production
Ok, so I gave up on the option settings file and created an env.config file with the following in it:
option_settings:
- option_name: NODE_ENV
value: production
That worked fine. I'm using the aws eb command line tools. Complete contents of env.config under .ebextensions folder:
packages:
yum:
ImageMagick: []
option_settings:
- option_name: NODE_ENV
value: production
commands:
000_fixNpmHome:
command: sed -i 's/function error_exit/export HOME=\/root\n\nfunction error_exit/' /opt/elasticbeanstalk/hooks/appdeploy/pre/50npm.sh
010_fixNpmProduction:
command: sed -i "s/'install'/'install', '--production'/" /opt/elasticbeanstalk/containerfiles/ebnode.py
Related
In CircleCi config, I added my-domain to etc/hosts in-order to access local webserver by domain name.
For example => http://my-domain:3000/some-endpoint
But when I start Selenium-testing using the following config.yml, I can only call http://127.0.0.1:3000/some-endpoint and http://localhost:3000/some-endpoint from Selenium.
When I try to use http://my-domain:3000/some-endpoint from the Selenium, it gave me org.openqa.selenium.NoSuchElementException
steps:
- checkout
- run:
name: Add my-domain in etc/hosts
command: |
echo '127.0.0.1 my-domain' | sudo tee -a /etc/hosts
cat /etc/hosts
- run:
name: Start server for testing
command: |
cd ${DIR}
. venv/bin/activate
python3 server.py
background: true
- run:
name: Start Testing
command: ./gradlew test --stacktrace
I am using gitlab ci cd pipe line to deploy my application to ubuntu server. I have different .env file for local and for dev env and its not a part of git repo (included in gitignore) how to get env variables in my app when deployed to ubuntu server
my gitlab-ci.yml
stages:
- deploy
cache:
paths:
- node_modules/
deploy:
stage: deploy
script:
- npm install
- sudo pm2 delete lknodeapi || true
- sudo pm2 start server.js --name lknodeapi
I guess you are looking for this -Create Variables Gitlab.You can create your environment variables in the ui and then change your gitlab-ci.yml like below
stages:
- deploy
cache:
paths:
- node_modules/
deploy:
stage: deploy
script:
- echo "NGINX_REPO_KEY"=$NGINX_REPO_KEY >> ".env"
- npm install
- sudo pm2 delete lknodeapi || true
- sudo pm2 start server.js --name lknodeapi
This will create a .env file in root folder and put your variables in it.
I would like to deploy my MERN stack app in DigitalOcean Droplet via CircleCI as CI/CD tool. I read that it needs ssh into the Droplet and run commands for building and deploying the app, but I have tried a several ways to achieve it yet still ends up no luck.
Below is my config.yml for CircleCI
version: 2.1
orbs:
node: circleci/node#4.1.0
jobs:
express_deploy:
docker:
- image: "cimg/node:current"
steps:
- run: node --version
- add_ssh_keys:
fingerprints:
- "$ssh_key_prints"
- run: ssh -oStrictHostKeyChecking=no $username#$ip "cd $directory \ npm install \ node app.js"
workflows:
init:
jobs:
- express_deploy
error: bash: line 0: cd: too many arguments
Some of the others attempts I have tried:
steps:
- run: node --version
- add_ssh_keys:
fingerprints:
- "$ssh_key_prints"
- run: ssh -oStrictHostKeyChecking=no $username#$ip "cd $directory"
- run: npm install
- run: node app.js"
error: module $directory/app.js not found
I wanna know if this approach is wrong or is there a way to fix it?
notes: $ are credential variables that I blurred here, but I tested them independently and they worked fine
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
Here is an excerpt of my EB configuration file .ebextensions/app.config:
option_settings:
- option_name: AWS_SECRET_KEY
value: xxxxxxxxxx
- option_name: AWS_ACCESS_KEY_ID
value: xxxxxxxxxx
- option_name: APP_ENV
value: development
- namespace: aws:elasticbeanstalk:container:nodejs
option_name: ProxyServer
value: nginx
- namespace: aws:elasticbeanstalk:container:nodejs
option_name: GzipCompression
value: true
- namespace: aws:elasticbeanstalk:container:nodejs
option_name: NodeVersion
value: 0.8.10
- namespace: aws:elasticbeanstalk:container:nodejs
option_name: NodeCommand
value: npm start
commands:
test_command:
command: echo $APPLICATION_ENV > /home/ec2-user/test.txt
cwd: /home/ec2-user
ignoreErrors: true
then I do the normal thing:
$ git commit -am "wrote config file"
$ eb init
...
$ eb start
...
would you like to use the most recent commit [y/n]
$ y
Then after deploy is complete and in green state, looking inside the eb generated .elasticbeansalk/optionsettings.myapp-env file I found:
[aws:elasticbeanstalk:application:environment]
PARAM1=
PARAM2=
PARAM3=
PARAM4=
PARAM5=
[aws:elasticbeanstalk:container:nodejs]
GzipCompression=false
NodeCommand=
NodeVersion=0.8.24
ProxyServer=nginx
My environment variable was not set, the NodeCommand directive was not set, and the NodeVersion has been ignored. What gives, EB? How can it ignore certain directives and not others? Any ideas on what I'm doing wrong?
EDIT
according to this post, the JSON holding the environment variables is held here:
/opt/elasticbeanstalk/deploy/configuration/containerconfiguration
which means I can parse this fiel for the variables, but this is frustrating since it's supposed to be taken care of with the configuration file (otherwise why have one?). There still must be an issue with my configuration file, otherwise EB seems completely broken in this respect...
I've run into this problem as well. I believe there are 2 ways to solve it.
Run "eb update" this should update your environment and hopefully grab the variables.
Create a new env and deploy your code into that environment. Once everything is good then point dns at the new env and delete the old one.
Also I read somewhere (aws forum I believe) that if you update the env in the elastic beanstalk gui interface that those values will take precedence over anything you put in the source code.