How caiuaeoreo/localizalabschallenge works
Project Type and Purpose
• This project is a challenge from LocalizaLabs focused on deploying a microservice application using AWS infrastructure. The project consists of two major aspects:
• A microservice implemented in Python using Flask (found in the “flask-app” directory), containerized (with a Dockerfile) and tested using automated tests.
• Infrastructure provisioning via Terraform (located in “terraform” and “bucket-tfstate” directories) to set up AWS resources (such as DNS records and tagging modules) that the application will live upon.
• GitHub Actions (with workflow YAML files in several .github directories) are used for CI/CD: running tests, performing build tasks, and deploying the application automatically when changes are merged into the main branch.
Analyzing the File Structure
• Top-level directories:
• .github – contains workflows to support CI/CD for the entire repository.
• bucket-tfstate – holds Terraform backend configuration for remote state storage.
• flask-app – contains the Flask application code (app.py), its Dockerfile for containerization, its Python dependencies (requirements.txt), and tests (test_app.py). This folder also has its own .github directory for any specialized workflow needs.
• terraform – contains Terraform scripts and modules. Within this folder:
▫ The main Terraform configuration (backend.tf, main.tf, outputs.tf, variables.tf) is used for AWS infrastructure deployment.
▫ The “modules” subdirectory holds reusable Terraform modules (e.g., “dns-record” and “tags”) which are used to provision specific AWS resources.
Key Components
a. Main Components:
• Developer/Source Code Repository: Represents the GitHub repository that holds both application and infrastructure code.
• CI/CD Pipeline: GitHub Actions workflows that automate testing, building, and deploying. These workflows are triggered on commits/merges to the main branch.
• Flask Application: The microservice package in “flask-app”, containerized using Docker, responsible for running the application logic.
• Terraform-Based Infrastructure: This includes the AWS infrastructure components configured via Terraform. The “terraform” directory (and its modules) defines resources such as DNS records and tagging, while “bucket-tfstate” configures remote state storage.
• AWS Cloud Resources: Represents the deployed resources (such as compute instances, load balancers, DNS settings, etc.) that support the microservice.
b. Relationships and Interactions:
• Developers push code changes that trigger GitHub Actions workflows.
• CI checks run tests in the flask-app (unit tests, static analysis, etc.) and, upon passing, proceed to build the Docker image.
• Successful builds then initiate Terraform scripts to provision or update the AWS infrastructure.
• The built Docker container containing the Flask app is deployed onto the AWS resources provisioned by Terraform.
• The remote “bucket-tfstate” ensures that Terraform state is maintained consistently across deployments.
c. Architectural Patterns and Design Principles:
• Infrastructure as Code (Terraform modules): Emphasizes reproducibility and modular design.
• Microservice Architecture: Separation of concerns where the Flask app is a distinct, independently deployable service.
• CI/CD Pipeline: Automated integration testing and deployment via GitHub Actions ensure continuous delivery.
• Containerization: Using Docker (via the Dockerfile in flask-app) enables environment consistency.
d. Relevant Technologies and Frameworks:
• Python, Flask, and Docker for building and running the microservice.
• Terraform for describing and deploying cloud infrastructure.
• GitHub Actions to automate testing, builds, and deployment pipelines.
• AWS services as the target runtime environment.
Elements
• Use clear labels for:
• “Developers/Repository” (the GitHub repository holding the code).
• “CI/CD Pipeline” (GitHub Actions workflows that trigger on pushes to ‘main’).
• “Flask Application” (the microservice container built from flask-app).
• “Terraform Infrastructure” (with subcomponents for state management in “bucket-tfstate” and resource provisioning in “terraform” modules).
• “AWS Cloud Resources” (the deployed resources the application runs on).
• From developers committing code and pushing to GitHub.
• From GitHub Actions running tests, building the Docker image, and then triggering Terraform.
• From Terraform modules provisioning/update AWS resources.