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). π©οΈ
- About the Project
- Features
- Prerequisites
- Getting Started
- CI/CD Workflow Details
- Directory Structure
- Built With
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
- π± 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.
Before you begin, ensure you have the following:
-
AWS IAM User:
- The IAM user should have the
AmazonEC2ContainerRegistryFullAccesspolicy attached.
- The IAM user should have the
-
AWS CLI: Installed and configured with credentials for the IAM user.
-
GitHub Secrets: Set up the following secrets in your GitHub repository:
AWS_ACCESS_KEY_IDAWS_SECRET_ACCESS_KEYAWS_REGIONAWS_ECR_REGISTRY: The AWS account ID.AWS_ECR_REPO_NAME: The name of your ECR repository.
-
Docker: Installed and configured on your local machine if you want to run the image locally.
git clone https://github.com/your-username/nimbus-ecr.git
cd nimbus-ecr-
Build the Project:
mvn clean install
-
Build and Run Docker Container:
docker build -t nimbusecr:local . docker run -p 8080:8080 nimbusecr:local -
Access the Endpoint:
Open your browser or usecurlto hit:curl http://localhost:8080/hello
The .github/workflows/main.yml file defines the CI/CD pipeline. Below is an explanation of each step:
-
Check Out the Code:
Usesactions/checkout@v4to pull the code from the repository. -
Set Up JDK:
Installs OpenJDK 21 to build the Spring Boot application. -
Clean Build Directory:
Removes any previous build artifacts usingmvn clean. -
Build Project:
Builds the Spring Boot JAR file usingmvn install. -
Configure AWS Credentials:
Configures GitHub Actions to use your AWS credentials. -
Login to Amazon ECR:
Authenticates Docker to your Amazon ECR repository. -
Build and Push Docker Image:
- Builds the Docker image for the application.
- Pushes the image to your specified Amazon ECR repository.
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
- 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.
The application exposes a simple REST API:
Response:
{
"message": "server, online!"
}Contributions are welcome! If you find any issues or have suggestions, feel free to open an issue or a pull request.
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>