Skip to content

Commit 041b79a

Browse files
committed
hammer: 환경변수 분리 및 deploy 스크립트 작성
1 parent 6b01c32 commit 041b79a

File tree

7 files changed

+155
-0
lines changed

7 files changed

+155
-0
lines changed

.github/workflows/deploy.yml

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Deploy to Server
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
7+
jobs:
8+
build-and-deploy:
9+
runs-on: ubuntu-latest
10+
11+
steps:
12+
- uses: actions/checkout@v2
13+
14+
- name: Set up JDK 17
15+
uses: actions/setup-java@v2
16+
with:
17+
java-version: '17'
18+
distribution: 'adopt'
19+
20+
- name: Build with Gradle
21+
run: |
22+
chmod +x ./gradlew
23+
./gradlew bootJar -x test
24+
25+
- name: Rename JAR to app.jar
26+
run: mv build/libs/*.jar build/libs/app.jar
27+
28+
- name: Upload JAR to Raspberry Pi
29+
uses: appleboy/scp-action@master
30+
with:
31+
host: ${{ secrets.PI_HOST }}
32+
username: ${{ secrets.PI_USERNAME }}
33+
password: ${{ secrets.PI_PASSWORD }}
34+
port: ${{ secrets.PI_PORT }}
35+
source: "build/libs/app.jar"
36+
target: "Project/homework/app.jar"
37+
38+
- name: Restart Docker Compose on Raspberry Pi
39+
uses: appleboy/ssh-action@master
40+
with:
41+
host: ${{ secrets.PI_HOST }}
42+
username: ${{ secrets.PI_USERNAME }}
43+
password: ${{ secrets.PI_PASSWORD }}
44+
port: ${{ secrets.PI_PORT }}
45+
script: |
46+
cd Project/homework
47+
docker-compose up -d --build --force-recreate

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Compiled class file
22
*.class
3+
.env
34

45
# Log file
56
*.log

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ dependencies {
2727
// Swagger
2828
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.8.8'
2929

30+
implementation 'me.paulschwarz:spring-dotenv:4.0.0'
31+
3032
// Spring Web
3133
implementation 'org.springframework.boot:spring-boot-starter-web'
3234

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.vacation.homework.app.config;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
import org.springframework.boot.context.properties.ConfigurationProperties;
6+
7+
@Getter
8+
@Setter
9+
@ConfigurationProperties(prefix = "cors")
10+
public class CorsProperties {
11+
private String allowedOrigins;
12+
private String allowedMethods;
13+
private String allowedHeaders;
14+
private Boolean allowCredentials;
15+
private Long maxAge;
16+
}

src/main/java/com/vacation/homework/app/config/SecurityConfig.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,28 +5,38 @@
55
import com.vacation.homework.app.util.JwtFilter;
66
import com.vacation.homework.app.util.JwtUtil;
77
import lombok.RequiredArgsConstructor;
8+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
89
import org.springframework.context.annotation.Bean;
910
import org.springframework.context.annotation.Configuration;
1011
import org.springframework.security.authentication.AuthenticationManager;
1112
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
1213
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
14+
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
1315
import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer;
1416
import org.springframework.security.config.http.SessionCreationPolicy;
1517
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
1618
import org.springframework.security.crypto.password.PasswordEncoder;
1719
import org.springframework.security.web.SecurityFilterChain;
1820
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
21+
import org.springframework.web.cors.CorsConfiguration;
22+
import org.springframework.web.cors.UrlBasedCorsConfigurationSource;
23+
24+
import java.util.Arrays;
1925

2026
@Configuration
27+
@EnableWebSecurity
2128
@RequiredArgsConstructor
29+
@EnableConfigurationProperties(CorsProperties.class)
2230
public class SecurityConfig {
2331

2432
private final JwtUtil jwtUtil;
2533
private final CustomUserDetailsService userDetailsService;
34+
private final CorsProperties corsProperties;
2635

2736
@Bean
2837
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
2938
http
39+
.cors(cors -> cors.configurationSource(corsConfigurationSource()))
3040
.securityMatcher("/**")
3141
.authorizeHttpRequests(auth -> auth
3242
.requestMatchers("/api/auth/**",
@@ -61,4 +71,22 @@ public PasswordEncoder passwordEncoder() {
6171
return new BCryptPasswordEncoder();
6272
}
6373

74+
/*
75+
* Cors 설정
76+
* */
77+
@Bean
78+
public UrlBasedCorsConfigurationSource corsConfigurationSource() {
79+
UrlBasedCorsConfigurationSource corsConfigSource = new UrlBasedCorsConfigurationSource();
80+
81+
CorsConfiguration corsConfig = new CorsConfiguration();
82+
corsConfig.setAllowedHeaders(Arrays.asList(corsProperties.getAllowedHeaders().split(",")));
83+
corsConfig.setAllowedMethods(Arrays.asList(corsProperties.getAllowedMethods().split(",")));
84+
corsConfig.setAllowedOrigins(Arrays.asList(corsProperties.getAllowedOrigins().split(",")));
85+
corsConfig.setAllowCredentials(corsProperties.getAllowCredentials());
86+
corsConfig.setMaxAge(corsConfig.getMaxAge());
87+
88+
corsConfigSource.registerCorsConfiguration("/**", corsConfig);
89+
return corsConfigSource;
90+
}
91+
6492
}

