-
Notifications
You must be signed in to change notification settings - Fork 0
43 lines (33 loc) · 1.25 KB
/
main.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# Deploys to an Azure Virtual Machine and starts the web app
name: Deploy Java app to Azure Virtual Machine
on:
pull_request:
branches: [ "main" ]
types: [ closed ]
jobs:
deploy:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v2
with:
java-version: '21'
distribution: 'temurin'
cache: maven
- name: Build with Maven
run: mvn -B package --file pom.xml
- name: Create SSH key file
# Write private key to .pem file
run: echo "${{ secrets.SPRING_BOOT_VM_PRIVATE_KEY }}" > private_key.pem
- name: Deploy to Azure Virtual Machine
env:
SPRING_BOOT_VM_IP: ${{ secrets.SPRING_BOOT_VM_IP }}
SPRING_BOOT_VM_USERNAME: ${{ secrets.SPRING_BOOT_VM_USERNAME }}
run: |
# Add host to known hosts
ssh-keyscan -H ${{ secrets.SPRING_BOOT_VM_IP }} >> ~/.ssh/known_hosts
# Transfer artifact using scp
scp -v -o "StrictHostKeyChecking=no" -i private_key.pem target/*.jar $SPRING_BOOT_VM_USERNAME@$SPRING_BOOT_VM_IP:/home/$SPRING_BOOT_VM_USERNAME/spring_boot_demo/