Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 25 additions & 28 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ on:
env:
# Backend paths
BACKEND_JAR_PATH: build/libs/
REMOTE_BACKEND_PATH: "~/mywiki"

JAR_FILENAME: mywiki.jar
REMOTE_BACKEND_PATH: "~/mywiki/backend"

# Frontend paths
FRONTEND_SRC_PATH: ./frontend
FRONTEND_BUILD_PATH: frontend/build
REMOTE_FRONTEND_PATH: "/var/www/nginx"
REMOTE_FRONTEND_PATH: "~/mywiki/frontend"

jobs:
deploy-backend:
Expand All @@ -39,61 +40,57 @@ jobs:
- name: Build Backend JAR
run: ./gradlew bootJar

- name: Find JAR file name
id: find_jar
run: |
JAR_FILE=$(find ${{ env.BACKEND_JAR_PATH }} -name "*.jar" | head -n 1)
echo "jar_file=$JAR_FILE" >> $GITHUB_OUTPUT

- name: Create backend .env file
run: |
echo "DB_HOST=${{ secrets.DB_HOST }}" > .env
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> .env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> .env
echo "GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }}" >> .env
echo "GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }}" >> .env
echo "OAUTH2_REDIRECT_URI=http://${{ secrets.SERVER_HOST }}" >> .env

- name: Create remote directory
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_SECRET }}
script: mkdir -p ${{ env.REMOTE_BACKEND_PATH }}
echo "OAUTH2_REDIRECT_URI=${{ vars.OAUTH2_REDIRECT_URI }}" >> .env
echo "CORS_ALLOWED_ORIGINS=${{ vars.CORS_ALLOWED_ORIGINS }}" >> .env

- name: SCP JAR file
uses: appleboy/scp-action@master
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_SECRET }}
source: "${{ steps.find_jar.outputs.jar_file }}"
target: "${{ env.REMOTE_BACKEND_PATH }}/app.jar"
source: "${{ env.BACKEND_JAR_PATH }}${{ env.JAR_FILENAME }}"
target: "${{ env.REMOTE_BACKEND_PATH }}"
strip_components: 2
overwrite: true

- name: SCP .env file
uses: appleboy/scp-action@master
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_SECRET }}
source: ".env"
target: "${{ env.REMOTE_BACKEND_PATH }}"
overwrite: true

- name: Execute remote deploy script
uses: appleboy/ssh-action@master
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
key: ${{ secrets.SSH_SECRET }}
script: |
cd ${{ env.REMOTE_BACKEND_PATH }}
echo "Stopping existing application..."
pgrep -f app.jar | xargs -r kill -15 || true
sleep 5
# PID 파일이 있으면, 해당 파일의 PID를 읽어 프로세스를 종료합니다.
if [ -f ./mywiki.pid ]; then
kill -15 $(cat ./mywiki.pid) || true
rm ./mywiki.pid
sleep 5
fi

echo "Starting new application..."
set -o allexport; source .env; set +o allexport
nohup java -jar app.jar > app.log 2>&1 &
# 새 애플리케이션을 백그라운드로 실행하고, 프로세스 ID를 app.pid 파일에 저장합니다.
nohup java -jar ${{ env.JAR_FILENAME }} > app.log 2>&1 & echo $! > ./mywiki.pid

deploy-frontend:
name: Deploy Frontend
Expand All @@ -119,7 +116,7 @@ jobs:
npm run build

