Skip to content

πŸš€ This project automates deploying a Java 21 Spring Boot app to AWS App Runner using GitHub Actions, Docker 🐳, and ECR πŸ“¦. It includes IAM πŸ” setup, CI/CD flow πŸ€–, and a live URL 🌐 β€” cloud-native and efficient!

Notifications You must be signed in to change notification settings

moshclouds/springboot-app-runner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ AWS App Runner Demo with Spring Boot and GitHub Actions CI/CD

Image

Welcome to a complete deployment pipeline for your Spring Boot app using:

  • 🐳 Docker
  • ☁️ Amazon ECR
  • βš™οΈ AWS App Runner
  • πŸ€– GitHub Actions

This project shows how to go from code ➑️ container ➑️ deployed app automatically using CI/CD. This README.md will guide you through every step including screenshots, IAM setup, Dockerization, and deployment.


🧰 Tech Stack

  • β˜• Spring Boot (Java 21)
  • 🐳 Docker (multi-stage)
  • πŸ›’οΈ Amazon ECR
  • πŸš€ AWS App Runner
  • πŸ” IAM for secure access
  • πŸ€– GitHub Actions (CI/CD)

You're welcome! Here's a simple yet clear flow diagram that shows the end-to-end process β€” from code to cloud β€” using your Spring Boot, Docker, GitHub Actions, ECR, and AWS App Runner stack.


πŸ” Code to Cloud Flow Diagram

graph TD
  A[πŸ’» Developer Writes Code] --> B[πŸ™ Push to GitHub Repo]
  B --> C[πŸ€– GitHub Actions Triggered]
  C --> D[🐳 Build Docker Image]
  D --> E[☁️ Push to Amazon ECR]
  E --> F[πŸš€ AWS App Runner Pulls Image]
  F --> G[🌐 App Deployed to Public URL]
Loading

πŸ“¦ Components Explained:

Symbol Description
πŸ’» Developer writes Spring Boot code
πŸ™ Code pushed to GitHub triggers workflow
πŸ€– GitHub Actions builds app, pushes to ECR
🐳 Docker image created and uploaded to AWS ECR
πŸš€ App Runner pulls from ECR and deploys the app
🌐 App is now live on a public URL

πŸ“¦ Dockerfile Explained

πŸ” What is a Multi-Stage Build?

In Docker, a multi-stage build allows you to:

  • Compile and build your application in one stage
  • Copy only the final .jar to a clean runtime image in another stage

πŸ‘‰ This reduces image size and keeps the production image clean and secure.

🐳 Dockerfile Breakdown

# πŸ—οΈ Stage 1: Builder
FROM eclipse-temurin:21-jdk AS builder
WORKDIR /app
COPY . .
RUN ./mvnw clean package -DskipTests
  • Uses JDK to build the Spring Boot JAR
  • Skips tests for faster CI builds
  • Packages everything into target/app.jar
