-
Notifications
You must be signed in to change notification settings - Fork 0
87 lines (73 loc) · 3.68 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
78
79
80
81
82
83
84
85
86
87
name: Deploy Spring Boot to EC2
on:
push:
branches:
- main
# - develop
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Set up JDK 21
uses: actions/setup-java@v1
with:
java-version: '21'
- name: Set up Docker credentials
run: |
echo "DOCKER_USERNAME=${{ secrets.DOCKER_USERNAME }}" >> $GITHUB_ENV
echo "DOCKER_PASSWORD=${{ secrets.DOCKER_PASSWORD }}" >> $GITHUB_ENV
- name: Build JAR file
run: ./gradlew bootJar
- name: Build and push Docker image with JIB
run: ./gradlew jib -Pprod --image=${{ secrets.DOCKER_USERNAME }}/the_monitor:latest
deploy:
runs-on: ubuntu-latest
needs: build
steps:
- name: Connect to EC2 and deploy
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ec2-user
key: ${{ secrets.EC2_PRIVATE_KEY }}
script: |
# Create a custom network if it doesn't exist
docker network inspect the_monitor_network >/dev/null 2>&1 || docker network create the_monitor_network
# Stop and remove any existing Redis container
docker stop redis-server || true
docker rm redis-server || true
# Run Redis in the custom network
docker run -d --name redis-server --network the_monitor_network \
-p 6379:6379 redis
# Pull the latest application image
docker pull ${{ secrets.DOCKER_USERNAME }}/the_monitor:latest
# Stop and remove any existing application container
docker stop the_monitor-container || true
docker rm the_monitor-container || true
# Run the application in the custom network
docker run -d --network the_monitor_network -p 8080:8080 --name the_monitor-container \
-e SPRING_DATASOURCE_URL="${{ secrets.SPRING_DATASOURCE_URL }}" \
-e SPRING_DATASOURCE_USERNAME="${{ secrets.SPRING_DATASOURCE_USERNAME }}" \
-e SPRING_DATASOURCE_PASSWORD="${{ secrets.SPRING_DATASOURCE_PASSWORD }}" \
-e CLOUD_AWS_REGION_STATIC="${{ secrets.CLOUD_AWS_REGION_STATIC }}" \
-e CLOUD_AWS_CREDENTIALS_ACCESS_KEY="${{ secrets.CLOUD_AWS_CREDENTIALS_ACCESS_KEY }}" \
-e CLOUD_AWS_CREDENTIALS_SECRET_KEY="${{ secrets.CLOUD_AWS_CREDENTIALS_SECRET_KEY }}" \
-e CLOUD_AWS_S3_BUCKET="${{ secrets.CLOUD_AWS_S3_BUCKET }}" \
-e SPRING_MAIL_HOST="smtp.gmail.com" \
-e SPRING_MAIL_PORT="587" \
-e SPRING_MAIL_USERNAME="${{ secrets.SPRING_MAIL_USERNAME }}" \
-e SPRING_MAIL_PASSWORD="${{ secrets.SPRING_MAIL_PASSWORD }}" \
-e JWT_SECRET_KEY="${{ secrets.JWT_SECRET_KEY }}" \
-e JWT_ACCESS_TOKEN_EXPIRE="${{ secrets.JWT_ACCESS_TOKEN_EXPIRE }}" \
-e JWT_REFRESH_TOKEN_EXPIRE="${{ secrets.JWT_REFRESH_TOKEN_EXPIRE }}" \
-e SPRING_DATA_REDIS_HOST="redis-server" \
-e SPRING_DATA_REDIS_PORT=6379 \
-e NAVER_API_CLIENT_ID="${{ secrets.NAVER_API_CLIENT_ID }}" \
-e NAVER_API_CLIENT_SECRET="${{ secrets.NAVER_API_CLIENT_SECRET }}" \
-e NAVER_API_BASE_URL="${{ secrets.NAVER_API_BASE_URL }}" \
-e GOOGLE_API_KEY="${{ secrets.GOOGLE_API_KEY }}" \
-e GOOGLE_API_SEARCH_ENGINE_ID="${{ secrets.GOOGLE_API_SEARCH_ENGINE_ID }}" \
-e GOOGLE_API_BASE_URL="${{ secrets.GOOGLE_API_BASE_URL }}" \
${{ secrets.DOCKER_USERNAME }}/the_monitor:latest