1- name : Java CI/CD with Gradle and Docker
1+ name : Deploy with Docker Compose
22
33on :
44 push :
55 branches : [ "main" ]
6- pull_request :
7- branches : [ "main" ]
8-
9- permissions :
10- contents : read
116
127jobs :
13- build-docker-image :
8+ deploy :
149 runs-on : ubuntu-latest
10+
1511 steps :
1612 - name : Checkout repository
1713 uses : actions/checkout@v3
1814
19- - name : Set up JDK 17
20- uses : actions/setup-java@v3
21- with :
22- java-version : ' 17'
23- distribution : ' temurin'
24-
25- - name : Grant execute permission for Gradle
26- run : chmod +x ./gradlew
27-
28- - name : Build with Gradle
29- run : ./gradlew clean bootJar
30-
31- - name : Build Docker Image
32- run : docker build -t ${{ secrets.DOCKER_USERNAME }}/fossistant:latest .
33-
34- - name : Docker Hub Login
35- uses : docker/login-action@v2
36- with :
37- username : ${{ secrets.DOCKER_USERNAME }}
38- password : ${{ secrets.DOCKER_PASSWORD }}
39-
40- - name : Push Docker Image to Docker Hub
41- run : docker push ${{ secrets.DOCKER_USERNAME }}/fossistant:latest
42-
43- deploy :
44- runs-on : ubuntu-latest
45- needs : build-docker-image
46- steps :
47- - name : Setup SSH private key
15+ - name : Set up SSH private key
4816 run : |
4917 echo "${{ secrets.SSH_KEY }}" > private_key.pem
5018 chmod 600 private_key.pem
5119
52- - name : Debug SSH connection
53- run : ssh -o StrictHostKeyChecking=no -i private_key.pem ${{ secrets.AZURE_VM_USER }}@${{ secrets.AZURE_VM_HOST }} "echo ✅ SSH 접속 성공!"
20+ - name : Generate .env for Docker Compose
21+ run : |
22+ echo "AZURE_DB_USERNAME=${{ secrets.AZURE_DB_USERNAME }}" >> .env
23+ echo "AZURE_DB_PASSWORD=${{ secrets.AZURE_DB_PASSWORD }}" >> .env
24+ echo "GEMINI_KEY=${{ secrets.GEMINI_KEY }}" >> .env
25+ echo "GITHUB_TOKEN=${{ secrets.GITHUB_TOKEN }}" >> .env
26+ echo "JWT_SECRET_KEY=${{ secrets.JWT_SECRET_KEY }}" >> .env
27+ echo "JWT_ACCESS_TOKEN_TIME=${{ secrets.JWT_ACCESS_TOKEN_TIME }}" >> .env
28+ echo "JWT_REFRESH_TOKEN_TIME=${{ secrets.JWT_REFRESH_TOKEN_TIME }}" >> .env
29+ echo "GITHUB_CLIENT_ID=${{ secrets.GITHUB_CLIENT_ID }}" >> .env
30+ echo "GITHUB_CLIENT_SECRET=${{ secrets.GITHUB_CLIENT_SECRET }}" >> .env
5431
5532 - name : SSH to Azure VM and Deploy
5633@@ -60,33 +37,10 @@ jobs:
6037 key : ${{ secrets.SSH_KEY }}
6138 port : 22
6239 script : |
63- echo "✅ Creating Docker network (if not exists)..."
64- sudo docker network create my-network || true
65-
66- echo "✅ Starting Redis container..."
67- sudo docker rm -f redis || true
68- sudo docker run -d --name redis --network my-network redis
69-
70- echo "✅ Stopping old application container..."
71- sudo docker stop fossistant-container || true
72- sudo docker rm fossistant-container || true
73-
74- echo "✅ Pulling latest application image..."
75- sudo docker pull ${{ secrets.DOCKER_USERNAME }}/fossistant:latest
76-
77- echo "✅ Starting application container...."
78- sudo docker run -d --name fossistant-container -p 8080:8080 \
79- --network my-network \
80- -e SPRING_DATASOURCE_URL="jdbc:mysql://fossistantdb.mysql.database.azure.com:3306/fossistantdb?sslMode=REQUIRED" \
81- -e SPRING_DATASOURCE_USERNAME="${{ secrets.AZURE_DB_USERNAME }}" \
82- -e SPRING_DATASOURCE_PASSWORD="${{ secrets.AZURE_DB_PASSWORD }}" \
83- -e SPRING_GEMINI_API_KEY="${{ secrets.GEMINI_KEY }}" \
84- -e SPRING_REDIS_HOST="redis" \
85- -e SPRING_REDIS_PORT="6379" \
86- -e SPRING_GITHUB_TOKEN="${{ secrets.HUB_TOKEN }}" \
87- -e JWT_SECRET_KEY="${{ secrets.JWT_SECRET_KEY }}" \
88- -e JWT_ACCESS_TOKEN_TIME="${{ secrets.JWT_ACCESS_TOKEN_TIME }}" \
89- -e JWT_REFRESH_TOKEN_TIME="${{ secrets.JWT_REFRESH_TOKEN_TIME }}" \
90- -e SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENT_ID="${{ secrets.CLIENT_ID }}" \
91- -e SPRING_SECURITY_OAUTH2_CLIENT_REGISTRATION_GITHUB_CLIENT_SECRET="${{ secrets.CLIENT_SECRET }}" \
92- ${{ secrets.DOCKER_USERNAME }}/fossistant:latest
40+ cd /home/ubuntu/fossistant
41+ echo "✅ pulling latest image..."
42+ docker compose pull
43+ echo "🧹 stopping old containers..."
44+ docker compose down || true
45+ echo "🚀 starting new containers..."
46+ docker compose up -d --build
0 commit comments