How is a test site created with Rails 4?
I'm building a Rails 4 app. I develop locally, have a github repo, and have a live production Heroku site.
Now I want a 'test' or 'dev' site that is on the web, so all the employees working with the app can see features even before they are rolled out.
It sounds like a standard enough issue that I suspect Rails has some built in approach, making use of the "dev", "test, and "production" environment variables.
Heroku has a methodology for this --
https://devcenter.heroku.com/articles/multiple-environments
I prefer to use standard git mechanics to control the flow. On a web application we develop this really helps us. We have a reasonable sized team and what we do is:
Create a feature branch (tools like git-flow can help with keeping standards in your team)
When done we push up to our git remote, create a pull request and someone reviews the contribution. Once the changes are good they get merged into master.
As part of continuous integration (after our specs are run successfully) we have a simple Jenkins job that clean rebases into the appropriate branch and pushes to the remote.
Everyone has their own flow, but you can use your master branch as development then when you're ready merge/rebase into your other environment branches.
On your destination Rails platform (in my case Ninefold, because it's really easy), pick the branch and deploy. On Ninefold as soon as you push to your branch your app is redeployed via a Post-receive hook.
We configure up the application's environment by passing RAILS_ENV=staging / RAILS_ENV=production, and ensure you have an appropriate (environment).rb file with all the relevant settings for your environment.
Related
What does it mean by deploying code from dev to prod environments using Jenkins. Can anyone please help. I currently have the source code in my gitlab. I need to deploy this code from dev env to prod env
Thanks in advance.
Source code present in GitLab is just the files that is needed to create a WAR/EAR/JAR to run the application.
It's the environment files if present which makes the application behave slightly different on each environment i.e. DEV/PROD the data that you see on DEV will not be the same that you see on PROD(application is live), as developers tend to test/modify code/data to ensure that the application works as excepted. This is fine on DEV but is a big no-no on PROD as it will impact business.
Deploying code from dev to prod environments just means building the application with the right environment files e.g DEV points to xyz DB but prod points to abc DB.
All this can be achieved with jenkins and if your project uses maven/gradle then with a single line command you can achieve the above.(A bit of googling will help you here)
If your project doesn't involve Maven/Gradle then you will have to replace the environment file each time a build happens based on a parameter which can be passed from jenkins.
This whole process is part of DevOps culture. In simple terms it looks like this:
Developer pushes changes to source control (i.e. gitlab).
Build server (i.e. Jenkins) automatically downloads latest changes and builds an application (i.e. creates setup files or just the binaries). Usually you run tests (unit, integration, automation tests etc.). If something fails then developers get notified about it. This whole process is called continuous integration.
If everything went right then you can deploy your application to production. This part of the process is called continuous deployment.
It's a common strategy for web apps. For larger projects QA team tests the software and the software gets deployed once QA team approves it.
I have an general query about maintaining our project. Our project has some code changes between development source and production source. That is production source has live database configuration in web config, and payment checkout mode set to production in some class files. But in development source these are set to testing environment. Other than those both the development and production has same codes. Because of having difference between development and production source, we have to keep these source separately and work on two sources to publish any changes. We are frequently doing any features and bug fixes and publish the changes immediately. So we couldn’t follow Gitflow model (development and master). But Github model will suit for our case because of having immediate publish after feature or bug fixes done.
The problem is Github model says to maintain master source alone. But in our case master source connected to production database, so taking branch from master also connect to production. We need our development should be done with testing configuration. How can we maintain production and testing configuration in master branch itself and switching some configuration leads to connect to testing or production. What is the best way to do this?
Thanks,
Karthik.
From my understanding, Your problem really is about how to keep test config and production config seperate.
If I am right, then here is my two cents.
Say if all your config is in web.config, why not use the config transformation, where you save your test config to git (master) and
use transform to change it to production config when publishing.
In essense, it is just creating another Web.{build profile name}.config where when you publish in that build profile, your web.config will be transorm
more detail check
https://learn.microsoft.com/en-us/aspnet/web-forms/overview/deployment/visual-studio-web-deployment/web-config-transformations
For configuration changes use web config transformations. You can run those enable transformations on build with Visual Studio
Use dependency injection for mocking/faking implementations. You can set some key in web.config (the value is going to be set in web config transformations) which will determine whether to use fake implementation or the real-one
I have an application on GitHub and I am working on making an interface to easily deploy branches of the application to separate Heroku applications for various reasons. Is it possible to specify a specific Heroku application you'd like to deploy a specific branch to using a Heroku deploy button?
If you have git and heroku toolbelt installed with your application, you could easily automate it by calling in in your shell
git push [your-heroku-app-as-a-remote] [branch_name]:master
Where [your-heroku-app-as-a-remote] could be a variable containing the heroku-app you need to push, and [branch_name] a var holding the branch name you want to push.
You could always automate the fetch of all remotes/branches and also the process of creating Heroku apps on the fly. Of course, any scripting language could be used to call all these actions with ease
I have this confusion and perhaps it may be basic question. I am planning to work on a Rails project along with a friend who stays in a different location.
We have identified Heroku as our deployment platform and Bitbucket for SCM related activities.
Both me and my friend are new to rails but we are familiar with web development in general.
I m working on a Windows box while he is on a Mac. We both have the same rails version including the gems. However, I'm not sure really sure how do we manage the source code and code integration. The reason I say this is because, when we try to commit the entire code from our systems a few platform specific rails file gets uploaded on the server, thereby rendering the deployment useless.
So my question is if I am on Windows and my friend is on Mac, whats the recommended way of working together on a single RAILS project and deploy it on a common platform to get the same desired functionality.
Yes, by using the source control management (SCM) you selected when you set up your repository.
For instance, if you use git, you would copy your repository using git clone (the command is provided via the bitbucket interface by clicking on clone), make your changes, and then git push your changes back into the repository.
When you want to code next, execute a git pull command to get the latest repo changes and then work and git push your changes back to the repo.
For examples see Bitbuckets fantastic tutorial.
As a side note, bitbucket also supports mercurial, although I haven't used it.
As far as your actual issue, each person will need to make sure the platform dependent files are excluded from your repository. If you're using git, see the git book specifically the section on .gitignore and git rm
I am working with this school project (webapp in RoR) in group of 10 and we get into this fight.
One says we should use Heroku as our web host because it does version control with git.
The other says it's cool to use Heroku as web host, but it doesn't not store old code and keep track of changes, so we should set up our own github/assembla-git.
Who is right?
Heroku uses git for deploy. So you can use it as version control too.
But I would not recommend it. When you push to heroku it's mean deploy to production. But your code can be not ready for it. Not tested yet, feature not fully implemented and etc.
You can add 2 remote for your repository.
git push origin master # github
git push heroku master
So I would recommend you use heroku as webhost and github as version control
There is nothing wrong with using Heroku as your main Git repository. I have dozens of projects that are set up this way.
Heroku is definitely not going to arbitrarily delete code or commits in your repository.
Of course, anything you push to the master branch will actually be deployed, but you are free to push other branches if you want (Heroku will simply ignore those).
The advantage of using GitHub in addition to Heroku is that you get a bunch of extra functionality on top of just the bare Git repository, such as a web-based UI and collaboration tools like pull requests, etc. Keep in mind that GitHub for private repositories is a paid service, however. There are also competitors to GitHub such as Bitbucket which offers private repositories for free for small teams.
But if you are already familiar with Git and don’t feel like you need any extra functionality on top of it, you might as well just go with Heroku. There’s something to be said for simplicity, as well.