GitHub Fundamentals: Basics and Rollback Strategies ππβͺ
Letβs go through the process of setting up EC2 instances, connecting to GitHub with SSH keys, deploying two different websites one after the other, and then using version control to revert to the first website i.e previous deploymentοΈ. This will help us check if `git revert` or rollback works correctly. ππ₯
Step 1: Create EC2 Instances with Ubuntu AMI π
- Launch an EC2 Instance:
- Choose Ubuntu as the Amazon Machine Image (AMI) π§
- Launch the instance and connect to it via SSH. π
Step 2: Create SSH Keys π
- Generate SSH Keys:
- Run the command: `ssh-keygen` π§ - Display the public key: `cat /home/ubuntu/.ssh/id_rsa.pub` π
Step 3: Connect to GitHub π
1. Copy the SSH Key:
Copy the output of `cat /home/ubuntu/.ssh/id_rsa.pub`. π
2. Add SSH Key to GitHub:
Go to GitHub settings, navigate to βSSH and GPG keysβ and paste your SSH key. π»
Step 4: Create a Repository on GitHub π
- Create a New Repository:
- Name it
devops88 or anything of your choice
Step 5: Clone the Repository π
1. Copy the SSH Link:
- Click on the βCodeβ button and copy the SSH link. π
2. Clone the Repository:
- Open Git Bash terminal and run: `git clone [your SSH link]` π
Step 6: Create a Script π
1. Navigate to the Repository:
- Go to your cloned repository directory.
2. Create a Script:
- Create a file named website.sh
` and add your deployment code for the `chillingcafe` website. πΎ
Step 7: Set Execute Permission on the Script π
- Grant Execute Permission:
sudo chmod +x website.sh
Step 8: Execute the Script and View the Website π
- Run the Script:
- Execute: website.sh
2. View the Website:
- Place the instanceβs IP address in a new browser tab. π
Step 9: Check and Add Files π
1. Check the Status:
- Run: `git status` to see the changes. π
2. Add the Script:
- Run: `git add website.sh` β
Step 10: Commit and Push to GitHub π€
1. Commit the Changes:
- Run: `git commit -m β Deploying chilling cafe websiteβ` π
2. Push to Repository:
- Run: `git push` π
Step 11: Deploying a New Website π
1. Change the Script:
- Update website.sh
with the deployment code for the `moso-interior
` website (Another website template). βοΈ
Step 12: Check and Add Changes π
1. Check the Status:
- Run: `git status` to see the changes. π
2. Add the Script:
- Run: `git add website.sh` β
Step 13: Commit and Push Updates π€
- Commit the Changes:π
git commit -m "Deploying moso interior website"
2. Push to Repository:π
git push
Step 14: Refresh and View Updated Website ππ
- Refresh the Browser Tab:
- View the updated `moso interior` website with the instanceβs IP address. π
Step 15: Reverting to the Previous Website using commit hashβͺ
- Revert to Previous Commit:
git log
To find the commit ID of the `chilling cafe` deployment. π΅οΈ
2. Run: `git revert [commit ID]` to undo the changes and go back to the `chilling cafe` website. β©οΈ
Step 16: Re-deploy the Previous Code π
- Execute the Reverted Script:
- Run:website.sh
π
- View the Previous Website:
- Refresh the browser tab to see the `chilling cafe` website again. π
2. Push to Repository:
- Run: `git push` π€
And there you have it! Youβve set up EC2 instances, connected to GitHub, deployed your websites, and used the `git revert` command to switch back to a previous version. Happy coding! βοΈπ