src/main/java/com/vacation/homework/app/controller/AuthController.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@ public class AuthController {
1919

2020
private final AuthService authService;
2121

22+
@GetMapping("/test")
23+
public ResponseEntity<String> login() {
24+
return ResponseEntity.ok("안녕하세요!");
25+
}
26+
2227
@Operation(summary = "로그인", description = "아이디와 비밀번호로 로그인하고 JWT를 발급받습니다.")
2328
@ApiResponses({
2429
@ApiResponse(responseCode = "200", description = "로그인 성공"),

src/main/resources/application.yml

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
server:
2+
port: 8080
3+
4+
spring:
5+
datasource:
6+
url: ${MYSQL_URL}
7+
username: ${MYSQL_USER}
8+
password: ${MYSQL_ROOT_PASSWORD}
9+
driver-class-name: com.mysql.cj.jdbc.Driver
10+
11+
jpa:
12+
hibernate:
13+
ddl-auto: ${JPA-DDL_AUTO}
14+
properties:
15+
hibernate:
16+
format_sql: true
17+
show_sql: true
18+
database-platform: org.hibernate.dialect.MySQL8Dialect
19+
20+
21+
# cors
22+
cors:
23+
allowed-origins: ${ALLOWED_ORIGINS}
24+
allowed-methods: GET,POST,PUT,PATCH,DELETE,OPTIONS
25+
allowed-headers: "*"
26+
allow-credentials: true
27+
28+
29+
# kafka:
30+
# bootstrap-servers: localhost:9092
31+
# consumer:
32+
# group-id: diary-group
33+
# key-deserializer: org.apache.kafka.common.serialization.StringDeserializer
34+
# value-deserializer: org.apache.kafka.common.serialization.StringDeserializer
35+
# producer:
36+
# key-serializer: org.apache.kafka.common.serialization.StringSerializer
37+
# value-serializer: org.apache.kafka.common.serialization.StringSerializer
38+
39+
jwt:
40+
secret: ${JWT_SECRET}
41+
access-token-expiration: ${ACCESS_TOKEN_EXP}
42+
refresh-token-expiration: ${REFRESH_TOKEN_EXP}
43+
44+
firebase:
45+
service-account-path: classpath:firebase/firebase-service-key.json
46+
47+
springdoc:
48+
api-docs:
49+
enabled: true
50+
swagger-ui:
51+
enabled: true
52+
path: /swagger-ui.html
53+
54+
app:
55+
terms:
56+
version: 1.0.0

0 commit comments

Comments
 (0)