Auto deploy after commiting - ruby-on-rails

I'm developing on Ruby on Rails and write some articles on Hexo.
My project source code repo is on Gitlab server.
So my deploy flow is
Commit the production code to Gitlab from my working space.
Login in the Web server, then pull the production code from Gitlab
Restart the Webserver, or regenerate articles for Hexo.
Is there any way to let me, renew the webserver with one step ?

hexo is on node so not sure how ruby on rails fits in. I would recommend you take a look at their documentation which has few plugins for deployments link
pasting an excerpt that's valid at this moment
Edit _config.yml.
deploy:
type: git
message: [message]
repo:
gitlab: <repository url>,[branch]
gitcafe: <repository url>,[branch]

It's better to setup a GitLab hook which should call a hexo generate command.

Related

Dokku DigitalOceans droplet: remote rejected error... how to solve it?

I recently heard about Dokku, and wanted to deploy a dockerized Rails application using the DigitalOceans droplet. I followed these guidelines, and everything seemed working fine... till I tried to push on Dokku :'( I get always the same "remote rejected error", but with not explicits informations that could help me to solve my problem... So if anyone could help, it would be really great!
Here are my steps:
Created the droplet, with the 5$ plan. On setup I left the fields as they were (hostname, ...).
Added a swap file (as recommended in the tutorial)
Created the dokku app, and linked it to the PG plugin I installed just before
Added the remote as git remote add dokku dokku#my-droplet-ip:myapp
Updated the DB url on my Rails configuration
Pushed my branch using git push dokku <branchname>: for branchname other than master, you have to configure Dokku... ;)
Dokku push logs: https://gist.github.com/soykje/1ddeb5f04fd85e8bd2d2b1f46e63da1e
Dokku app report: https://gist.github.com/soykje/f5192775742848f96437705c6608080f
Thx in advance
I had to include a file named Procfile in the root of the project with the contents of
release: bundle exec rails db:migrate
web: bundle exec rails s
https://dokku.com/docs/deployment/builders/dockerfiles/#procfiles-and-multiple-processes

How to deploy a rails app to heroku using C9

I am trying to deploy my rails app to heroku. However, it seems that there is a long process to do. I have to change my db but I do not know how! I also want to know how to push to heroku please!
Thanks in advance!
I think you might be interested in Michael Hartl's tutorial where there is section on deploying to Heroku.
Remember that you will need Git before deploying to Heroku. There is good info on that in same tutorial here.
I hope this helps.
Read this instruction https://devcenter.heroku.com/articles/getting-started-with-rails4
I usually create a Git repo on GitHub or BitBucket and push my Rails project there. Then I go to Heroku website, manually create a new project there (in a dashboard) - and right after that step Heroku provides a detailed list of the Git commands describing how to pull your code from, say, GitHub.
After that you need to run migrations on Heroku - you can do that on your local machine in the console window - but you need to install Heroku CLI (locally) first.
That's it basically. After that Heroku starts your app automatically.
It is not required for you to deploy your code on GitHub or BitBucket. After you init a Git repo locally, you can directly push to Heroku Git. But I prefer use BitBucket as a convenient storage additionally.

The page you were looking for doesn't exist

I'm trying to learn Rails ( developpment beginner here )
When I try to deploy my first app on Heroku and execute $ heroku open I got
"The page you were looking for doesn't exist.”
In my Heroku control pannel I also have a second link who works, http://secret-refuge-2130.herokuapp.com/, but different from localhost.
Here's my first app https://github.com/Freysh/first_app
As Michael Hartl propose "Unfortunately, the resulting page is an error; as of Rails 4.0, for technical reasons the default Rails page doesn’t work on Heroku. The good news is that the error will go away (in the context of the full sample application) when we add a root route in Section 5.3.2."
You need to work on the Root route of your routes.rb in config folder.
Looks like you haven't pushed your repo to Heroku yet?
Since you're new, let me give you some ideas about how Heroku works, and how you can deploy your app to it...
Heroku
When you use Heroku, you basically get a bare git repo which you can push your application to. This repo will essentially allow you to use the following commands:
> $ git add .
> $ git commit -a -m "Your App"
> $ git push heroku master
This is, of course, only possible if you have added your heroku repo to your local remote repositories:
> $ git remote add heroku https://heroku.com/......
When you push your local repo to your Heroku one, Heroku then runs what's known as a buildpack:
When you git push heroku, Heroku’s slug compiler prepares your code
for execution by the Heroku dyno manager. At the heart of the slug
compiler is a collection of scripts called a buildpack.
Heroku’s Cedar
stack has no native language or framework support; Ruby, Python, Java,
Clojure, Node.js and Scala are all implemented as buildpacks.
This means that when you push your app to your repo, Heroku will endeavour to compile & run it for you. This is when the app will run.
Fix
To fix, you should follow the tutorial here
Basically, you need to get your git repo created locally, which will then provide you with the ability to push to your remote heroku repo

