Project 2: Automating Testing and Deployment with GitHub Actions

Ayodeji HamedAyodeji Hamed
3 min read

Introduction

Welcome to the second article in my blog series: H A R S H H A A's 50 DevOps Projects: Build Skills from Beginner to Advanced. This project builds upon the foundation laid in the first and dives into the essential realm of Continuous Integration and Continuous Deployment (CI/CD) pipelines.

The task was straightforward: automate the testing and deployment of a simple Python application using GitHub Actions. The pipeline was designed to run tests on every push to the repository and deploy the application to a DigitalOcean droplet upon successful testing. While this was a basic project in theory, I faced unrelated challenges that delayed progress. However, perseverance paid off, and the final outcome was a robust pipeline that served its purpose effectively.


Overview of the Project

This project centers on implementing a Basic CI/CD Pipeline to streamline the development process. Here’s what the pipeline achieved:

  1. Automated Testing:

    • Unit tests were executed automatically using Python's unittest framework in a virtual environment.

    • Any failing test stopped the pipeline, ensuring only valid code was deployed.

  2. Automated Deployment:

    • The application was deployed to a DigitalOcean droplet.

    • The workflow intelligently handled deployment, either updating an existing droplet or creating a new one as needed.

This hands-on project not only emphasized the basics of CI/CD but also laid the groundwork for understanding DevOps best practices.


Approach

This project was broken into the following phases to ensure a structured implementation:

1. Setting Up the Application

I started by creating a simple Python application and a corresponding test suite. The application accepted a user’s name and returned a formatted greeting, while the test suite validated its behavior under different scenarios.

2. Configuring the CI/CD Workflow

The core of the project was the GitHub Actions workflow, defined in code-ci-cd.yml. The workflow consisted of two jobs:

  • Test Job:

    • Ensured code validity by running unit tests on each push to the main branch.

    • Included steps for setting up a virtual environment and installing dependencies.

  • Deploy Job:

    • Depended on the successful completion of the test job.

    • Verified if a DigitalOcean droplet with the desired name existed:

      • If it existed, updated the application and dependencies.

      • If not, created a new droplet and deployed the application.

3. Testing and Debugging the Workflow

Several iterations were performed to debug issues such as missing dependencies, SSH key configuration, and droplet connectivity. Careful logging and error handling ensured these issues were addressed effectively.

For detailed documentation, including screenshots of the testing process, visit the project README.


Key Takeaways

  1. Automation Simplifies Development: Automating repetitive tasks like testing and deployment frees up time for actual development.

  2. Error Handling is Critical: CI/CD workflows must include robust error handling to address unforeseen issues.

  3. Small Steps Lead to Big Wins: Even a simple pipeline like this provides immense value by ensuring code quality and deployment reliability.


Conclusion

This project was a rewarding experience, showcasing the power of GitHub Actions to implement a Basic CI/CD Pipeline. Despite minor setbacks, it reinforced the importance of perseverance and problem-solving in DevOps.


What’s Next?

In the next project, I’ll dive into Docker, where I’ll deploy a static website by:

  • Designing a simple HTML/CSS website.

  • Packaging it into a Docker container.

  • Running it on a local server.

This will introduce the fundamentals of containerization—a must-know skill for any aspiring DevOps engineer.

Catch joke: Why did the developer go broke?
Because they used up all their cache! 😄

Stay tuned for more exciting projects in the H A R S H H A A's 50 DevOps Projects series!

0
Subscribe to my newsletter

Read articles from Ayodeji Hamed directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Ayodeji Hamed
Ayodeji Hamed

🚀 Welcome to my tech playground on Hashnode! I'm Hamed Ayodeji, a DevOps/Cloud Engineer with a passion for all things innovative and cutting-edge in the world of technology. Join me as I explore the latest trends, share insights, and embark on exciting coding adventures. Let's connect, learn, and grow together in this ever-evolving digital landscape! #DevOps #CloudEngineering #Innovation