# πŸš€ Stage 2: Runtime
FROM eclipse-temurin:21-jre
WORKDIR /app
COPY --from=builder /app/target/*.jar app.jar
EXPOSE 8080
ENTRYPOINT ["java", "-jar", "app.jar"]
  • Uses a smaller JRE image (Java Runtime only)
  • Only the JAR is copied from the builder stage
  • Exposes port 8080 and starts your Spring Boot app

βœ… Benefits:

  • Smaller image size
  • Faster startup
  • No Maven or source code in the final container

πŸ“ .dockerignore

Keeps your Docker image clean by ignoring unnecessary files:

target/
.git
.gitignore
README.md
Dockerfile

πŸ” IAM Setup (Security First)

πŸ§‘β€πŸ’» IAM User for GitHub Actions

Create an IAM user (e.g., springboot-app-runner) with:

  • AmazonEC2ContainerRegistryFullAccess βœ…
  • AWSAppRunnerFullAccess βœ…
  • Custom inline policy:
{
  "Effect": "Allow",
  "Action": "iam:PassRole",
  "Resource": "arn:aws:iam::YOUR_ACCOUNT_ID:role/AppRunnerECRAccessRole"
}

This allows GitHub Actions to pass a role to App Runner.

Image
Image
Image
Image
Image


🎟️ IAM Role for App Runner (access-role-arn)

Create a new IAM Role with:

Trust Policy (custom):

{
	"Version": "2012-10-17",
	"Statement": [
		{
          "Effect": "Allow",
          "Principal": {
            "Service": "build.apprunner.amazonaws.com"
          },
          "Action": "sts:AssumeRole"
        }
	]
}

Permissions:

  • Attach: AmazonEC2ContainerRegistryReadOnly

Image
Image
Image
Image
Image


πŸ—οΈ GitHub Actions Workflow: Step-by-Step

βœ… 1. Checkout Code

- uses: actions/checkout@v3

➑️ Pulls your latest source code from GitHub.


πŸ” 2. Authenticate to AWS

- uses: aws-actions/configure-aws-credentials@v4

➑️ Uses AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY to allow access to AWS services.

Below Shows a Step by Step Guide for the Key creation

Image
Image
Image
Image


πŸ“¦ 3. Log in to Amazon ECR

- uses: aws-actions/amazon-ecr-login@v2

➑️ Logs Docker into your ECR registry so it can push the image.


🐳 4. Build and Push Docker Image

docker build -t $IMAGE_URI .
docker push $IMAGE_URI

➑️ Builds your app into a Docker image and pushes it to ECR.


πŸš€ 5. Deploy to App Runner

- uses: awslabs/amazon-app-runner-deploy@main
  with:
    service: springboot-apprunner
    image: 66656744752.dkr.ecr.us-east-1.amazonaws.com/my-springboot-app:latest
    region: us-east-1
    access-role-arn: ${{ secrets.APP_RUNNER_ACCESS_ROLE_ARN }}

➑️ Deploys the latest image from ECR to AWS App Runner ➑️ Uses the IAM role to pull the image securely


πŸ“¬ GitHub Secrets Required

In your GitHub repo β†’ Settings > Secrets and variables > Actions:

Key Description
AWS_ACCESS_KEY_ID From IAM user
AWS_SECRET_ACCESS_KEY From IAM user
APP_RUNNER_ACCESS_ROLE_ARN IAM role used by App Runner

πŸ“Έ Screenshots

  • βœ… Spring Initializr setup
    Image

  • πŸ“¦ ECR repository screen
    Image

  • πŸš€ App Runner deployment success
    Image
    Image

  • πŸ“¬ Github Action Execution
    Image


🌐 Final Result

Once deployed, App Runner will give you a public URL like:

https://pnxwcd9w25.ap-southeast-1.awsapprunner.com

You can test it by visiting:

GET /
Response:
{
  "status": "success",
  "data": {
    "message": "Server is online",
    "code": 200
  }
}

🚧 Future Improvements

  • πŸ”œ Add custom domain to App Runner
  • πŸ”œ Add health checks and alerting
  • πŸ”œ Switch to Terraform IaC
  • πŸ”œ Add staging environment

πŸ™Œ Acknowledgements

  • AWS App Runner Docs
  • GitHub Actions Marketplace
  • You β€” for deploying Java apps the cloud-native way ☁️

✨ Done!

You now have:

βœ… Dockerized Spring Boot app
βœ… Pushed to Amazon ECR
βœ… Deployed to AWS App Runner
βœ… Automated with GitHub Actions

Enjoy shipping with confidence! πŸ›³οΈπŸ’»πŸŒ

About

πŸš€ This project automates deploying a Java 21 Spring Boot app to AWS App Runner using GitHub Actions, Docker 🐳, and ECR πŸ“¦. It includes IAM πŸ” setup, CI/CD flow πŸ€–, and a live URL 🌐 β€” cloud-native and efficient!

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published