Generating App on Remote Server - ruby-on-rails

A friend of mine runs hosting services and iam looking to get my rails 3 App hosted on his service.
My App is very small.
The Question is, is it a good idea to build the App right on the server which i want to host?
There's command line and everything else needed to work remotely.
Any opinions?

In my experience it's much more practical to build the app locally, and then to deploy it to the server using git. This way you can keep working on it even when you are not connected to the remote server.

Related

Example of web development local and production environment sample setup and workflow

I am working on moving our existing websites from a shared hosting to a VPS and then they will be redeveloped and improved using Laravel. My background is not software development, I have however a decent understanding of web development (enough to make a blog, CMS etc) BUT I have never worked in a web dev team so I don't know how things should be done "properly".
Locally I have always used XAMPP and remotely it has always been as basic as publishing files via Filezilla.
Now I have been required to do:
Version control - the changes to the website should be reviewed by a second (non technical person) before going live
Develop a system based on Laravel
What I am struggling to understand is how Ubuntu Server, GIT, Docker, Kubernetes, NGINX etc. all work together. Basically I don't know what "the big picture" looks like, how a decent workflow should look like.
So far I have manually installed all the necessary software to run Laravel on the VPS (the LAMP stack) but soon after I started to run into problems (libraries that are activated locally are not activated remotely). It has also become clear that software updates and differences between my local environment and remote (production environment) will make the issues worst over time.
Can someone explain in VERY general terms, how things should fit together so that my setup is both resilient, robust and scalable? For example:
Install docker on the server and on your computer
Download such and such image
connect GIT in such and such way
Enable unattended-upgrades
The more I read the more I get confused.
What I would like is a simple guide/idea on how things should be done properly.

How to host a web app locally on my computer

I have created a web app and I want to have it hosted locally on my computer so I can go to the browser and type https://localhost:<port number> and it will load up. However I am not sure how to do this or if it is even possible. My issue is I am not entirely sure what I need to google to get the answers and advice.
A little about what I have created and want to achieve:
This web app is written in Angular with a Spring Boot back end that it calls with all the functionality (it is a little overkill but the aim was to learn Java and Spring Boot, I could have technically done it all in the front end)
The data for this web app is stored in a MongoDB that is on my laptop
I currently run npm run dev when I have been developing it which is concurrently \"java -jar jars/java-fuel-consumption-api.jar\" \"npm start\" \"ng serve --proxy-config proxy.conf.json --open\"
I am not interested in having it hosted for others to use, it is just a simple personal project that I have written to help me learn JS and Spring Boot more
I have a MacBook Air so I am not sure if there is anything already installed from Apple that can help
I have got some experience of Docker and wouldn't say no to trying to learn a bit more
I want it to be running in the background so I can just access it any time without doing an npm run ... command but have the ability to stop it when required (for updates and fixes)
Not bothered about the URL - I assume that as it is being hosted on my computer it will just be localhost
I want to avoid AWS/Azure with the reason is that I don't want to pay! It works by doing npm run dev but I just want to have it in a more professional manner
Sorry for the vauge question but I am in need of some advice of where to start - I know the end goal but like with most things like this I have little experience in how it needs to be acheived! Help to be pointed in the right direction is most appreciated.
You can use XAMPP, it's a, simple to install, Apache Server with DB: https://www.apachefriends.org/download.html
This will allow you to host anything locally.
Another option would be AWS, they offer some test/trial servers as well.

Rails: How to "publish" a website

So, I am almost done with my website. I created it using ruby on rails on the Cloud9 IDE. Is there a way to publish it? To go on it, a user has to be signed on Cloud9 and then I need to run the code on the terminal...
rails server -b $IP -p $PORT
How would I be able to publish my website? I am very new to rails and I have no idea.
To publish your website you need to host it somewhere.
There are multiple ways to do this. For instance you can use Heroku. They provide PaaS (Platform as a service), which means they will handle the installation of the app for you and the maintenance of the virtual machine it resides (updates and whatnot).
Heroku also gives you a very nice admin view for the status of your app, online log display and some other goodies.
Another alternative would be Amazon Web Services, DigitalOcean or Linode (among many others!). They provide IaaS(Infrastructure as a Service). They only give you a virtual machine with your choice of operating system, you will have to manually publish your app and provide manual maintenance of the VM and pretty much anything including the database itself.
Using Heroku would be your best choice for the moment as they are very straightforward with the publishing part. Once you get the grip you can go to the other platforms for customization.
You will also need some deployment tools such as capistrano or mina.
If you're going to host your app in heroku, it's much easier to deploy. As simple as pushing your codes with git.