- name: Prepare remote directory
uses: appleboy/ssh-action@master
uses: appleboy/ssh-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
Expand All @@ -130,7 +127,7 @@ jobs:
rm -rf ${{ env.REMOTE_FRONTEND_PATH }}/*

- name: SCP Frontend files
uses: appleboy/scp-action@master
uses: appleboy/scp-action@v1
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USERNAME }}
Expand Down
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -64,3 +64,7 @@ kotlin {
tasks.withType<Test> {
useJUnitPlatform()
}

tasks.withType<org.springframework.boot.gradle.tasks.bundling.BootJar> {
archiveFileName.set("mywiki.jar")
}
2 changes: 1 addition & 1 deletion frontend/public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
<title>My Wiki</title>
</head>
<body>
<noscript>You need to enable JavaScript to run this app.</noscript>
Expand Down
4 changes: 2 additions & 2 deletions frontend/public/manifest.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"short_name": "React App",
"name": "Create React App Sample",
"short_name": "My Wiki",
"name": "집단지성을 이용한 거대하고 효율적인 지식 저장소 구축 프로젝트",
"icons": [
{
"src": "favicon.ico",
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/api/apiClient.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import axios from 'axios';

const apiClient = axios.create({
baseURL: process.env.REACT_APP_API_BASE_URL || 'http://localhost:8080',
baseURL: process.env.REACT_APP_API_BASE_URL || '',
withCredentials: true, // 세션 쿠키 사용을 위해 필수
});

Expand Down
5 changes: 2 additions & 3 deletions frontend/src/pages/LoginPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,8 @@ import './LoginPage.css';

const LoginPage: React.FC = () => {
const handleLogin = () => {
if (process.env.REACT_APP_API_BASE_URL) {
window.location.href = `${process.env.REACT_APP_API_BASE_URL}/oauth2/authorization/google`;
}
const baseUrl = process.env.REACT_APP_API_BASE_URL || '';
window.location.href = `${baseUrl}/oauth2/authorization/google`;
};

return (
Expand Down
4 changes: 2 additions & 2 deletions nginx-prod.conf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ server {
try_files $uri $uri/ /index.html;
}

# API 요청을 백엔드 서버(localhost:8080)로 전달
location /api/ {
# API, 인증 요청을 백엔드 서버(localhost:8080)로 전달
location ~ ^/(api|oauth2|login/oauth2) {
proxy_pass http://localhost:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
Expand Down
5 changes: 3 additions & 2 deletions src/main/kotlin/com/yhproject/mywiki/config/SecurityConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ import org.springframework.web.cors.UrlBasedCorsConfigurationSource
@EnableWebSecurity
class SecurityConfig(
private val customOAuth2UserService: CustomOAuth2UserService,
@Value("\${app.oauth2.redirect-uri}") private val redirectUri: String
@Value("\${app.oauth2.redirect-uri}") private val redirectUri: String,
@Value("\${app.cors.allowed-origins}") private val allowedOrigins: String
) {

@Bean
Expand Down Expand Up @@ -56,7 +57,7 @@ class SecurityConfig(
@Bean
fun corsConfigurationSource(): CorsConfigurationSource {
val configuration = CorsConfiguration()
configuration.allowedOrigins = listOf("http://localhost:3000")
configuration.allowedOrigins = allowedOrigins.split(",")
configuration.allowedMethods = listOf("GET", "POST", "PUT", "DELETE", "OPTIONS")
configuration.allowedHeaders = listOf("*")
configuration.allowCredentials = true
Expand Down
7 changes: 6 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
server:
forward-headers-strategy: framework

spring:
application:
name: mywiki

datasource:
url: jdbc:mysql://localhost:3306/mywiki
url: jdbc:mysql://${DB_HOST:localhost}:3306/mywiki
username: ${DB_USERNAME:mywiki}
password: ${DB_PASSWORD:1234}
driver-class-name: com.mysql.cj.jdbc.Driver
Expand All @@ -30,3 +33,5 @@ spring:
app:
oauth2:
redirect-uri: ${OAUTH2_REDIRECT_URI:http://localhost:3000}
cors:
allowed-origins: ${CORS_ALLOWED_ORIGINS:http://localhost:3000}
2 changes: 2 additions & 0 deletions src/test/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,5 @@ spring:
app:
oauth2:
redirect-uri: http://localhost:3000
cors:
allowed-origins: http://localhost:3000