-
Notifications
You must be signed in to change notification settings - Fork 0
77 lines (64 loc) · 2.42 KB
/
deploy.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
name: Deploy to Dev Environment
on:
workflow_dispatch:
inputs:
environment:
description: 'Which environment to deploy to'
required: true
default: 'development'
deploy_message:
description: 'Deployment message'
required: false
jobs:
deploy:
runs-on: self-hosted
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Set up JDK 17
uses: actions/setup-java@v4
with:
distribution: 'corretto'
java-version: '17'
- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v4
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: ${{ secrets.AWS_REGION }}
- name: Decode Google Cloud credentials
run: echo "${{ secrets.GOOGLE_APPLICATION_CREDENTIALS_JSON }}" | base64 --decode > gcloud-key.json
- name: Set GOOGLE_APPLICATION_CREDENTIALS environment variable
run: echo "GOOGLE_APPLICATION_CREDENTIALS=$GITHUB_WORKSPACE/gcloud-key.json" >> $GITHUB_ENV
- name: Build with Maven
env:
GOOGLE_APPLICATION_CREDENTIALS: ${{ env.GOOGLE_APPLICATION_CREDENTIALS }}
run: mvn clean package
- name: Upload JAR artifact
uses: actions/upload-artifact@v3
with:
name: app-jar
path: target/quizly-0.0.1-SNAPSHOT.jar
- name: Download artifact
uses: actions/download-artifact@v3
with:
name: app-jar
path: ./target
- name: Set up SSH key
run: |
mkdir -p ~/.ssh
echo "${{ secrets.EC2_KEY }}" > ~/.ssh/ec2-key.pem
chmod 600 ~/.ssh/ec2-key.pem
- name: Add EC2 host to known_hosts
run: |
ssh-keyscan -H ${{ secrets.EC2_IP }} >> ~/.ssh/known_hosts
- name: Deploy to EC2
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
EC2_IP: ${{ secrets.EC2_IP }}
EC2_JAR_PATH: ${{ secrets.EC2_JAR_PATH }}
run: |
scp -i ~/.ssh/ec2-key.pem target/quizly-0.0.1-SNAPSHOT.jar ec2-user@${{ secrets.EC2_IP }}:${{ secrets.EC2_JAR_PATH }}
ssh -i ~/.ssh/ec2-key.pem ec2-user@${{ secrets.EC2_IP }} 'sudo systemctl restart quizly'