How to place files outside app deployment directory in AWS Elastic Beanstalk? - amazon-elastic-beanstalk

In AWS EB, how to place my environment.properties (contains app runtime config like port, logs dir, DB info, security keys, etc.) under /var/env_config/myapp, so it can be referred by the app at runtime?
Though my further plan is to put this environment.properties in a secure non app directory of local or remote file system as it contains sensitive information.
global.env = propsReader(path.join(process.env.ENV_PATH, 'env-main.properties'));
On the EB, I have added an Environment property 'ENV_PATH = /var/env_config/myapp'
EB logs:
web: > myapp#1.0.0 start /var/app/current
web: > node src/app-main.js
web: 8266 [
web: '/opt/elasticbeanstalk/node-install/node-v12.18.1-linux-x64/bin/node',
web: '/var/app/current/src/app-main.js'
web: ]
web: /var/env_config/myapp
web: internal/fs/utils.js:230
web: throw err;
web: ^
web: Error: ENOENT: no such file or directory, open '/var/env_config/myapp/env-main.properties'
I just wanna deploy my application in the same fashion in AWS EB or Docker or VM or local machine, with just an environment property saying where the required runtime input files are.

How to access Elastic Beanstalk file system to configure my .properties file?
Not sure what do you mean by "accessing file system", but usually you would create .ebextensions folder in your project directory. The extensions are commonly used for running commands or scripts when you are deploying your app. There are special sections for that:
commands: You can use the commands key to execute commands on the EC2 instance. The commands run before the application and web server are set up and the application version file is extracted.
container_commands: You can use the container_commands key to execute commands that affect your application source code. Container commands run after the application and web server have been set up and the application version archive has been extracted, but before the application version is deployed.
Therefore, you could use the above sections to modify your .properties file during deployment of your application into EB.

Related

EB: Trigger container commands / deploy scripts on configuration change

I am running my web server on Elastic Beanstalk, and using Papertrail for logging. I am using the official .ebextensions script to get papertrail set up during deployment, but I have a problem. I use environment variables as part of my hostname used as the sender when remote_syslog uploads logs to papertrail, and while this works fine during deployment, when the 01_set_logger_hostname container command is triggered, I run into problems whenever I change environment variables by modifying the environment's configuration, since it seems an eb config call will only restart the application server, not run any of the scripts run during deployment, including the ebextensions container commands.
"/tmp/set-logger-hostname.sh":
mode: "00555"
owner: root
group: root
encoding: plain
content: |
#!/bin/bash
logger_config="/etc/log_files.yml"
appname=`{ "Ref" : "AWSEBEnvironmentName" }`
instid=`wget -q -O - http://169.254.169.254/latest/meta-data/instance-id`
myhostname=${SOME_VARIABLE}_${appname}_${instid}
if [ -f $logger_config ]; then
# Sub the hostname
sed "s/hostname:.*/hostname: $myhostname/" -i $logger_config
fi
As you can see, since my hostname depends on ${SOME_VARIABLE}, I need to refresh the hostname whenever ${SOME_VARIABLE} is modified following eb config.
Is there a way to trigger a script to be run whenever an eb config command is run, so that I can not only restart my web application but also reconfigure and restart remote_syslog with the updated hostname?
This is now possible on AWS Linux 2 based environments with Configuration deployment platform hooks.
For example, you can make a shell script .platform/confighooks/predeploy/predeploy.sh that will run on all configuration changes. Make sure that you make this file executable according to git, or Elastic Beanstalk will give you a permission denied error.

Gunicorn: No module named '/path/to/my/django/project'

I was using gunicorn with nginx on Ubuntu 16.04 system to deploy a django project and want to create a systemd service for gunicorn. In /lib/systemd/system/gunicorn-mywebsite.service, I write following codes:
ExecStart=/home/myusername/sites/pythonEnv/bin/gunicorn --bind unix:/tmp/mywebsite.socket /path/to/my/django/project.wsgi:application
But when I ran service gunicorn-mywebsite start, there was problem No module named '/path/to/my/django/project'.
If I run the same command my django project directory with relative path of my wsgi:application, it will work.
How can I fix this problem?
You can't give gunicorn a path to a file, it needs to be a module path, with application entry point name. So just project.wsgi:application. If the directory containing project is not in your path, then use the --pythonpath to gunicorn to tell it where it is.

How to deploy application in OpenShift 3?