What is the best workflow for updating / deploying a Rails app through Git?

I just deployed my first Ruby on Rails app on a VPS at Digital Ocean.
To get started quickly, I did this by simply dragging my Rails directory tree (and its containing files) onto the server via (S)FTP.
I know this isn't the best solution in the long run. So how can I link my app on the server to my git repository at GitHub?
Ideally, when I work on my app locally, and then git commit and git push to my git repository, my app on the VPS will also get updated automatically.
How can this be achieved or what is the best strategy to achieve this?
Since I am building this app just by myself, I can probably keep things simple and stick to a single master branch, rather than having multiple branches.
Thanks for any help.
If I were you, I'd do the pulling and updating on the remote manually. Sorry, but this is not only best practice, but will also force you to learn something useful about system administration and don't require you to be dependent on one host, but can switch service provider and setup as easy it is to make a git-clone somewhere else.
So my workflow would be:
Client:
# Do some changes, commit and add a nice message
$ git commit myfiles
# Push to remote once I'm happy.
$ git push
# SSH to server, and continue from there.
$ ssh username#server
Server:
# Enter project directory
$ cd /var/www/myproject
# Pull code
$ git pull
Done. Or perhaps finish by refreshing server container (uWSGI, fcgi, gunicorn, what have you...)
Reading other similar answers, they hint to looking at the following resource using Capistrano:
Capistrano documentation at GitHub
You should spend a little time now setting up deploys with some automation. Since you are using rails, you should try Capistrano Gem
Capistrano will help you deploy and maintain your application with just a few simple commands. The Readme will show you how to get started, but in general, you will add the Gem by adding this to your Gemfile:
gem 'capistrano', '~> 3.2.0'
then run bundle install to install Capistrano into your bundle. If you are not already using bundler, you should start.
then run bundle exec cap install to setup your local repo for Capistrano.
Basically now you have a nice structure for deployment scripts as part of your repo. You will have to write some deploy scripts now, or modify the examples.
Once done, Capistrano will help you deploy new code (once committed and pushed to your remote repo) and restart the services.
It depends on whatever service you are using to publish your app. Depending on the provider, they may or may not provide rails service. For example, a site like Heroku, where you can actually host for free up until certain restrictions is accessible via github and you can do exactly what you're saying and just push up and publish.
If you can put your repo on your server, you can set up post-receive hooks to pull your branch into your web app directory.
To do so you would create a bare repo on your server, add it as a remote on your development machine, and then (on your server) create the file /my/app.git/hooks/post-receive and add these lines:
#!/bin/bash
#CONFIG
LIVE="/home/saintsjd/www"
read oldrev newrev refname
if [ $refname = "refs/heads/master" ]; then
echo "===== DEPLOYING TO LIVE SITE ====="
unset GIT_DIR
cd $LIVE
git pull origin master
echo "===== DONE ====="
fi
Code from Automated Deployment of PHP Applications using git, by Jon Saints.
Note that it would be possible to do something like this without putting the repo on your server if you use Github's webhooks (https://developer.github.com/v3/repos/hooks/).
However, I would highly recommend using Capistrano (https://github.com/capistrano/capistrano), which can deploy your application code and help you with a lot of administrative tasks (like restarting the server, etc.).
If you want to stick relatively close to git, you might also check out the git-deploy gem.

From manual pull on server to Capistrano

I've always deployed my apps through SSH by manually logging in and running git pull origin master, running migrations and pre-compiling assets.
Now i started to get more interested in Capistrano so i gave it a try, i setup a recipe with the repository pointing to github and deploy_to to /home/myusername/apps/greatapp
The current app on the server is already hooked up with Git too so i didn't know why i had to specify the github url in the recipe again, but i ran cap deploy which was successful.
The changes didn't apply, so out of curiosity i browsed to the app folder on the server and found out that Capistrano created folders: shared, releases and current. the latter contained the app, so now i have 2 copies one in /home/myusername/apps/greatapp and another in /home/myusername/apps/greatapp/current.
Is this how it should be? and I have to migrate user uploads to current and destroy the old app?
Does Capistrano pull the repo on my localhost then upload it through SSH or run pull on the server? in other words can someone outline how the deployment works?
Does Capistrano run precompile:assets?
/releases/ is for previous versions incase you want to do cap:rollback.
/current/ as you rightly pointed out is for the current version of your app.
/shared/ is for files and folders that you want to persist between deployments, they typically get symlinked to your /current/ folder as part of your recipe.
Capistrano connects to your server in a shell and then executes the git commands on the server.
Capistrano should automatically put anything in public/system (the rails convention for stored user-uploaded files) into the shared directory, and set up the necessary symlinks.
If you put in the github url, it actually fetches from your github repo. Read https://help.github.com/articles/deploying-with-capistrano for more info.
It does, by default.

Resources