# Assignment 1 — DevOps CI/CD Website ```html Assignment 1 - Raif

Muhammad Raif Ali

Assignment 1

Azure VM Hosting using GitHub Actions CI/CD

Project Overview

This project demonstrates how to host a static website on an Azure Virtual Machine using Nginx and automate deployment using GitHub Actions.

Step 1 — Azure VM Setup

Connected to Azure Ubuntu VM using SSH.

ssh raif@20.66.70.155
                

Step 2 — Installed Required Packages

Installed Nginx and Git on the Azure VM.

sudo apt update
sudo apt install nginx git -y
                

Step 3 — Created Website Project

Created website folder and added HTML code.

mkdir ~/mywebsite
cd ~/mywebsite
nano index.html
                

Step 4 — GitHub Repository Setup

Created GitHub repository and pushed local code using Git.

git init
git add .
git commit -m "Initial website"
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/mywebsite.git
git push -u origin main
                

Step 5 — Nginx Configuration

Configured Nginx to serve website files.

sudo nano /etc/nginx/sites-available/mywebsite
sudo ln -s /etc/nginx/sites-available/mywebsite /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl restart nginx
                

Step 6 — GitHub Actions CI/CD

Configured GitHub Actions workflow to automatically deploy changes to Azure VM.

name: Deploy Website

on:
  push:
    branches:
      - main

jobs:
  deploy:
    runs-on: ubuntu-latest

    steps:
    - name: Checkout
      uses: actions/checkout@v4

    - name: Deploy to Azure VM
      uses: appleboy/ssh-action@v1.0.3
                

Step 7 — SSH Authentication Fix

Fixed SSH authentication issue by generating SSH keys for the correct user (raif) and adding the public key to authorized_keys.

ssh-keygen -t rsa -b 4096
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys
                

Step 8 — Fixed Dubious Ownership Error

Fixed Git safe directory and ownership issues.

sudo chown -R raif:raif /home/raif/mywebsite
sudo chown -R raif:raif /var/www/mywebsite

git config --global --add safe.directory /home/raif/mywebsite
git config --global --add safe.directory /var/www/mywebsite
                

Step 9 — DuckDNS Domain Configuration

Created a free DuckDNS domain and pointed it to the Azure VM public IP.

Domain Created:
raif-assigment1.duckdns.org

Azure VM Public IP:
20.66.70.155
                

Step 10 — SSL/HTTPS Configuration using Certbot

Installed Certbot and generated a free SSL certificate using Let's Encrypt.

sudo apt update
sudo apt install certbot python3-certbot-nginx -y

sudo certbot --nginx
                

Certbot automatically configured HTTPS and SSL certificates for the website.

Step 11 — HTTPS Enabled Successfully

The website is now securely accessible using HTTPS with automatic certificate renewal.

https://raif-assigment1.duckdns.org
                

Final Result

The website is now automatically deployed whenever code is pushed to GitHub.

Technologies Used:

```