Created
March 13, 2023 12:48
-
-
Save Bogyie/8fce8a560f259e5f6f0e18ed9b16df8f to your computer and use it in GitHub Desktop.
Deploy java project to AWS EC2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
[Unit] | |
Description=Spring Boot Application | |
After=syslog.target | |
[Service] | |
User=ubuntu | |
ExecStart=/usr/bin/java -jar /home/ubuntu/app.jar | |
SuccessExitStatus=143 | |
[Install] | |
WantedBy=multi-user.target |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Deploy to AWS EC2 | |
on: | |
push: | |
branches: | |
- main | |
jobs: | |
deploy: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Java | |
uses: actions/setup-java@v3 | |
with: | |
java-version: '11' | |
- name: Build with Gradle | |
run: ./gradlew build | |
- name: Copy files to remote server | |
uses: appleboy/scp-action@master | |
with: | |
host: ${{ secrets.AWS_EC2_HOST }} | |
username: ${{ secrets.AWS_EC2_USERNAME }} | |
key: ${{ secrets.AWS_EC2_KEY }} | |
source: 'build/libs/*.jar' | |
target: '/home/ubuntu/app.jar' | |
- name: Restart remote service | |
run: ssh -i ${{ secrets.AWS_EC2_KEY }} ${AWS_EC2_USERNAME}@${AWS_EC2_HOST} 'sudo systemctl restart app.service' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment