To Bring SSH key Command
User@Phebe-enoch MINGW64 ~
$ cd .ssh/
$ cat id_rsa.pub
Copy SSH Key and paste it while creating the new Webserver
1. Setup Azure VM
2. Connect to VM From VS Code
$ ssh azureuser@IP address
3. Install Nginx- [Link]
sudo apt install nginx
nginx -v
Verify Nginx : sudo systemctl status nginx
Check with IP: IP From Azure - Check in the Browser with the IP. So the Nginx server
should be Up and Running
4. Install Node JS Version 16.X
curl -fsSL [Link] | sudo -E bash - &&sudo apt-get install -y
nodejs
Verify Node is Installed: node -v
5. Install PostGres DB
[Link]
sudo sh -c 'echo "deb [Link] $(lsb_release -cs)-pgdg main"
> /etc/apt/[Link].d/[Link]'
wget --quiet -O - [Link] | sudo apt-key add -
sudo apt-get update
sudo apt-get -y install postgresql
6. Setup DB Password: Password can be anything -password
sudo su postgres
psql
command : \password
postgres=# \password
Enter new password for user "postgres":
Enter it again:
Exit : postgres=# exit
postgres@LMSVMServer:/home/azureuser$ exit
7. Setup LMS Code :
git clone [Link]
Get Branches: git branch -r (Navigate to the LMS-Public folder then search for Git Branches)
git status
Change the Branch to vm-docker-cicd by using following command
git checkout vm-docker-cicd
8. Get Nginx ready to Accept the Request for LMS Application
Stop Nginx: sudo systemctl stop nginx
Remove Defualt Config File:
sudo rm /etc/nginx/sites-enabled/default
sudo vi /etc/nginx/sites-available/lms-app
server {
server_name [Link];
location / {
root /home/azureuser/lms-public/webapp/dist;
}
location /api {
proxy_pass [Link]
}
}
Verify whether the LMS files are available under this path:
cd /var/www/html/
If not, then copy the LMS files from Webapp>Dist folder by using the following command
cd lms-public/webapp/dist/
ls
sudo cp -r * /var/www/html/
Restart Nginx
9. Godaddy and Point Domain Name to our Nginx
10. Setup FE and FE
Got to WebApp Folder: lms-public/webapp
npm install
npm installis a command used in [Link] to install code libraries (also
known as packages or dependencies) that your project needs to run
properly. When you run npm install, it looks at a file called [Link] in
your project folder and installs all the libraries listed there. This command
is important because it saves you time and effort in manually installing
each library one by one, and ensures that you have all the necessary
components for your project to function.
npm run build
npm run build is a command used in [Link] to prepare your web
application for deployment on a production server. When you run this
command, it creates a smaller and optimized version of your application
that is ready to be uploaded to a web server or hosting service. This
optimized version ensures that your application will load faster and
perform better for your users.
Change the Webapp environment variable with domain/hostname ([Link])
lms-public>>webapp>>
vi .env
change the Localhost name to domain/hostname ([Link])
Then again re-run npm run build to make sure that changes are get updated
11. Create a simlink for Sites Avaiable to Sites Enabled
sudo ln -s /etc/nginx/sites-available/lms-app /etc/nginx/sites-enabled/lms-app
12. Restart Nginx to Access the Front
sudo systemctl restart nginx
and Make URL is Up and Running [Link]
13 Install Certificate to Enable HTTPS
URL: [Link]
----- Select Ubuntu 20 and Nginx
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx
Give Email ID :
Say : Y,Y
Select : 1
14: Set Backend API
Go to API Folder (lms-public/app)
npm install
Install PM2 : Node Process Manager
sudo npm install -g pm2
Give DB info in Env File:
sudo vi .env
Go to Insert Mode by typing i
Paste the below code
MODE=production
PORT=8080
DATABASE_URL=postgresql://postgres:password@localhost:5432/postgres
Exit with :wq
15 Get DataBase Ready
npx prisma db push
16 Build and Run Backend:
npm run build
NODE_PORT=8080 pm2 start -i 0 build/[Link]
Setup LMS ON Docker:
1. Install VM on Cloud
2. Install Docker
3. Post Install Steps for Docker
4. Setup DB
5. Create FE Images
6. Create FE Docker Files
7. Build Docker FE Images
8. Build Docker BE Images
9. External Nginx for HTTPS, LB
10. Docker Compose, YAML
Installing Docker Images and Containers
To Bring SSH key Command
User@Phebe-enoch MINGW64 ~
$ cd .ssh/
$ cat id_rsa.pub
Copy SSH Key and paste it while creating the new Webserver
1. Setup Azure VM
2. Connect to VM From VS Code
$ ssh azureuser@IP address
3. Install Docker : [Link]
Setting up the Repository:
i. Update the apt package index and install packages to allow apt to use a repository
over HTTPS:
sudo apt-get update
sudo apt-get install \
ca-certificates \
curl \
gnupg
ii. Add Docker’s official GPG key:
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL [Link] | sudo gpg --dearmor -
o /etc/apt/keyrings/[Link]
iii. Use the following command to set up the repository:
sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL [Link] | sudo gpg --dearmor -
o /etc/apt/keyrings/[Link]
Install Docker Engine:
i. Update the apt package index:
sudo apt-get update
ii. Install Docker Engine, container, and Docker Compose
sudo apt-get install docker-ce docker-ce-cli [Link] docker-buildx-plugin
docker-compose-plugin
Post Docker Installation Steps:
i. Create the docker group.
sudo groupadd docker
ii. Add your user to the docker group.
sudo usermod -aG docker $USER
iii. log out and log back in so that your group membership is re-evaluated.
newgrp docker
4. Setup LMS Code:
git clone [Link]
Get Branches: git branch -r (Navigate to the LMS-Public folder then search for Git Branches)
git status
Change the Branch to vm-docker-cicd by using following command
git checkout vm-docker-cicd
5. Creating Images:
Creating Network:
docker network create lms-network (Network is created)
Front End Image: (lms-public >> Webapp)
docker build --tag lms-web . (Instead of lms-web, we can give our Image name)
Back End Image: (lms-public >> api)
docker build --tag lms-public-api . (Instead of lms-public-api, we can give our Image name)
docker images to check whether the Images are created or not
6. Creating DB with/without Network image:
Without Network:
docker run -d -p 5432:5432 -e POSTGRES_PASSWORD=password --name lmsdb postgres
With Network:
docker run -d -p 5432:5432 --network lms-network -e POSTGRES_PASSWORD=password
--name lmsdb postgres
docker images to check whether the DB Image is created or not and is up and running
When the above is executed along with the Image, the Docker container is also generated.
docker ps to check whether the DB container is created or not and is up and running
7. Setting up the Back-end container with DB through network:
docker run -d -p 8080:8080 --network lms-network -e
DATABASE_URL=postgresql://postgres:password@lmsdb:5432/postgres -e PORT=8080 -e
MODE=local lms-public-api
Add Port 8080 into the Azure Server inbound Network
8. Setting up the Front-end container with Back-end:
docker run -d -p 3000:80 --name lmsfe lms-web
To check the application is up and running in the cd use the following command
curl [Link]
Access the IP Address to check whether the Application is Up and Running
9. Install Nginx- [Link]
sudo apt install nginx
nginx -v
Verify Nginx : sudo systemctl status nginx
10. Get Nginx ready to Accept the Request for LMS Application
Stop Nginx: sudo systemctl stop nginx
Remove Defualt Config File:
sudo rm /etc/nginx/sites-enabled/default
sudo vi /etc/nginx/sites-available/lms-app
server {
server_name [Link];
location / {
proxy_pass [Link]
}
location /api {
proxy_pass [Link]
}
}
Map the Azure IP address to GO daddy Container:
11. Create a simlink for Sites Avaiable to Sites Enabled
sudo ln -s /etc/nginx/sites-available/lms-app /etc/nginx/sites-enabled/lms-app
12 Install Certificate to Enable HTTPS
URL: [Link]
----- Select Ubuntu 20 and Nginx
sudo snap install core; sudo snap refresh core
sudo snap install --classic certbot
sudo ln -s /snap/bin/certbot /usr/bin/certbot
sudo certbot --nginx
Give Email ID :
Say : Y,Y
Select : 1
14 Update the [Link] file in the Web-App FE
VITE_API_URL=[Link]
Now we have to stop the Docker Front end Container
docker ps
docker container stop <<dockerfile name/container ID>>
docker container rm <<dockerfile name/container ID>>
Now the Docker Image should be removed for the stopped container
docker rmi <<dockerfile name/container ID>>
Restart Nginx: sudo systemctl restart nginx
Verify Nginx Status : sudo systemctl status nginx
To check previous run commands: history |grep docker
Now we have changed the FE path, we need to re-build and re-run the docker FE with the
Port number adding into it
docker build --tag lms-web .
docker run -d -p 3000:80 --name lmsfe lms-web
Add Port 3000 into the Azure Server inbound Network
Go to API Folder (lms-public/app)
sudo apt npm install
Install PM2 : Node Process Manager
sudo npm install -g pm2
Give DB info in Env File:
sudo vi .env
Go to Insert Mode by typing i
Paste the below code
MODE=production
PORT=8080
DATABASE_URL=postgresql://postgres:password@localhost:5432/postgres
Exit with :wq
15 Get DataBase Ready
npx prisma db push
16 Build and Run Backend:
npm run build
NODE_PORT=8080 pm2 start -i 0 build/[Link]