This approach will deploy a spring boot MVC application to Tomcat in EC2 location. We will use two built-in mechanisms of Github

  1. Action: For CI Part (Build Test etc)

and

  1. Runner: For CD Part (Deployment )

<aside> 💡 Disclaimer: This approach is not an ideal approach for the production environment as CI and production server are in the same location here. This is why the tomcat server is stopped before the maven builds start, to avoid low configuration EC2 freeze conditions. Use it only for personal projects.

</aside>

Technology Used:

Steps:

Step 1:Configure Workflow/Action for CI


Step 2: Configure Runner for CD



For Step 1

Sample maven.yml

# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time
# For more information see: <https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven>

name: Java CI with Maven

on:
  push:
    branches: [ "main" ]
jobs:
  build:

    runs-on: self-hosted

    steps:
      - uses: actions/checkout@v3
      - name: Set up JDK 11
        uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'temurin'
          cache: maven
      - name: stop tomcat
        run: sudo systemctl stop tomcat & rm -rf _work/prod-mnhmilu-server.com/prod-mnhmilu-server.com/demo/target/myblog.war
      - name: Build with Maven
        run: mvn -B package --file demo/pom.xml
      - name: Remove old myblog
        run: sudo rm -r /opt/tomcat/webapps/myblog
      - name: Copy to tomcat folder and start tomcat
        run: sudo cp -rf /home/ubuntu/actions-runner/_work/prod-mnhmilu-server.com/prod-mnhmilu-server.com/demo/target/myblog.war /opt/tomcat/webapps & sudo systemctl start tomcat