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.
- β 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.
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]
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 |
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.
# ποΈ 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
- Smaller image size
- Faster startup
- No Maven or source code in the final container
Keeps your Docker image clean by ignoring unnecessary files:
target/
.git
.gitignore
README.md
Dockerfile
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.
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
- uses: actions/checkout@v3
β‘οΈ Pulls your latest source code from GitHub.
- 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
- uses: aws-actions/amazon-ecr-login@v2
β‘οΈ Logs Docker into your ECR registry so it can push the image.
docker build -t $IMAGE_URI .
docker push $IMAGE_URI
β‘οΈ Builds your app into a Docker image and pushes it to ECR.
- 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
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 |
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
}
}
- π Add custom domain to App Runner
- π Add health checks and alerting
- π Switch to Terraform IaC
- π Add staging environment
- AWS App Runner Docs
- GitHub Actions Marketplace
- You β for deploying Java apps the cloud-native way βοΈ
You now have:
β
Dockerized Spring Boot app
β
Pushed to Amazon ECR
β
Deployed to AWS App Runner
β
Automated with GitHub Actions
Enjoy shipping with confidence! π³οΈπ»π