Exploring Makefiles, SSH, and Gradle
Week 4: Makefiles, SSH, Build Tools & More
Introduction
Hello there! 👋 This past week marked the fourth week of my DevOps journey. While I was a bit inconsistent and sluggish, I still managed to learn some exciting and essential concepts. Initially, my plan was to start learning Python, but I realized it would be better to push it down the roadmap and focus on some other important tools first.
This week, I:
- Completed another mini Bash scripting project
- Learned about Makefiles
- Explored SSH login & SSH keys
- Dived into advanced Git features
- Revised API development in Next.js
- Started learning Build Tools, mainly Gradle
I'll share everything I learned, the resources I used, and the challenges I faced. Let's get started.
Automating AWS S3 Bucket Creation with Bash
Last week, I completed a mini project in which I wrote a script to create an EC2 instance on AWS and automate the AWS configuration. Although I modified the script and learned a lot, I wanted to build something similar but completely on my own.
So, I decided to write a Bash script to create an S3 bucket with default configurations on AWS. I reused some functions from my previous EC2 script, such as AWS CLI installation, and then searched for AWS CLI commands to create an S3 bucket.
Creating an S3 Bucket
The commands for creating an S3 bucket were simpler compared to EC2 instance creation. Here’s the function I wrote:
create_s3_bucket() {
echo "Creating S3 bucket with default name as 'shell-scripting-demo'..."
BUCKET_NAME="shell-scripting-demo"
aws s3 mb s3://$BUCKET_NAME --region $AWS_DEFAULT_REGION
if aws s3api head-bucket --bucket "$BUCKET_NAME" 2>/dev/null; then
echo "S3 bucket created successfully!"
else
echo "There was an error creating S3 bucket, exiting the process..."
exit 1
fi
}
Copying an Item into the S3 Bucket
To add more challenge, I also wrote a function to upload a sample file to the newly created bucket:
copy_item_in_bucket() {
echo "Copying sample item to S3 bucket..."
local ITEM="/home/vagrant/DevOps-Learning/shell-scripting/script-projects/todo.txt"
aws s3 cp $ITEM s3://$BUCKET_NAME
local KEY=$(aws s3api list-objects-v2 --bucket $BUCKET_NAME --query "sort_by(Contents, &LastModified)[-1].Key" --output text)
if [ -n "$KEY" ]; then
echo "Item copied successfully! Bucket name: $BUCKET_NAME S3 item Key: $KEY"
else
echo "Item couldn't be copied to $BUCKET_NAME bucket"
return 1
fi
}
One tricky part was checking whether the item was successfully copied. Initially, I used the prefix keyword, but it was prone to errors as multiple files could have the same starting name (as mentioned on Stack Overflow). Using the last modified sorting provided a better approach.
Learning Makefiles
After completing my mini Bash scripting project, I started learning about Makefiles. I had briefly encountered them during my Linux fundamentals, but I hadn't explored them in depth.
What is a Makefile?
A Makefile is a simple text file that controls a project's build process. It is used to automate tasks in C, C++, and many other languages.
Why Use Makefiles?
Automates repetitive tasks like compiling code, running tests, and installing dependencies.
Simplifies command execution by defining custom rules.
Speeds up builds by recompiling only changed files.
I explored the syntax and practiced by creating a simple Makefile to automate a small workflow.
Exploring SSH & SSH Keys
When I first learned Linux fundamentals, I didn’t fully grasp SSH (Secure Shell), so I revisited it this week. SSH is a protocol used for secure remote server access, file transfers, and system administration.
To practice SSH, I created an EC2 instance to simulate a remote server.
Methods to Login into a Remote Server I learned:
1️⃣ Password Authentication
2️⃣ SSH Keys
Generating an SSH Key Pair
The SSH key method doesn’t require passwords. Here’s how I generated an SSH key pair:
ssh-keygen -t rsa -b 4096
This command creates two keys: a public key (stored on the server) and a private key (stored on the client).
To log in, the public key is matched with the private key using:
ssh user@host_ip_addr
This ensures secure authentication without requiring passwords.
Getting Started with Gradle & Advanced Git Features
I took some time to understand what build tools are and why they are essential in software development. Build tools help automate the process of transforming source code into executable applications by handling tasks like:
Compiling: Converting source code (C, Java, etc.) into machine code or bytecode.
Linking: Combining multiple compiled files into a single executable.
Dependency Management: Ensuring all required libraries are available.
Testing & Packaging: Running unit tests and packaging the application for distribution.
Common Build Tools
Build Tool | Used For | Language |
Make | Automating builds | C, C++ |
Maven | Dependency & project management | Java |
Gradle | Faster, flexible builds | Java, Kotlin |
Bazel | Scalable builds | Multi-language |
Ant | XML-based build automation | Java |
After understanding these concepts, I started with one of the most popular build tools for Java—Gradle.
I started with Gradle, one of the popular build tools for Java, Android, and Kotlin projects. I explored:
→ Gradle Project Structure - Understanding files and directories in a basic project.
→ Gradle Tasks & Wrapper - How automation works within a Gradle project.
→ Running a small Java application using Gradle.
To practice, I got the code of a Java project that prints "Hello" or "Hola" based on an argument. I initially did all this on my Ubuntu dual-boot setup, but I ran into system crashes and memory issues, even though I had allocated 20GB of space. Eventually, I had to remove Ubuntu and switch back to Windows.
After tackling the basics of Gradle, I spent a few hours learning advanced Git features like:
Interactive Rebase
Reflog
Search & Find
Submodules
Cherry-picking
Since I had been focused on DevOps, I hadn't done much Web Development recently. To refresh my skills, I revised API development in Next.js, covering:
CRUD operations
Query parameters
Dynamic routes
Middleware concepts
Resources I used this week-
Challenges I Faced This Week
1️⃣ Checking if an Item Was Copied in an S3 Bucket
Issue: Initial method using prefix keyword was unreliable.
Solution: Used last modified sorting for accuracy.
2️⃣ SSH Login Issues
Issue:
ssh username@server_ip
was failing despite enabling PasswordAuthentication.Solution: Couldn’t find a solution, so I switched to SSH keys, which worked perfectly.
3️⃣ Ubuntu Performance Issues
Issue: Ubuntu wasn’t running smoothly, even with 20GB allocated space.
Solution: Couldn’t find a way to increase disk space, so I removed Ubuntu and switched back to Windows.
What’s Next?
Next week, I plan to:
✅ Explore more Build Tools & Package Managers
✅ Learn about Artifacts & Artifact Repository Management
Let’s Connect!
🔗 My LinkedIn 🔗 My GitHub
If you have any recommended resources, better approaches to my challenges, or insights, I’d love to hear them! Drop your thoughts in the comments.
Have a wonderful day!