Please find steps for Deploying Java WAR file to Tomcat using GitHub Actions:
Pre-requisites:
Implementation steps:
We need to setup secrets to store tomcat user name, password and Tomcat url.
Add Tomcat user name, password and Tomcat Host url as Secret in GitHub Actions
Go to your GitHub Repo --> Settings -->
Click on Secrets and Variables under Security in left nav
Click new Repository Secret
Create TOMCAT_USER secret and add user name
Create TOMCAT_PASSWORD secret and Tomcat passwordClick new Repository Secret
Create TOMCAT_HOST secret and add tomcat url
GitHub Actions Workflow YAML for Deploying a WAR file to Tomcat
You will create this file .github/workflows/cicd.yaml inside GitHub Repo where your Java code is.
name: Build a WAR file using Maven and Deploy Java App to Tomcat running in AWS EC2
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up JDK 11
uses: actions/setup-java@v2
with:
distribution: 'adopt'
java-version: '11'
- name: Build with Maven
run: mvn clean install -f MyWebApp/pom.xml
- name: Deploy to Tomcat
run: |
curl -v -u ${{ secrets.TOMCAT_USER }}:${{ secrets.TOMCAT_PASSWORD }}
-T MyWebApp/target/MyWebApp.war \
"http://${{ secrets.TOMCAT_HOST }}/manager/text/deploy?path=/MyWebApp&update=true"
No comments:
Post a Comment