ImageUploader is a Spring Boot application that allows users to upload images or files to an AWS S3 bucket. It's designed to run on an AWS EC2 instance and can be easily dockerized for deployment. This README provides a brief overview of how to use the application, dockerize it, and set up Continuous Integration/Continuous Deployment (CI/CD) using GitHub Actions.
- Upload images or files to AWS S3 bucket.
- Easy deployment with Docker.
- Automated CI/CD pipeline using GitHub Actions.
- Java 11 or higher
- Docker
- AWS S3 bucket
- AWS EC2 instance
-
Clone the repository:
git clone https://github.com/subhajit4980/ImageUploader.git cd ImageUploader
-
Configure AWS credentials:
Make sure you have AWS credentials configured either through environment variables, AWS CLI, or an IAM role attached to the EC2 instance.
-
Build the application:
./mvnw package
-
Run the application:
java -jar target/ImageUploader.jar
-
Access the application:
Open your web browser and go to http://localhost:8080.
To dockerize the application:
-
Build the Docker image:
docker build -t image-uploader .
-
Run the Docker container:
docker run -p 8080:8080 -e AWS_ACCESS_KEY_ID=<your-access-key> -e AWS_SECRET_KEY=<your-secret-key> image-uploader
Replace
<your-access-key>
and<your-secret-key>
with your AWS access key and secret key.
This repository includes a GitHub Actions workflow to automate CI/CD. The workflow file (ci-cd.yml
) is configured to:
- Build the application.
- Run tests.
- Build the Docker image.
- Push the Docker image to a container registry (e.g., Docker Hub).
- Deploy the application to an AWS EC2 instance.
To set up CI/CD:
name: CICD
on:
push:
branches: [master]
jobs:
build:
runs-on: [ubuntu-latest]
steps:
- name: Checkout source
uses: actions/checkout@v3
- name: Setup Java
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Build Project
env:
ACCESS_KEY: ${{ secrets.ACCESS_KEY }}
SECRET_KEY: ${{ secrets.SECRET_KEY }}
run: mvn clean install -DskipTests
- name: Login to docker hub
run: docker login -u YOUR_DOCKER_USERNAME -p YOUR_DOCKER_PASSWORD
- name: Build docker image
run: docker build -t YOUR_DOCKER_USERNAME/image_upload .
- name: Publish image to docker hub
run: docker push YOUR_DOCKER_USERNAME/image_upload:latest
deploy:
needs: build
runs-on: [AWS-EC2]
steps:
- name: Pull Image from docker hub
run: docker pull YOUR_DOCKER_USERNAME/image_upload:latest
- name: Delete old container
run: docker rm -f image_upload-container
- name: Run docker container
run: docker run -e ACCESS_KEY=AWS_ACCESS_KEY -e SECRET_KEY=AWS_SECRET_KEY -d -p 8080:8080 --name image_upload-container YOUR_DOCKER_USERNAME/image_upload
-
Replace the placeholder values in the workflow file with your AWS credentials and container registry information.
-
Enable GitHub Actions for your repository.
-
Push changes to trigger the CI/CD pipeline.
Before deploying the app please install docker in your virtual machine and configure Github Action Runner.
After configure Github Action Runner run the action-runner by ./run.sh
Contributions are welcome! If you find any issues or have suggestions for improvement, please create a GitHub issue or submit a pull request.