Skip to content

Welcome to NimbusECR! This project demonstrates a full CI/CD pipeline using GitHub Actions to build and push a Dockerized Spring Boot application to Amazon Elastic Container Registry (ECR). 🌩️

Notifications You must be signed in to change notification settings

moshclouds/NimbusECR

Repository files navigation

NimbusECR πŸš€

Welcome to NimbusECR! This project demonstrates a full CI/CD pipeline using GitHub Actions to build and push a Dockerized Spring Boot application to Amazon Elastic Container Registry (ECR). 🌩️

18 (3)

πŸ“œ Table of Contents


πŸ” About the Project

NimbusECR is a starter Spring Boot REST API application with a hello world endpoint, designed to showcase the following:

  • Building a Spring Boot application using Maven
  • Containerizing the application with Docker
  • Pushing the image to Amazon Elastic Container Registry (ECR) using GitHub Actions
  • Deploying and running the container on local or cloud environments

✨ Features

  • 🌱 Lightweight Spring Boot Starter App: Minimalistic REST API for easy understanding.
  • πŸ‹ Dockerized Build: Containerized application for consistent deployments.
  • ☁️ ECR Integration: Pushes the Docker image to Amazon ECR seamlessly.
  • πŸ€– Automated CI/CD: Utilizes GitHub Actions for build and push automation.

πŸ› οΈ Prerequisites

Before you begin, ensure you have the following:

  1. AWS IAM User:

    • The IAM user should have the AmazonEC2ContainerRegistryFullAccess policy attached.
  2. AWS CLI: Installed and configured with credentials for the IAM user.

  3. GitHub Secrets: Set up the following secrets in your GitHub repository:

    • AWS_ACCESS_KEY_ID
    • AWS_SECRET_ACCESS_KEY
    • AWS_REGION
    • AWS_ECR_REGISTRY: The AWS account ID.
    • AWS_ECR_REPO_NAME: The name of your ECR repository.
  4. Docker: Installed and configured on your local machine if you want to run the image locally.


πŸš€ Getting Started

Clone the Repository

git clone https://github.com/your-username/nimbus-ecr.git
cd nimbus-ecr

Run Locally

  1. Build the Project:

    mvn clean install
  2. Build and Run Docker Container:

    docker build -t nimbusecr:local .
    docker run -p 8080:8080 nimbusecr:local
  3. Access the Endpoint:
    Open your browser or use curl to hit:

    curl http://localhost:8080/hello

πŸ€– CI/CD Workflow Details

GitHub Actions Workflow

The .github/workflows/main.yml file defines the CI/CD pipeline. Below is an explanation of each step:

  1. Check Out the Code:
    Uses actions/checkout@v4 to pull the code from the repository.

  2. Set Up JDK:
    Installs OpenJDK 21 to build the Spring Boot application.

  3. Clean Build Directory:
    Removes any previous build artifacts using mvn clean.

  4. Build Project:
    Builds the Spring Boot JAR file using mvn install.

  5. Configure AWS Credentials:
    Configures GitHub Actions to use your AWS credentials.

  6. Login to Amazon ECR:
    Authenticates Docker to your Amazon ECR repository.

  7. Build and Push Docker Image:

    • Builds the Docker image for the application.
    • Pushes the image to your specified Amazon ECR repository.

πŸ—‚οΈ Directory Structure

nimbus-ecr/
β”œβ”€β”€ src/                   # Application source code
β”‚   β”œβ”€β”€ main/
β”‚   β”‚   β”œβ”€β”€ java/
β”‚   β”‚   β”‚   └── com.example.demo/ # Your Spring Boot code
β”‚   β”‚   └── resources/     # Application resources
β”œβ”€β”€ target/                # Compiled JAR and build artifacts
β”œβ”€β”€ Dockerfile             # Docker configuration file
β”œβ”€β”€ pom.xml                # Maven project file
└── .github/
    └── workflows/
        └── main.yml       # CI/CD workflow file

πŸ› οΈ Built With

  • Spring Boot: A Java framework for building RESTful APIs.
  • Maven: Dependency and build management.
  • Docker: Containerization platform.
  • Amazon ECR: Secure container registry.
  • GitHub Actions: CI/CD automation.

πŸ“œ Example API Endpoint

The application exposes a simple REST API:

GET /

Response:

{
  "message": "server, online!"
}

πŸŽ‰ Contributing

Contributions are welcome! If you find any issues or have suggestions, feel free to open an issue or a pull request.


πŸš€ Ready to Deploy

Once the Docker image is pushed to Amazon ECR, you can pull it and run it locally or deploy it in your AWS environment.

# Authenticate Docker
aws ecr get-login-password --region <your-region> | docker login --username AWS --password-stdin <your-ecr-uri>

# Pull the image
docker pull <your-ecr-uri>:<tag>

# Run the container
docker run -p 8080:8080 <your-ecr-uri>:<tag>

Proof Of Concepts

iam_user
image_ecr
local_docker_logs
local_docker_logs
auth_ECR
ecr_repo
create_aws_ecr_repo

About

Welcome to NimbusECR! This project demonstrates a full CI/CD pipeline using GitHub Actions to build and push a Dockerized Spring Boot application to Amazon Elastic Container Registry (ECR). 🌩️

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published