deploying a rails project to a remote server

is it possible to deploy a rails project to a remote server using FileZilla ? the server is running nginx/1.4.6 (ubuntu)
if no what is the best way to deploy the project if there is already a running version !
To answer your question yes, the code needs to be up, so FTP should do the trick. You might need to restart nginx to pick up the changes, usually touching a restart.txt is enough, but that's particular to your setup.
Is this the best way? Possibly not!
Others suggested capistrano and that would be a good fit for a server you maintain, or go Heroku (or similar) service for a simpler setup.
Deploying a Rails app is a tough job. There is always the easy way (heroku) however shared servers don't deal well with rails. Theoretically you can but usually this shared servers have really outdated ruby and rails versions and are absolutely useless. And you can try to connect via ssh and try to update it but i doubt you will be able to do that. So... If you are a rails developer i can suggest.
1- For small apps run Heroku (easy and free) however cost grows like hell with the app's growth
2- If you're thinking about developing big apps get a dedicated server (you can get cheap ones for 5€/month) and configure it as u would for your computer except when you run rails you run it in production.
3- Trust me... i fought enough Rails and shared servers and i quit... I just gave up

How to monitor and maintain my grails application in live/production environment?

It is the first time I have ever launched live a website (with Grails web framework under Amazon EC2 platform and Cloud Foundry) and I realized quickly that I am not ready for monitoring and maintening correctly my application in production mode (fortunately the website is accessible to a very limited number of users) .
The issues I have faced so far are:
Cannot change my views. I need to redeploy my application
I have no monitoring. I don't know who is connected, when do they sign in / sign out...
Redploying my application (upload WAR + deploy) takes at least 30 minutes.
I don't know how to restart my Tomcat server without a redeploy through Cloud Foundry !
...
So, my question is very simple:
What tools (including grails plugins) and methods can you recommend me for taking me out from my current blindness?
I am not sure how much this will help, however I use the JavaMelody Grails Plugin(http://www.grails.org/plugin/grails-melody) I use it to see if the site is being used before I pull down the service.
Hope that helps.
I tried Cloud Foundry in it's early days and found it a little rough. Sounds like that's still the case with 30+ minute deploys and the inability to restart your tomcat server. Half of your problems could be solved if you just created your own EC2 instance, installed tomcat and managed your own deployments. That'll let you bounce tomcat through shell access:
sudo /etc/init.d/tomcat6 restart
and redeploy your app
sudo /etc/init.d/tomcat6/stop
cp my.war /to/tomcat/dir
sudo /etc/init.d/tomcat6 start
or else you could do it through the tomcat admin console, but I find it to be flaky.
Regarding monitoring, there are a couple of ways you can do that. The easiest is to add CloudWatch monitoring to your system. That'll give you more insight into the performance of the application.
For more detailed monitoring regarding who's connecting to your app, I'd suggest looking at Google Analytics or Mint. If you need to get beyond that (with per user monitoring), you'll likely have to roll your own logging/tracking for what meets your needs. There are also other paid packages out there along the lines of Google Analytics and Mint that you can integrate with, but what fits your needs best, I can't say.
For actual monitoring of deployed system you can also use Hiperic HQ. It's a monitoring solution from Spring Source, who also are owners of Grails Framework.
It can manage, at your case:
tomcat server
database
linux
network
etc
btw redeploying app with changes is ok. it's a very bad practice to modify running app, on the production server.
I don't know if JMX and JConsole can help, but that might be a good way to see what the status of JMX-enabled POJOs is. Spring makes this easy to do.
Yes, you need to re-deploy your app when you change stuff in it, there's no way around that.
Deploy/re-deploy time has been cut significantly recently if using the grails plugin (btw, what version of the plugin do you use?) In some cases the upload time is as short as 15 seconds. Add 2-3 minutes for Amazon to spin up the instances and the deploy time is still pretty manageable. For re-deploy the instances don't have to be started, so it's even less than that.
To restart Tomcat login into your CloudFoundry account, click on the Deployment details, click on the instance that's running your Tomcat, and there will be a button "Restart service" that will do just that - restart Tomcat service.
You don't have to start your own EC2 instances in order to get a shell access. Copy the public DNS name of the instance from DeploymentDetails, and SSH into it using the private key you entered when registering for Cloudfoundry. Example:
ssh -i /path/to/gsg-keypair.pem root#your_instance_DNS_name

Resources