After using Heroku as a great platform for developing and deploying applications we’re going to learn how to migrate an application from Heroku to GCP (Google Cloud Platform). This blog presents a detailed tutorial using Google Cloud Platform since it allows you to create, implement and scale either apps or websites in the same Google infrastructure.
This blog presents the part 2 of “How to deploy an application on Heroku”.
3.1 Enter to Google Cloud Platform and click on “Go to Console”.
3.2 Once you had entered, create a new project and go to the Compute engine tab:
3.3 Click on VM instances.
3.4 Select create and assigned it a name and select the project on the top, as the image shows:
3.5 Create a new instance:
3.6 Create it as your convenience, the price it shows is a mensual average of how much the instance will cost.
The instance will look like this:
3.7 To start working with the instance, click on the “SSH” button or with a remotely terminal. After you logged in with an SSH session on the Google Cloud instance, proceed to install Heroku CLI to clone the repository with the application’s files.
3.7.1 You’re going to install Heroku CLI with next commands:
sudo apt-get install software-properties-common # debian only sudo add-apt-repository "deb https://cli-assets.heroku.com/branches/stable/apt ./" curl -L https://cli-assets.heroku.com/apt/release.key | sudo apt-key add - sudo apt-get update sudo apt-get install heroku
3.8 After the installation, clone the app with:
heroku git:clone -a “proyect” cd “proyect”
3.9 For the next step is necessary to install MySQL, Node.js, Nginx and npm; they allow us to use the port 80. Just in case you want to manage the different versions of Node.js you can use nvm through npm, on this occasion we’re going to use the default version.
sudo apt-get install nodejs nodejs-legacy npm nginx mysql-server
3.10 It is time to configure the local database and to import the backup we previously mentioned on the requirements. Here are the commands to do it:
mysql -u “root” -p #Set your password
3.11 Create a database and a user inside of MySQL:
create database “name”; use “name”; source “database/route”;
3.12 The only thing we’re missing it to modify the database configuration files with the needed data. In order to use the port 80 is necessary to edit the default server block of Nginx located in:
server { listen 0.0.0.0:80; server_name aplicacion.com.mx www.aplicacion.com.mx; access_log /var/log/nginx/aplicacion.log; error_log /var/log/nginx/aplicacion.log; location ~ /.well-known { allow all; } location / { proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarder-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_set_header X-NginX-Proxy true; proxy_pass http://127.0.0.1:3000; proxy_read_timeout 600; proxy_redirect off; } }
3.12.1 Save everything and reset Nginx with:
sudo service nginx restart
3.13 The applications of node have a file called “package.json”, it contains the modules that the application needs to work properly. To install them we only need the next command:
npm install
3.13.1 If everything went properly then the app is ready to run, you can do this with the next
command: node “file.js” ó npm start
*In case you want to run it in the background, you can use a tool as supervisor, the documentation is in the next link: http://supervisord.org
As you can see, migrating a NodeJS application from Heroku to Google Cloud Platform becomes really easy and fast. Google Cloud offers a wide variety of services that our applications would benefit. From now on, migrating from one cloud to another shouldn’t be a problem for you. Hire a dedicated team of experts to assess your current environment and help you migrate any application to Google Cloud Platform or in any other cloud.
Discover the steps for developing cloud applications, from costs to cloud app deployment
Imagine launching your product with just the core features, getting honest user feedback, and then…
When a tight deadline is non-negotiable, every second counts! Here’s how we developed and launched…
You may have considered hiring a nearshore software development company or services, but you still have doubts…
End-to-end project management goes as far back as you can remember. Every project in history, even…
AWS DevOps has recently become a trending topic in IT circles as it offers companies…