Using this tutorial for using private Node.js repo from BitBucket in OpenShift, in last command getting an error, why?
Kukodas-MBP:~ kukodajanos$ ./oc new-app httpd~git#bitbucket.org:j4nos/nodejs.git --name mysite
error: Errors occurred while determining argument types:
httpd~git#bitbucket.org:j4nos/nodejs.git as a local directory pointing to a Git repository: stat httpd~git#bitbucket.org:j4nos/nodejs.git: no such file or directory
Errors occurred during resource creation:
error: the image match "httpd" for source repository "git#bitbucket.org:j4nos/nodejs.git" does not appear to be a source-to-image builder.
- to attempt to use this image as a source builder, pass "--strategy=source"
- to use it as a base image for a Docker build, pass "--strategy=docker"
Changed httpd to nodejs, I am using for repo name, and so it works:
Kukodas-MBP:~ kukodajanos$ ./oc new-app nodejs~git#bitbucket.org:j4nos/nodejs.git --name mysite
--> Found image cd02d02 (3 weeks old) in image stream "openshift/nodejs" under tag "6" for "nodejs"
Node.js 6
---------
Node.js 6 available as docker container is a base platform for building and running various Node.js 6 applications and frameworks. Node.js is a platform built on Chrome's JavaScript runtime for easily building fast, scalable network applications. Node.js uses an event-driven, non-blocking I/O model that makes it lightweight and efficient, perfect for data-intensive real-time applications that run across distributed devices.
Tags: builder, nodejs, nodejs6
* A source build using source code from ssh://git#bitbucket.org/j4nos/nodejs.git will be created
* The resulting image will be pushed to image stream "mysite:latest"
* Use 'start-build' to trigger a new build
* This image will be deployed in deployment config "mysite"
* Port 8080/tcp will be load balanced by service "mysite"
* Other containers can access this service through the hostname "mysite"
--> Creating resources ...
imagestream "mysite" created
buildconfig "mysite" created
deploymentconfig "mysite" created

How to setup/configure laravel project on cloud server

I have this laravel application on /var/www/html/application-folder/public_html
When I enter the apache server IP it doesn't load the laravel application instead it displays the Apache home page
How can I display the url /var/www/html/application-folder/public_html ?
When I type the full url I get the following error:
Forbidden
You don't have permission to access /folder/public_html/index.php on this server.
Apache/2.2.15 (CentOS) Server
If you have full root access to your server then you can
Step 1
upload your laravel project from the development machine(local) to the /var/www on your server - upload all folders except vendor and node_modules
Step2
once the project is uploaded, run composer install, if you need any of the node packages run npm install
Step 3
create virtual host for your site with DocumentRoot /var/www/yourProjectFolder/public
Step 4
Ensure storage folder has write permissions for your apache/webserver user - recursively
Step 5
Ensure that public folder has appropriate permissions - recursively, if you have uploaded the project as root then you will need to change the owner/permissions
Following this workflow you will be able to get your Laravel site up and running.
Important distinction to make here is that you have full root access to your server and that you can install composer and/or npm on your server before proceeding with the workflow.
If you can't install composer and/or npm on your server, then you have to upload the vendor directory to your server as well (and if you need any node packages then the node_modules as well) - following the documentation link in my comment above will help you.
Refer Virtual Host on Cent Os 6

Unable to upload widget to Wirecloud instances in private server

We have downloaded and installed a running instance of Wirecloud in our company server following the steps at:
https://conwet.fi.upm.es/wirecloud/install
We created the instance using the --quick-start command to try the instance, and ran wirecloud using the Django internal web server with the following command:
$ python manage.py runserver 0.0.0.0:8080 --insecure
We are able to enter the instance, and move around the enviroment, but we have encountered a problem when we try to upload a widget to our local workspace. After I search for the widget in my computer (previously downloaded from the Fi-lab marketplace), we get the next message:
Error adding packaged resource: Internal Server Error.
We also tried to download the zip file of the widget from github, unzip it and recompress it as a wgt file (compress as a zip but changing the extension to .wgt) and we get the same answer from our wirecloud instance; but if we try to upload the same package to the instance in fi-lab, it uploads successfully.
We don't know if it's because of the quick-start installation we made or if we have to modify something from our widget files in order to be able to upload it to our local instance.
Solved
The problem was in the config.xml file: the name of the attributes and the structure of the widgets unable to upload were different from the template of the config.xml file posted at the users guide.
After changing it to follow the structure of the template it works fine.
My widget example was the NGSI Updater. The thing is that it uploads perfectly in the instance at FiLab, even though the config.xml file had a different structure from the one of the template; but it encounters an error when uploading it to the Wirecloud local instance at my server.