Devops

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 11

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- https://github.com/digital-lync-2023/DL-DevOps-Docs

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 https://deb.nodesource.com/setup_16.x | sudo -E bash - &&sudo apt-get install -y


nodejs

Verify Node is Installed: node -v

5. Install PostGres DB

https://www.postgresql.org/download/linux/ubuntu/

sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt $(lsb_release -cs)-pgdg main"


> /etc/apt/sources.list.d/pgdg.list'
wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | 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 https://github.com/KonaMarsTech/lms-public.git

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 konalms.in;
location / {
root /home/azureuser/lms-public/webapp/dist;
}
location /api {
proxy_pass http://localhost:8080;
}
}

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 Node.js 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 package.json 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 Node.js 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 (bhagyadevops.in)

lms-public>>webapp>>
vi .env

change the Localhost name to domain/hostname (bhagyadevops.in)

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 http://yourdomain

13 Install Certificate to Enable HTTPS

URL: https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal

----- 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/index.js

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 : https://docs.docker.com/engine/install/

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 https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -
o /etc/apt/keyrings/docker.gpg

iii. Use the following command to set up the repository:


sudo mkdir -m 0755 -p /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -
o /etc/apt/keyrings/docker.gpg

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 containerd.io 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 https://github.com/KonaMarsTech/lms-public.git

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 http://localhost:8080/api

Access the IP Address to check whether the Application is Up and Running

9. Install Nginx- https://github.com/digital-lync-2023/DL-DevOps-Docs

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 konalms.in;
location / {
proxy_pass http://localhost:3000;
}
location /api {
proxy_pass http://localhost:8080;
}
}

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: https://certbot.eff.org/instructions?ws=nginx&os=ubuntufocal

----- 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 vi.env file in the Web-App FE

VITE_API_URL=https://bhagyadevops.in/api

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/index.js

You might also like