How to deploy and update the backend server
We have two backend applications that was deployed to AWS cloud server.
One is OD backend application and another is hublink backend application.
If you want some new change or modification, we modify the code part in the
local and updates to the cloud server again.
If this is not expert in this field, it is not easy.
We must know git and linux commands.
1. HUBLink
There are a lot of methods, but, I will try to explain with the easy method.
This is a completed hublink backend application.
To deploy this to cloud server, first, we must deploy this application to
github
The flow diagram is following.
Local work->github deploy->cloud server access->github download->run
The local work means the application that we completed in the local.
As the second step, we must deploy this application to the github.
So, we must create one repository with his github account.
If you login with your account and click your github profile, it shows a lot of
menu items.
Like this, you see a lot of menu items.
There, you click “Your repositories” option.
Then, you see this screen.
Here, you click “New” button.
Then, you see the one screen to create the new repository.
Here, you must give the repository name and you must choose the
repository as the private.
So, other people can’t see and access our repository.
If you set as a public, all the people have the access to our repository and
download our applications.
Next, it has “Add a README file” and “Add .gitignore” file.
These are optional, but, you must generally consider “Add .gitignore” file.
When we develop some application, we download a lot of libraries from
online.
These are really vast and you must not deploy these libraries to the github.
When you run this application in your local, you must download these
libraries from online with some command and run the applications.
So, “.gitignore” file is to add items that must not be deployed.
On this screen, this option that is called “node_modules” is just library and
this is the vast library.
So, this must not be deployed and it must be added to “gitignore” file.
But, without this library, this application can’t absolutely run.
So, if you want to run this application in your PC, you must install these
libraries.
After you download this github source code, if you run this console
command, you can install all the libraries.
It is just simple and it is “npm install”.
NPM is a short of Node Package Manager.
After this command, node_modules directory is shown in the project
structure.
But, this command doesn’t install all the libraries.
It only installs defined libraries in the [Link] file.
In this project, I have used 26 node libraries and if you run “npm install”, 26
libraries are installed.
But, in any PC, “npm install” command doesn’t work.
So that the PC can recognize ‘npm’ command, you must install some
application.
[Link]
In this link, you download some installer file and install it to your PC.
Then, “npm install” command works.
Like this, we make “gitignore” file and within the file, we must add some
commands.
I defined “/node_modules” and it means that this module is not deployed.
The # symbol is comment and it doesn’t have some meaning.
Ok. So, I explained fully about “.gitignore” file.
As the repository name, I gave “HUBLINK” and clicked the “Create
repository” button.
Then, it gives this screen.
Now, the repository was created and we must link our local work and this
github repository.
To do this, we must use the following commands.
git init
git add [Link]
git commit -m "first commit"
git branch -M main
git remote add origin [Link]
git push -u origin main
But, this is very important how and where we use these commands.
First, please go to your local work directory.
In my case, it is E:\Ropeless-Hub-Integration
There are several methods, too, but, I will explain with the method that
developers use very much.
You enter to the work directory and you click the right mouse.
Then, there are Git Gui Here and Git Bash Here option.
You click “Git Bash Here”.
If you can’t see this, you must install these tools.
[Link]
From this site, you download it.
You can download and install 64bit or 32bit.
If you install this, you see options that I mentioned above.
Like this, when you click “Git Bash Here” option, it shows command dialog and it
indicates the root directory of the project.
Here, you input “git init” command as I done on above screenshot.
Then, .git directory is generally.
Next, you input “git add .” command.
After “add” word, you must input surely space and input “.”
Next, you must input git commit –m “first commit”
Here, “first commit” is given with any word.
Because it is new, now, it is just “first commit”.
This command is just words that we see in this screen.
The local work is yet not linked with github.
Next, we must input this command “git branch –M main”.
Next, we must input this command.
This command is just to link our work and github.
After this command, local work and github link is connected each other.
After this connection, we can just deploy.
The git push command is just to deploy our local work to the github repository.
Until now, we saw how the local work is deployed to the github.
Our goal is to download and run this application to cloud server.
To do it, first, we must have the access about cloud server.
You know that your employee, Jamie manages the AWS server.
So, From Jamie, I required some information to access to the server.
Public IP Address: [Link]
Domain: [Link]
And one file that is called “PEM”.
It’s extension is pem and file name is [Link].
Because domain and IP address is same, we can use the domain name or IP
address.
To have an access to the cloud server, we need two information, that is, Domain
or IP address and *.pem file.
In Windows system, there is an application to access to the cloud server that is
called “putty”.
This is a default application and the system has this application.
So, you don’t need to install it.
So, you open the putty application.
Here, you input the domain name or IP address that you receive from server
manager(Jamie).
The port is 22 as default.
And you click “Open” button.
Then, you see some error message because you didn’t add pem file.
So, you must surely add pem file.
The pem file is called “private key”.
It shows “Private key file for authentication” box.
From “Browse” button, you upload pem file from your local pc.
Then, it shows an alert that pem file is not supported.
Really, pem file is not supported with putty application.
We must change *.pem file to *.ppk file.
There is an application to do this.
It is called puttyygen.
This application converts just *.pem file to *.ppk file.
This is a screenshot to convert *.pem file to *.ppk file.
[Link]
This link is very good link for it.
You can follow this link.
After you make *.ppk file, you upload it again.
You must save this ppk file well.
Because it is needed when you access to the cloud server, it is very important file.
Here, you upload the *.ppk file.
You come back to the original screen.
In this original screen, you input the domain name and click “Open” button.
Then, you can see this screen.
This means that you had an access to the cloud server.
As you know, all the cloud servers are linux server and it is not windows server.
Because it is the linux server, you must do everything with console command.
To do this, you must be familiar with Linux commands.
So, I am making this report now.
To do something with this screen, you must have super admin privilege
First, with “clear” command, you make this screen simple.
It is very simple screen.
Here, you input “sudo su” command.
It was changed as user that has an admin privilege.
Next, we must go to /var/www directory.
Because the directory is one that we must access.
We must deploy our application to the directory.
So, you input cd /var/www command.
And you input “ls” command.
The “ls” command is to view the directory structure.
You enter to this directory and you must download your application from your
github account.
The command is following.
git clone [Link]
But, when you click “enter” key, it shows surely an error.
That is, because you didn’t create an access token to access to your github
account.
Without an access token, you can’t download your application to the cloud
server.
git clone
[Link]
r/[Link]
This is an access token from “//” sysmbol to before “@” system.
When you carry out git clone command with this access token, you can download
your application from your github to the this cloud server.
From now, let’s consider how we will create an access token.
In your github profile, you click “Settings” menu.
When you click “Settings”, you can see the following screen.
In this screen, you click “ Developer settings” option.
Then, you can see “Personal access tokens” option and it has two items.
You choose “Tokens(classic)” item.
You click “Generate new token” option.
In Note box, you give some name, for example, I gave “HUBLINK”.
And you must set expiration date.
This token works only until date that you set.
So, generally, I chose “No Expiration” option.
And you must check the option that is called “repo”.
I checked it now.
Next, you click “Generate token” button.
Then, it shows such token.
You must save this well.
Because you can’t download your application from your github to cloud server
without this token.
After you get this token, with this token, you input git clone command.
After this command, within /var/www directory, you can see a new directory that
you downloaded from your github.
It is now ropeless-hub-integration.
The name is the one when you create git repository.
With cd directory name command, you enter within the directory.
Then, you can see the file structure.
It is the file structure that you developed in the local.
It is just this file structure that you developed in your local environment.
In the directory, you give “npm install” command.
So, you must install node libraries.
If the linux server is not recognized npm command, you must install some
program to do it.
$ sudo apt install npm
OR
$ sudo apt install npm nodejs
You must input either of these two commands.
Like this, if you install it, after it, npm command is recognized.
And you run “npm install’ again.
Then, you can see the option that is called “node_modules”.
This means that you installed correctly libraries.
Next, you input npm start command.
Then, the project is compiled and new directory is shown.
It is just “dist” directory.
That is, the compiled files are entered within this directory.
You can confirm it with cd command. cd dist and ls command.
Then, within dist directory, you can see a lot of files that has *.js extension.
This means that the project was correctly compiled.
Because the project was compiled, you must run this project.
You can see file here that is called “[Link]”.
It is just the main function as c language project.
You must run this [Link] file.
The command is following.
pm2 start dist/[Link]
Like this, you input the command.
If the linux server is not recognized pm2 command, you must install this.
Sudo npm i –g pm2
Here, sudo means that it is super admin. You can omit it.
And i means that it is a short of “install”.
And g means that it is global.
After this command, you can use pm2 command.
I put pm2 status command.
It shows that status is online.
It means that the server is running in the cloud server.
If it is not running, it shows ‘offline”.
I tried to explain fully.
This is really a long document.
2. Ocean dashboard.
It is same.
Only difference is domain name and *pem file.
Domain name: [Link]
Public IP: [Link]
And it has *.pem file.
I will upload OD and hublink pem files to google drive.
Currently, Jamie and I have server information(Domain and IP address) and
pem file.
And today, if I share this to you, totally, 3 people know this.
Other people must not have this information except us.
So, you must save this information very well.
Thank you.