Deploying a Spring Boot application using Github Action, an AWS EC2 instance, and Docker.

date
Feb 21, 2024
slug
spring-boot-deployment
status
Published
tags
SPRING
summary
type
Post

Problem

You have an Amazon EC2 instance, and you want to set up a simple CI/CD using github actions. Additionally, you want to deploy your application inside a Docker container. 

Folder Structure

  • ProjectName
    • Backend
    • Frontend
  1. First, you need to set up secrets. So that github actions can use it to connect with the EC2 server. We need to set HOSTNAME, USERNAME, KEY or PASSWORD of EC2 server. Here, I will be using Key.
notion image
  1. You need to have two files in the Backend folder. One is Dockerfile, and the other is docker-compose.yml for building the docker image and running it.

Dockerfile

docker-compose.yml

  1. Now we need to specify a file for github actions.
Essentially, we're creating a jar file on Github and sending it, together with the Dockerfile and docker-compose.yml file, to the remote server.

Note: You need to install docker and docker-compose on EC2 server first.

 

© Rupesh Dang 2021 - 2025