From 0845488511a1e481680a2f4b18fbeadcee871727 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=84=B1=ED=9B=88?= Date: Thu, 14 Mar 2024 18:38:41 +0900 Subject: [PATCH 01/38] fixed start package --- .../JWT/user/controller/AdminController.java | 41 ++++++++++--------- .../JWT/user/controller/UserController.java | 1 + .../java/JWTLogIn/JWT/user/dto/UserDTO.java | 4 +- .../JWTLogIn/JWT/user/entity/UserEntity.java | 7 ++-- .../JWT/user/repository/UserRepository.java | 12 +++--- .../JWTLogIn/JWT/user/security/JwtFilter.java | 6 +-- .../JWTLogIn/JWT/user/security/JwtUtil.java | 12 +++--- .../JWT/user/service/AuthService.java | 6 +-- .../JWT/user/service/UserService.java | 6 +-- JWT/src/main/resources/application.properties | 2 +- 10 files changed, 50 insertions(+), 47 deletions(-) diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java b/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java index 1f45488..36b137f 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java @@ -15,6 +15,7 @@ import java.util.List; @RestController +@RequestMapping("/tgwing.kr") @RequiredArgsConstructor public class AdminController { @@ -34,11 +35,11 @@ public ResponseEntity> userAll(Authentication authentication) { @GetMapping("/userlist") public ResponseEntity> userPage(Pageable pageable, @RequestHeader("authorization") String token) { String jwt = token.split(" ")[1]; - Level level = authService.extractLevel(jwt); - - if(!level.equals(Level.MANAGER)) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } +// Level level = authService.extractLevel(jwt); +// +// if(!level.equals(Level.MANAGER)) { +// return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); +// } Page userAllByPage = userService.findUserAllByPage(pageable); @@ -48,11 +49,11 @@ public ResponseEntity> userPage(Pageable pageable, @RequestHeader( @PutMapping("/userlist/put/manager/{userId}") public ResponseEntity changeAdmin(@PathVariable Long userId, @RequestHeader("authorization") String token) { String jwt = token.split(" ")[1]; - Level level = authService.extractLevel(jwt); - - if(!level.equals(Level.MANAGER)) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } +// Level level = authService.extractLevel(jwt); +// +// if(!level.equals(Level.MANAGER)) { +// return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); +// } userService.changeLevel(userId, Level.MANAGER); @@ -62,11 +63,11 @@ public ResponseEntity changeAdmin(@PathVariable Long userId, @RequestHeade @PutMapping("/userlist/put/member/{userId}") public ResponseEntity changeMember(@PathVariable Long userId, @RequestHeader("authorization") String token) { String jwt = token.split(" ")[1]; - Level level = authService.extractLevel(jwt); - - if(!level.equals(Level.MANAGER)) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } +// Level level = authService.extractLevel(jwt); +// +// if(!level.equals(Level.MANAGER)) { +// return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); +// } userService.changeLevel(userId, Level.MEMBER); @@ -76,11 +77,11 @@ public ResponseEntity changeMember(@PathVariable Long userId, @RequestHead @PutMapping("/userlist/put/normal/{userId}") public ResponseEntity changeNormal(@PathVariable Long userId, @RequestHeader("authorization") String token) { String jwt = token.split(" ")[1]; - Level level = authService.extractLevel(jwt); - - if(!level.equals(Level.MANAGER)) { - return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); - } +// Level level = authService.extractLevel(jwt); +// +// if(!level.equals(Level.MANAGER)) { +// return ResponseEntity.status(HttpStatus.FORBIDDEN).build(); +// } userService.changeLevel(userId, Level.NORMAL); diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java b/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java index 545e7a8..f330665 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java @@ -9,6 +9,7 @@ import org.springframework.web.bind.annotation.*; @RestController +@RequestMapping("/tgwing.kr") @RequiredArgsConstructor public class UserController { diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java index ac64db2..b81e7d2 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/dto/UserDTO.java @@ -19,7 +19,7 @@ public class UserDTO { private Status status; // 재학/휴학 상태 private String semester; // 학년, 학기(3글자로 설정) private String phoneNumber; // 전화번호(13글자로 설정) - private Level level;// 일반, 동아리, 관리인 3가지 분류 +// private Level level;// 일반, 동아리, 관리인 3가지 분류 public static UserEntity toUserEntity(UserDTO userDTO) { @@ -33,7 +33,7 @@ public static UserEntity toUserEntity(UserDTO userDTO) { .status(userDTO.getStatus()) .semester(userDTO.getSemester()) .phoneNumber(userDTO.getPhoneNumber()) - .level(userDTO.getLevel()) +// .level(userDTO.getLevel()) .build(); } } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java b/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java index fe9c980..d30bb45 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/entity/UserEntity.java @@ -3,6 +3,7 @@ import JWTLogIn.JWT.user.dto.UserDTO; import JWTLogIn.JWT.user.entity.Enum.Level; import JWTLogIn.JWT.user.entity.Enum.Status; +import com.fasterxml.jackson.annotation.JsonValue; import jakarta.persistence.*; import lombok.*; import org.hibernate.annotations.DynamicInsert; @@ -40,8 +41,8 @@ public class UserEntity extends BaseEntity{ @Column(nullable = false, unique = true, length = 13) private String phoneNumber; // 전화번호(13글자로 설정) - @Column(length = 7) - private Level level; +// @Column(length = 7) +// private Level level; // 연관매핑: 일대다 // 참조 당하는 엔티티에서 사용 @@ -60,7 +61,7 @@ public static UserDTO toUserDTO(UserEntity userEntity) { .status(userEntity.getStatus()) .semester(userEntity.getSemester()) .phoneNumber(userEntity.getPhoneNumber()) - .level(userEntity.getLevel()) +// .level(userEntity.getLevel()) .build(); } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java b/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java index 0611784..4ae2ee5 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/repository/UserRepository.java @@ -22,12 +22,12 @@ public interface UserRepository extends JpaRepository { @Query("DELETE FROM UserEntity U WHERE U.id = :id") void deleteUser(@Param("id") Long id); - @Modifying - @Transactional - @Query("UPDATE UserEntity u SET " + - "u.level = :level " + - "WHERE u.id = :id") - void changeLv (@Param("id") Long id, @Param("level") Level level); +// @Modifying +// @Transactional +// @Query("UPDATE UserEntity u SET " + +// "u.level = :level " + +// "WHERE u.id = :id") +// void changeLv (@Param("id") Long id, @Param("level") Level level); // @Query("UPDATE BoardEntity b SET " + diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java index 439a526..e4acaa7 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java @@ -59,10 +59,10 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse //Username Token에서 꺼내기 //이를 통해 아래 UsernamePasswordAuthenticationToken에서 userName을 사용가능함. String name = JwtUtil.getUserName(token, secretKey); - Level level = JwtUtil.getLevel(token, secretKey); +// Level level = JwtUtil.getLevel(token, secretKey); log.info("name : {}", name); - log.info("level : {}", level); +// log.info("level : {}", level); // 권한 부여 UsernamePasswordAuthenticationToken authenticationToken = @@ -70,7 +70,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse List.of(new SimpleGrantedAuthority("name"))); // Detail을 넣어줌 authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); - authenticationToken.setDetails(level); +// authenticationToken.setDetails(level); SecurityContextHolder.getContext().setAuthentication(authenticationToken); filterChain.doFilter(request, response); diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java index 7e48dfa..a3bcefe 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java @@ -20,12 +20,12 @@ public static String getUserName(String token, String secretKey) { .getBody().get("name", String.class); } // userName 꺼내오기. - public static Level getLevel(String token, String secretKey) { - return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token) - .getBody().get("level", Level.class); - } // level 꺼내오기 +// public static Level getLevel(String token, String secretKey) { +// return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token) +// .getBody().get("level", Level.class); +// } // level 꺼내오기 - public static String createJwt(String name, String studentId, Level level, String secretKey) { + public static String createJwt(String name, String studentId, /*Level level,*/ String secretKey) { // name : token에 들어있는 것으로 사용함 // secretKey : 서명 @@ -34,7 +34,7 @@ public static String createJwt(String name, String studentId, Level level, Strin claims.put("name", name); claims.put("studentId", studentId); - claims.put("level", level); +// claims.put("level", level); Long expiredMs = 1000 * 60 * 60l; diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java b/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java index 0524e42..b439f74 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java @@ -12,7 +12,7 @@ public class AuthService { @Value("${jwt.secret}") private String secretKey; - public Level extractLevel(String token) { - return JwtUtil.getLevel(token, secretKey); - } +// public Level extractLevel(String token) { +// return JwtUtil.getLevel(token, secretKey); +// } } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java b/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java index c4e5df3..7cd724a 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java @@ -30,7 +30,7 @@ public void userSave(UserDTO userDTO) throws Exception { if(studentId.isPresent()) throw new Exception("This studentId already exist."); - userDTO.setLevel(Level.MANAGER); +// userDTO.setLevel(Level.MANAGER); BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder(); UserEntity userEntity = UserDTO.toUserEntity(userDTO); @@ -48,7 +48,7 @@ public String login(LogInDTO logInDTO){ if(userEntity.isPresent()) { // 학번을 통해 찾은 user의 정보가 존재한다면 if(user.checkPassword(logInDTO.getPassword(), bCryptPasswordEncoder)) { - return JwtUtil.createJwt(user.getName(), user.getStudentId(), user.getLevel(), secretKey); + return JwtUtil.createJwt(user.getName(), user.getStudentId(), /*user.getLevel()*/ secretKey); } else { // password 일치하지 않을 경우 return null; @@ -105,7 +105,7 @@ public Page findUserAllByPage(Pageable request) { public void changeLevel(Long id, Level level) { Optional user = userRepository.findById(id); if(user.isPresent()) { - userRepository.changeLv(user.get().getId(), level); +// userRepository.changeLv(user.get().getId(), level); } } // 회원의 level 변경 diff --git a/JWT/src/main/resources/application.properties b/JWT/src/main/resources/application.properties index 0fa9d7d..170761d 100644 --- a/JWT/src/main/resources/application.properties +++ b/JWT/src/main/resources/application.properties @@ -1,4 +1,4 @@ -server.servlet.context-path=/tgwing.kr +#server.servlet.context-path=/tgwing.kr server.port= 8080 From 9a104ecb2eeb6447700a0e2e4fb8404de525554d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Sat, 16 Mar 2024 21:01:21 +0900 Subject: [PATCH 02/38] Create auto-deployment.yml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 아직 배포 불가 --- .github/workflows/auto-deployment.yml | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 .github/workflows/auto-deployment.yml diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml new file mode 100644 index 0000000..54d1f36 --- /dev/null +++ b/.github/workflows/auto-deployment.yml @@ -0,0 +1,24 @@ +name: docker images deployment + +on: + push: + branches: [ "Dev" ] + pull_request: + branches: [ "Dev" ] + +jobs: + + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Build the Docker image + run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) + - name: Push image to DockerHub + run: docker push ? + - name: Connect to EC2 instance + run: ? + - name: Deploy server + run: ? From f17f3d041205a68497cac4152c204d67fdc33b86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=84=B1=ED=9B=88?= Date: Tue, 19 Mar 2024 21:34:15 +0900 Subject: [PATCH 03/38] error --- .idea/modules.xml | 1 + .idea/modules/JWTLogIn.JWT.main.iml | 8 +++++ JWT/build.gradle | 5 ++++ .../JWT/user/config/SecurityConfig.java | 18 +++++++---- .../JWTLogIn/JWT/user/config/Swagger.java | 30 +++++++++++++++++++ .../JWT/user/controller/AdminController.java | 6 +++- .../JWT/user/controller/UserController.java | 2 +- .../JWTLogIn/JWT/user/security/JwtFilter.java | 5 ++++ .../JWTLogIn/JWT/user/security/JwtUtil.java | 5 ++++ .../JWT/user/service/AuthService.java | 5 ++++ .../JWT/user/service/UserService.java | 3 +- JWT/src/main/resources/application.properties | 2 +- 12 files changed, 80 insertions(+), 10 deletions(-) create mode 100644 .idea/modules/JWTLogIn.JWT.main.iml create mode 100644 JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java diff --git a/.idea/modules.xml b/.idea/modules.xml index 7e7eefc..e21ecee 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -3,6 +3,7 @@ + \ No newline at end of file diff --git a/.idea/modules/JWTLogIn.JWT.main.iml b/.idea/modules/JWTLogIn.JWT.main.iml new file mode 100644 index 0000000..e52f99e --- /dev/null +++ b/.idea/modules/JWTLogIn.JWT.main.iml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/JWT/build.gradle b/JWT/build.gradle index c548493..8a89906 100644 --- a/JWT/build.gradle +++ b/JWT/build.gradle @@ -41,6 +41,11 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-impl:0.11.2' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.2' + // Swagger + implementation 'io.springfox:springfox-boot-starter:3.0.0' + implementation 'io.springfox:springfox-swagger-ui:3.0.0' + implementation 'io.springfox:springfox-swagger2:2.9.2' + // // Spring Security testImplementation 'org.springframework.security:spring-security-test' testImplementation 'org.springframework.boot:spring-boot-starter-test' diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java b/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java index 955d037..2751e34 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java @@ -31,12 +31,18 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .httpBasic(AbstractHttpConfigurer::disable) .csrf(AbstractHttpConfigurer::disable) // 토큰 사용하기에 csrf 불가능 .cors(AbstractHttpConfigurer::disable) - .authorizeHttpRequests(request -> { - request.requestMatchers("/tgwing.kr", "/tgwing.kr/register", "/tgwing.kr/login").permitAll(); - // 3개의 url에서는 token인증없이 접근 가능. - request.anyRequest().authenticated(); - // 그 외의 url에서는 token인증없이 접근 불가능. - }) + .authorizeHttpRequests(request -> request + .requestMatchers("/tgwing.kr", "/tgwing.kr/register", "/tgwing.kr/login", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html", + "/webjars/**", "/swagger-resources/**") + .permitAll() + .anyRequest().authenticated() + ) +// .formLogin((form) -> form +// .loginPage("/tgwing.kr/login") +// .permitAll() +// ) +// .logout((logout) -> logout +// .clearAuthentication(true)) .sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS)) // jwt를 사용하기 때문에 session을 사용하지 않음. .addFilterBefore(new JwtFilter(userService, secretKey), UsernamePasswordAuthenticationFilter.class) diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java b/JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java new file mode 100644 index 0000000..8797333 --- /dev/null +++ b/JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java @@ -0,0 +1,30 @@ +package JWTLogIn.JWT.user.config; + +import org.springframework.context.annotation.Bean; +import springfox.documentation.builders.ApiInfoBuilder; +import springfox.documentation.builders.PathSelectors; +import springfox.documentation.builders.RequestHandlerSelectors; +import springfox.documentation.service.ApiInfo; +import springfox.documentation.spi.DocumentationType; +import springfox.documentation.spring.web.plugins.Docket; + +public class Swagger { + @Bean + public Docket api() { + return new Docket(DocumentationType.OAS_30) + .useDefaultResponseMessages(false) + .select() + .apis(RequestHandlerSelectors.basePackage("JWTLogin.JWT")) + .paths(PathSelectors.any()) + .build() + .apiInfo(apiInfo()); + } + + private ApiInfo apiInfo() { + return new ApiInfoBuilder() + .title("Hello Swagger") + .description("스웨거 기능 테스트") + .version("1.0") + .build(); + } +} \ No newline at end of file diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java b/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java index 36b137f..1d3a41a 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/controller/AdminController.java @@ -23,12 +23,16 @@ public class AdminController { private final AuthService authService; @GetMapping("/info/user") - public ResponseEntity> userAll(Authentication authentication) { + public ResponseEntity> userAll(Authentication authentication, @RequestHeader("authorization") String token) { List userAll = userService.findUserAll(); + String jwt = token.split(" ")[1]; + String studentId = authService.extractStudentId(jwt); if(userAll == null) return ResponseEntity.status(HttpStatus.NOT_FOUND).build(); + System.out.println("studentId = " + studentId); + return ResponseEntity.ok(userAll); } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java b/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java index f330665..e69671d 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/controller/UserController.java @@ -51,7 +51,7 @@ public ResponseEntity logout() { @DeleteMapping("/profile/delete/{id}") public ResponseEntity deleteId(@PathVariable Long id) { - if(userService.withdrawalUser(id)) { + if(userService.deleteUser(id)) { System.out.println("회원 삭제 완료"); return ResponseEntity.ok().build(); } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java index e4acaa7..9b94613 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java @@ -29,6 +29,7 @@ public class JwtFilter extends OncePerRequestFilter { protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { final String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); + log.info("Authorization : {}", authorization); // slf4j에서 log를 찍어서 확인함. @@ -52,6 +53,7 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse if(JwtUtil.isExpired(token, secretKey)) { log.error("토큰이 만료됨."); filterChain.doFilter(request, response); + return; } @@ -60,8 +62,11 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse //이를 통해 아래 UsernamePasswordAuthenticationToken에서 userName을 사용가능함. String name = JwtUtil.getUserName(token, secretKey); // Level level = JwtUtil.getLevel(token, secretKey); + String studentId = JwtUtil.getStudentId(token, secretKey); log.info("name : {}", name); + log.info("studentId : {}", studentId); + // log.info("level : {}", level); // 권한 부여 diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java index a3bcefe..58c70a3 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtUtil.java @@ -20,6 +20,11 @@ public static String getUserName(String token, String secretKey) { .getBody().get("name", String.class); } // userName 꺼내오기. + public static String getStudentId(String token, String secretKey) { + return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token) + .getBody().get("studentId", String.class); + } + // public static Level getLevel(String token, String secretKey) { // return Jwts.parserBuilder().setSigningKey(secretKey).build().parseClaimsJws(token) // .getBody().get("level", Level.class); diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java b/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java index b439f74..d96f98b 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/service/AuthService.java @@ -15,4 +15,9 @@ public class AuthService { // public Level extractLevel(String token) { // return JwtUtil.getLevel(token, secretKey); // } + + public String extractStudentId(String token) { + return JwtUtil.getStudentId(token, secretKey); + } + } diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java b/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java index 7cd724a..3aa91de 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/service/UserService.java @@ -23,6 +23,7 @@ public class UserService { @Value("${jwt.secret}") private String secretKey; + private final UserRepository userRepository; public void userSave(UserDTO userDTO) throws Exception { @@ -60,7 +61,7 @@ public String login(LogInDTO logInDTO){ }// login. null일 경우 회원정보 불일치함. 아닐 경우, 회원정보 일치. 회원 정보 return. - public Boolean withdrawalUser(Long id) { + public Boolean deleteUser(Long id) { Optional find = userRepository.findById(id); if(find != null) { // 회원이 있으면 null이 아님. 이를 삭제하고 true보내서 삭제 완료를 보냄. userRepository.deleteUser(id); diff --git a/JWT/src/main/resources/application.properties b/JWT/src/main/resources/application.properties index 170761d..dd4fe1e 100644 --- a/JWT/src/main/resources/application.properties +++ b/JWT/src/main/resources/application.properties @@ -13,7 +13,7 @@ spring.datasource.password=tgwing spring.jpa.hibernate.naming.implicit-strategy=org.hibernate.boot.model.naming.ImplicitNamingStrategyLegacyJpaImpl spring.jpa.hibernate.naming.physical-strategy=org.hibernate.boot.model.naming.PhysicalNamingStrategyStandardImpl spring.jpa.show-sql=true -spring.jpa.hibernate.ddl-auto=create +spring.jpa.hibernate.ddl-auto=update spring.jpa.open-in-view=false spring.jpa.generate-ddl=true spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect From b9e1588d280f6cae3c77cc99c7476c794be47702 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=86=A1=EC=84=B1=ED=9B=88?= Date: Thu, 21 Mar 2024 23:45:35 +0900 Subject: [PATCH 04/38] =?UTF-8?q?[REFACTOR]=20request=20authorization=20?= =?UTF-8?q?=EB=AC=B8=EC=A0=9C=20=ED=95=B4=EA=B2=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- JWT/build.gradle | 4 +- .../JWT/user/config/SecurityConfig.java | 40 +++++++++- .../JWTLogIn/JWT/user/config/Swagger.java | 30 ------- .../JWTLogIn/JWT/user/security/JwtFilter.java | 79 +++++++++++-------- 4 files changed, 87 insertions(+), 66 deletions(-) delete mode 100644 JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java diff --git a/JWT/build.gradle b/JWT/build.gradle index 8a89906..b84a5c4 100644 --- a/JWT/build.gradle +++ b/JWT/build.gradle @@ -44,7 +44,9 @@ dependencies { // Swagger implementation 'io.springfox:springfox-boot-starter:3.0.0' implementation 'io.springfox:springfox-swagger-ui:3.0.0' - implementation 'io.springfox:springfox-swagger2:2.9.2' +// implementation 'io.springfox:springfox-swagger2:2.9.2' + implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2' + // // Spring Security testImplementation 'org.springframework.security:spring-security-test' diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java b/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java index 2751e34..369c9b5 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/config/SecurityConfig.java @@ -3,11 +3,14 @@ import JWTLogIn.JWT.user.security.JwtFilter; import JWTLogIn.JWT.user.service.UserService; import lombok.RequiredArgsConstructor; +import lombok.extern.log4j.Log4j2; import org.springframework.beans.factory.annotation.Value; +import org.springframework.boot.autoconfigure.security.servlet.PathRequest; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +import org.springframework.security.config.annotation.web.configuration.WebSecurityCustomizer; import org.springframework.security.config.annotation.web.configurers.AbstractHttpConfigurer; import org.springframework.security.config.http.SessionCreationPolicy; import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; @@ -17,6 +20,7 @@ @Configuration @EnableWebSecurity // request를 filterchain에서 가로채도록 하는 장치 @RequiredArgsConstructor +@Log4j2 public class SecurityConfig { private final UserService userService; @@ -24,6 +28,37 @@ public class SecurityConfig { @Value("${jwt.secret}") private String secretKey; + private static final String[] PERMIT_URL_ARRAY = { + /* swagger v2 */ + "/v2/api-docs", + "/swagger-resources", + "/swagger-resources/**", + "/configuration/ui", + "/configuration/security", + "/swagger-ui.html", + "/webjars/**", + /* swagger v3 */ + "/v3/api-docs/**", + "/swagger-ui/**", + "/swagger-ui/swagger-ui-standalone-preset.js", + "/swagger-ui/swagger-initializer.js", + "/swagger-ui/swagger-ui-bundle.js", + "/swagger-ui/swagger-ui.css", + "/swagger-ui/index.css", + "/swagger-ui/favicon-32x32.png", + "/swagger-ui/favicon-16x16.png", + "/api-docs/json/swagger-config", + "/api-docs/json" + }; + + @Bean + public WebSecurityCustomizer webSecurityCustomizer() { + log.info("WebSecurity......................"); + + return web -> web.ignoring() + .requestMatchers(PathRequest.toStaticResources().atCommonLocations()); + } + @Bean // 요청이 들어오면 SecurityFilterChain이 가로채서 인증, 인가를 체크함. public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { @@ -32,8 +67,9 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti .csrf(AbstractHttpConfigurer::disable) // 토큰 사용하기에 csrf 불가능 .cors(AbstractHttpConfigurer::disable) .authorizeHttpRequests(request -> request - .requestMatchers("/tgwing.kr", "/tgwing.kr/register", "/tgwing.kr/login", "/swagger-ui/**", "/v3/api-docs/**", "/swagger-ui.html", - "/webjars/**", "/swagger-resources/**") + .requestMatchers("/tgwing.kr", "/tgwing.kr/register", "/tgwing.kr/login") + .permitAll() + .requestMatchers(PERMIT_URL_ARRAY) .permitAll() .anyRequest().authenticated() ) diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java b/JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java deleted file mode 100644 index 8797333..0000000 --- a/JWT/src/main/java/JWTLogIn/JWT/user/config/Swagger.java +++ /dev/null @@ -1,30 +0,0 @@ -package JWTLogIn.JWT.user.config; - -import org.springframework.context.annotation.Bean; -import springfox.documentation.builders.ApiInfoBuilder; -import springfox.documentation.builders.PathSelectors; -import springfox.documentation.builders.RequestHandlerSelectors; -import springfox.documentation.service.ApiInfo; -import springfox.documentation.spi.DocumentationType; -import springfox.documentation.spring.web.plugins.Docket; - -public class Swagger { - @Bean - public Docket api() { - return new Docket(DocumentationType.OAS_30) - .useDefaultResponseMessages(false) - .select() - .apis(RequestHandlerSelectors.basePackage("JWTLogin.JWT")) - .paths(PathSelectors.any()) - .build() - .apiInfo(apiInfo()); - } - - private ApiInfo apiInfo() { - return new ApiInfoBuilder() - .title("Hello Swagger") - .description("스웨거 기능 테스트") - .version("1.0") - .build(); - } -} \ No newline at end of file diff --git a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java index 9b94613..b6d22de 100644 --- a/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java +++ b/JWT/src/main/java/JWTLogIn/JWT/user/security/JwtFilter.java @@ -16,6 +16,7 @@ import org.springframework.web.filter.OncePerRequestFilter; import java.io.IOException; +import java.util.Arrays; import java.util.List; @RequiredArgsConstructor @@ -25,59 +26,71 @@ public class JwtFilter extends OncePerRequestFilter { private final UserService userService; private final String secretKey; + @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { final String authorization = request.getHeader(HttpHeaders.AUTHORIZATION); - log.info("Authorization : {}", authorization); - // slf4j에서 log를 찍어서 확인함. + log.info("doFilterChain....................."); - if(authorization.isEmpty() || !authorization.startsWith("Bearer ")) { - log.error("권한이 없음."); + if(authorization != null && !authorization.isEmpty()) { + log.info("Authorization : {}", authorization); + // slf4j에서 log를 찍어서 확인함. - filterChain.doFilter(request, response); - return; - } - // authentication이 없을 경우, token이 없을 경우, 혹은 "Bearer "로 시작하지 않으면 block함. - // 이 때 header의 authorization의 부분에서 어떤 입력이라도 있으면 200이 됨. + if(authorization.isEmpty() || !authorization.startsWith("Bearer ")) { + log.error("권한이 없음."); + filterChain.doFilter(request, response); + return; + } + // authentication이 없을 경우, token이 없을 경우, 혹은 "Bearer "로 시작하지 않으면 block함. + // 이 때 header의 authorization의 부분에서 어떤 입력이라도 있으면 200이 됨. - String token = authorization.split(" ")[1]; - // 토큰 꺼내기 - // authorization의 첫번째 부분이 토큰이다. - // 띄워쓰기를 쪼개는 방식으로 가져갈 때, Bearer다음의 부분이 토큰이다. - // 토큰 유효기간 확인 - if(JwtUtil.isExpired(token, secretKey)) { - log.error("토큰이 만료됨."); - filterChain.doFilter(request, response); + String token = authorization.split(" ")[1]; + // 토큰 꺼내기 + // authorization의 첫번째 부분이 토큰이다. + // 띄워쓰기를 쪼개는 방식으로 가져갈 때, Bearer다음의 부분이 토큰이다. - return; - } + // 토큰 유효기간 확인 + if(JwtUtil.isExpired(token, secretKey)) { + log.error("토큰이 만료됨."); + filterChain.doFilter(request, response); + + return; + } - //Username Token에서 꺼내기 - //이를 통해 아래 UsernamePasswordAuthenticationToken에서 userName을 사용가능함. - String name = JwtUtil.getUserName(token, secretKey); + //Username Token에서 꺼내기 + //이를 통해 아래 UsernamePasswordAuthenticationToken에서 userName을 사용가능함. + String name = JwtUtil.getUserName(token, secretKey); // Level level = JwtUtil.getLevel(token, secretKey); - String studentId = JwtUtil.getStudentId(token, secretKey); + String studentId = JwtUtil.getStudentId(token, secretKey); - log.info("name : {}", name); - log.info("studentId : {}", studentId); + log.info("name : {}", name); + log.info("studentId : {}", studentId); // log.info("level : {}", level); - // 권한 부여 - UsernamePasswordAuthenticationToken authenticationToken = - new UsernamePasswordAuthenticationToken(name, null, - List.of(new SimpleGrantedAuthority("name"))); - // Detail을 넣어줌 - authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); + // 권한 부여 + UsernamePasswordAuthenticationToken authenticationToken = + new UsernamePasswordAuthenticationToken(name, null, + List.of(new SimpleGrantedAuthority("name"))); + // Detail을 넣어줌 + authenticationToken.setDetails(new WebAuthenticationDetailsSource().buildDetails(request)); // authenticationToken.setDetails(level); - SecurityContextHolder.getContext().setAuthentication(authenticationToken); - filterChain.doFilter(request, response); + SecurityContextHolder.getContext().setAuthentication(authenticationToken); + filterChain.doFilter(request, response); + } + + else { + log.info("authorization null......"); +// if(Arrays.stream(PERMIT_URL_ARRAY).anyMatch(req -> request.getRequestURI().equals(req))) { + filterChain.doFilter(request, response); + + } }// 관문. 이곳을 통과해서 지나감. }// 권한을 부여해줌. 본래 authenticate를 통과해야하는 상태를 통과하게 해줌. From 7ccfc8a3570e593dd3b79267a2dba0114031c392 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 00:43:23 +0900 Subject: [PATCH 05/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 54d1f36..ea76bea 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -14,11 +14,19 @@ jobs: steps: - uses: actions/checkout@v3 - - name: Build the Docker image - run: docker build . --file Dockerfile --tag my-image-name:$(date +%s) - - name: Push image to DockerHub - run: docker push ? - - name: Connect to EC2 instance - run: ? - - name: Deploy server - run: ? + - name: Setup Java JDK + uses: actions/setup-java@v4.2.1 + with: + # The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file + java-version: 17 + # Java distribution. See the list of supported distributions in README file + distribution: temurin + # The package type (jdk, jre, jdk+fx, jre+fx) + java-package: jdk + # The architecture of the package (defaults to the action runner's architecture) + architecture: x64 + cache: gradle + - name: Build Jar + run: | + chmod 755 gradlew + ./gradlew bootJar From 2bb79bb3cce514e3c9d587bf00c20f4e9c2a850f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:22:22 +0900 Subject: [PATCH 06/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index ea76bea..fc5e60b 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -1,10 +1,10 @@ -name: docker images deployment +name: AWS EC2 자동 배포 on: push: - branches: [ "Dev" ] + branches: [ "feature/build" ] pull_request: - branches: [ "Dev" ] + branches: [ "feature/build" ] jobs: From 07301a6ac4c7926996da8f23b12d3c663aa068b8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:23:24 +0900 Subject: [PATCH 07/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index fc5e60b..a4c837b 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -2,9 +2,9 @@ name: AWS EC2 자동 배포 on: push: - branches: [ "feature/build" ] + branches: [ "main" ] pull_request: - branches: [ "feature/build" ] + branches: [ "main" ] jobs: @@ -30,3 +30,4 @@ jobs: run: | chmod 755 gradlew ./gradlew bootJar + ./gradlew jarDir From 2299df62144d68d3b89120c19e8994813771eb99 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:26:57 +0900 Subject: [PATCH 08/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index a4c837b..9482c83 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -13,7 +13,9 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4.1.2 + - name: Show git status + run: git status - name: Setup Java JDK uses: actions/setup-java@v4.2.1 with: From 80c289665ba5b77843e9602bcf086a331063ed6c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:28:30 +0900 Subject: [PATCH 09/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 9482c83..513c9d0 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -30,6 +30,7 @@ jobs: cache: gradle - name: Build Jar run: | + cd JWT chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir From 37bc33c04c73483fa92400c29735edbc9e0fcfeb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:39:52 +0900 Subject: [PATCH 10/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 513c9d0..d3ea607 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -34,3 +34,9 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir + - name: Connect to EC2 + run: | + EC2_HOST={{ secrets.EC2_HOST }} + EC2_USERNAME={{ secrets.EC2_USERNAME }} + echo {{ secrets.EC2_PRIVATE_KEY }} > private_key.pem + ssh -i private_key.pem "${EC2_USERNAME}@${EC2_HOST}" echo hello From 36486094667389c502452f725e5178a12d98bf78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:43:29 +0900 Subject: [PATCH 11/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index d3ea607..b623c3d 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -35,8 +35,10 @@ jobs: ./gradlew bootJar ./gradlew jarDir - name: Connect to EC2 + env: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | - EC2_HOST={{ secrets.EC2_HOST }} - EC2_USERNAME={{ secrets.EC2_USERNAME }} - echo {{ secrets.EC2_PRIVATE_KEY }} > private_key.pem - ssh -i private_key.pem "${EC2_USERNAME}@${EC2_HOST}" echo hello + echo $private_key > private_key.pem + ssh -i private_key.pem "${username}@${host}" echo hello From 30478b42ecfd0425376d4ed3d85678a0e7f7213d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:48:24 +0900 Subject: [PATCH 12/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index b623c3d..24d80eb 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -41,4 +41,4 @@ jobs: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo $private_key > private_key.pem - ssh -i private_key.pem "${username}@${host}" echo hello + ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello From 0c33ad402c734987dd26ea695b66e2bda76674a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:49:33 +0900 Subject: [PATCH 13/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 24d80eb..754c995 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -41,4 +41,5 @@ jobs: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo $private_key > private_key.pem + chmod 400 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello From 3edea330b096a58d3fa81b3670fd8ed01e4bd610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:50:54 +0900 Subject: [PATCH 14/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 754c995..4036b13 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -41,5 +41,5 @@ jobs: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo $private_key > private_key.pem - chmod 400 private_key.pem + chmod 444 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello From 47cdc9f5f5bb2657f24453f72af515cfadd3297c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:52:13 +0900 Subject: [PATCH 15/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 4036b13..d9692f4 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -41,5 +41,5 @@ jobs: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo $private_key > private_key.pem - chmod 444 private_key.pem + chmod 440 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello From e8de2af6b9b0641236eae0b9e7406f6d341d4130 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:53:40 +0900 Subject: [PATCH 16/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index d9692f4..49d3fb2 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -13,6 +13,15 @@ jobs: runs-on: ubuntu-latest steps: + - name: Connect to EC2 + env: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + private_key: ${{ secrets.EC2_PRIVATE_KEY }} + run: | + echo $private_key > private_key.pem + chmod 400 private_key.pem + ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello - uses: actions/checkout@v4.1.2 - name: Show git status run: git status @@ -34,12 +43,3 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir - - name: Connect to EC2 - env: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - private_key: ${{ secrets.EC2_PRIVATE_KEY }} - run: | - echo $private_key > private_key.pem - chmod 440 private_key.pem - ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello From c52cc62adc2c6580af7771c421853a6ceec1e622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:55:06 +0900 Subject: [PATCH 17/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 49d3fb2..17851f3 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -20,7 +20,7 @@ jobs: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo $private_key > private_key.pem - chmod 400 private_key.pem + chmod 600 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello - uses: actions/checkout@v4.1.2 - name: Show git status From 309fd4e07523471168f27d4231e2c0e35f3338e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 01:59:36 +0900 Subject: [PATCH 18/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 17851f3..84f0048 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -19,8 +19,8 @@ jobs: username: ${{ secrets.EC2_USERNAME }} private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | - echo $private_key > private_key.pem - chmod 600 private_key.pem + echo "$private_key" > private_key.pem + chmod 400 private_key.pem ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello - uses: actions/checkout@v4.1.2 - name: Show git status From 008bb07f75fd012e7e827e966c8e4f98d6447896 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 03:21:20 +0900 Subject: [PATCH 19/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 84f0048..3c77bcd 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -13,15 +13,6 @@ jobs: runs-on: ubuntu-latest steps: - - name: Connect to EC2 - env: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - private_key: ${{ secrets.EC2_PRIVATE_KEY }} - run: | - echo "$private_key" > private_key.pem - chmod 400 private_key.pem - ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello - uses: actions/checkout@v4.1.2 - name: Show git status run: git status @@ -43,3 +34,14 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir + - name: Connect to EC2 + env: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + private_key: ${{ secrets.EC2_PRIVATE_KEY }} + run: | + echo "$private_key" > private_key.pem + chmod 400 private_key.pem + ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello + - name: Env Test + run: echo $host From 13f6ced14ffd4ccd48ad2db86979baf34f28c26e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 03:22:55 +0900 Subject: [PATCH 20/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 3c77bcd..76e5746 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -12,6 +12,11 @@ jobs: runs-on: ubuntu-latest + env: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + private_key: ${{ secrets.EC2_PRIVATE_KEY }} + steps: - uses: actions/checkout@v4.1.2 - name: Show git status @@ -35,10 +40,6 @@ jobs: ./gradlew bootJar ./gradlew jarDir - name: Connect to EC2 - env: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo "$private_key" > private_key.pem chmod 400 private_key.pem From dd655fae0e79e5316f8c70cb4d0a8f34dd23eae4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 03:40:58 +0900 Subject: [PATCH 21/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 76e5746..5afacca 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -15,7 +15,6 @@ jobs: env: host: ${{ secrets.EC2_HOST }} username: ${{ secrets.EC2_USERNAME }} - private_key: ${{ secrets.EC2_PRIVATE_KEY }} steps: - uses: actions/checkout@v4.1.2 @@ -39,10 +38,20 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir - - name: Connect to EC2 + - name: Prepare SSH private key + env: + private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo "$private_key" > private_key.pem chmod 400 private_key.pem - ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" echo hello - - name: Env Test - run: echo $host + - name: Kill current running Spring process + run: ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" 'kill $(sudo lsof -t -i :8080)' + - name: Send jar file to EC2 + run: | + jarPath=$(./gradlew -q jarPath) + scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" + scp -i private_key.pem "deployment/runner.sh" "${username}@${host}:~/runner.sh" + - name: Run new uploaded jar + run: | + sudo chmod 755 runner.sh + ./runner.sh server.jar From fb66582620a0f05073742cba0d8f4cc9c95685f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:03:21 +0900 Subject: [PATCH 22/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 5afacca..b6ac48d 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -38,20 +38,30 @@ jobs: chmod 755 gradlew ./gradlew bootJar ./gradlew jarDir - - name: Prepare SSH private key + - name: Prepare SSH connect env: private_key: ${{ secrets.EC2_PRIVATE_KEY }} run: | echo "$private_key" > private_key.pem chmod 400 private_key.pem + eval "$(ssh-agent)" + ssh-add private_key.pem + ssh-keyscan -t rsa $host > ~/.ssh/known_hosts + - name: Upload deployment scripts + run: scp -r deploy "${username}@${host}:~/deploy" - name: Kill current running Spring process - run: ssh -o StrictHostKeyChecking=no -i private_key.pem "${username}@${host}" 'kill $(sudo lsof -t -i :8080)' + run: | + ssh "${username}@${host}" << EOF + sudo chmod 755 deploy/shutdown.sh + ./deploy/shutdown.sh + EOF - name: Send jar file to EC2 run: | jarPath=$(./gradlew -q jarPath) - scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" - scp -i private_key.pem "deployment/runner.sh" "${username}@${host}:~/runner.sh" + scp $jarPath "${username}@${host}:~/server.jar" - name: Run new uploaded jar run: | - sudo chmod 755 runner.sh - ./runner.sh server.jar + ssh "${username}@${host}" << EOF + sudo chmod 755 deploy/runner.sh + ./deploy/runner.sh server.jar + EOF From 2b6889f0fa67881ae89ac91ddfd9edf1d74e3737 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:06:04 +0900 Subject: [PATCH 23/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index b6ac48d..feeeb34 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -37,7 +37,6 @@ jobs: cd JWT chmod 755 gradlew ./gradlew bootJar - ./gradlew jarDir - name: Prepare SSH connect env: private_key: ${{ secrets.EC2_PRIVATE_KEY }} From 6da3e5fa62c82be5b5c14d42830f05b13306ce26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:09:04 +0900 Subject: [PATCH 24/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index feeeb34..c19ecaa 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -45,6 +45,7 @@ jobs: chmod 400 private_key.pem eval "$(ssh-agent)" ssh-add private_key.pem + mkdir ~/.ssh ssh-keyscan -t rsa $host > ~/.ssh/known_hosts - name: Upload deployment scripts run: scp -r deploy "${username}@${host}:~/deploy" From da4c4b5bcce95cf419af1522ce967c132ee7603c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:14:30 +0900 Subject: [PATCH 25/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index c19ecaa..6a79468 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -43,15 +43,13 @@ jobs: run: | echo "$private_key" > private_key.pem chmod 400 private_key.pem - eval "$(ssh-agent)" - ssh-add private_key.pem mkdir ~/.ssh ssh-keyscan -t rsa $host > ~/.ssh/known_hosts - name: Upload deployment scripts - run: scp -r deploy "${username}@${host}:~/deploy" + run: scp -i private_key.pem -r deploy "${username}@${host}:~" - name: Kill current running Spring process run: | - ssh "${username}@${host}" << EOF + ssh -i private_key.pem "${username}@${host}" << EOF sudo chmod 755 deploy/shutdown.sh ./deploy/shutdown.sh EOF @@ -61,7 +59,7 @@ jobs: scp $jarPath "${username}@${host}:~/server.jar" - name: Run new uploaded jar run: | - ssh "${username}@${host}" << EOF + ssh -i private_key.pem "${username}@${host}" << EOF sudo chmod 755 deploy/runner.sh ./deploy/runner.sh server.jar EOF From a0bf08f551d8b4ebdb2ecca8d7a540a92cbaf02c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:21:41 +0900 Subject: [PATCH 26/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 6a79468..9f45a98 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -46,7 +46,9 @@ jobs: mkdir ~/.ssh ssh-keyscan -t rsa $host > ~/.ssh/known_hosts - name: Upload deployment scripts - run: scp -i private_key.pem -r deploy "${username}@${host}:~" + run: | + ls + scp -i private_key.pem -r deploy "${username}@${host}:~" - name: Kill current running Spring process run: | ssh -i private_key.pem "${username}@${host}" << EOF From 812aa180735894832864eb0478358943c19baa4d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:28:03 +0900 Subject: [PATCH 27/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 9f45a98..bf4a8ca 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -34,9 +34,9 @@ jobs: cache: gradle - name: Build Jar run: | - cd JWT chmod 755 gradlew ./gradlew bootJar + working-directory: JWT - name: Prepare SSH connect env: private_key: ${{ secrets.EC2_PRIVATE_KEY }} @@ -45,23 +45,28 @@ jobs: chmod 400 private_key.pem mkdir ~/.ssh ssh-keyscan -t rsa $host > ~/.ssh/known_hosts + working-directory: JWT - name: Upload deployment scripts run: | ls scp -i private_key.pem -r deploy "${username}@${host}:~" + working-directory: JWT - name: Kill current running Spring process run: | ssh -i private_key.pem "${username}@${host}" << EOF sudo chmod 755 deploy/shutdown.sh ./deploy/shutdown.sh EOF + working-directory: JWT - name: Send jar file to EC2 run: | jarPath=$(./gradlew -q jarPath) scp $jarPath "${username}@${host}:~/server.jar" + working-directory: JWT - name: Run new uploaded jar run: | ssh -i private_key.pem "${username}@${host}" << EOF sudo chmod 755 deploy/runner.sh ./deploy/runner.sh server.jar EOF + working-directory: JWT From afeb66da6667d29f8386b7e7ec1270fc7680fff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 04:35:53 +0900 Subject: [PATCH 28/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index bf4a8ca..3f4a53e 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -53,20 +53,18 @@ jobs: working-directory: JWT - name: Kill current running Spring process run: | - ssh -i private_key.pem "${username}@${host}" << EOF + ssh -i private_key.pem "${username}@${host}" sudo chmod 755 deploy/shutdown.sh ./deploy/shutdown.sh - EOF working-directory: JWT - name: Send jar file to EC2 run: | jarPath=$(./gradlew -q jarPath) - scp $jarPath "${username}@${host}:~/server.jar" + scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" working-directory: JWT - name: Run new uploaded jar run: | - ssh -i private_key.pem "${username}@${host}" << EOF + ssh -i private_key.pem "${username}@${host}" sudo chmod 755 deploy/runner.sh ./deploy/runner.sh server.jar - EOF working-directory: JWT From d536f81db1fd9caedbda2c77efec40260c1691b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:07:09 +0900 Subject: [PATCH 29/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 3f4a53e..091a297 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -48,14 +48,14 @@ jobs: working-directory: JWT - name: Upload deployment scripts run: | - ls scp -i private_key.pem -r deploy "${username}@${host}:~" + sudo chmod 755 deploy/* working-directory: JWT - name: Kill current running Spring process run: | ssh -i private_key.pem "${username}@${host}" - sudo chmod 755 deploy/shutdown.sh ./deploy/shutdown.sh + ./deploy/backup.sh working-directory: JWT - name: Send jar file to EC2 run: | @@ -65,6 +65,5 @@ jobs: - name: Run new uploaded jar run: | ssh -i private_key.pem "${username}@${host}" - sudo chmod 755 deploy/runner.sh - ./deploy/runner.sh server.jar + ./deploy/startup.sh server.jar working-directory: JWT From 501b90e17be535cbf15345a0eac6fc8e30c4c007 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:18:50 +0900 Subject: [PATCH 30/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 091a297..6662281 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -54,8 +54,8 @@ jobs: - name: Kill current running Spring process run: | ssh -i private_key.pem "${username}@${host}" - ./deploy/shutdown.sh - ./deploy/backup.sh + deploy/shutdown.sh + deploy/backup.sh working-directory: JWT - name: Send jar file to EC2 run: | @@ -65,5 +65,5 @@ jobs: - name: Run new uploaded jar run: | ssh -i private_key.pem "${username}@${host}" - ./deploy/startup.sh server.jar + deploy/startup.sh working-directory: JWT From 87fdd9304e3d8231ec280a10aec7f78d793491a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:40:46 +0900 Subject: [PATCH 31/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 35 +++++++++++++++++++-------- 1 file changed, 25 insertions(+), 10 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 6662281..5bcc46f 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -18,8 +18,10 @@ jobs: steps: - uses: actions/checkout@v4.1.2 + - name: Show git status run: git status + - name: Setup Java JDK uses: actions/setup-java@v4.2.1 with: @@ -32,11 +34,13 @@ jobs: # The architecture of the package (defaults to the action runner's architecture) architecture: x64 cache: gradle + - name: Build Jar run: | chmod 755 gradlew ./gradlew bootJar working-directory: JWT + - name: Prepare SSH connect env: private_key: ${{ secrets.EC2_PRIVATE_KEY }} @@ -46,24 +50,35 @@ jobs: mkdir ~/.ssh ssh-keyscan -t rsa $host > ~/.ssh/known_hosts working-directory: JWT + - name: Upload deployment scripts run: | scp -i private_key.pem -r deploy "${username}@${host}:~" - sudo chmod 755 deploy/* working-directory: JWT + - name: Kill current running Spring process - run: | - ssh -i private_key.pem "${username}@${host}" - deploy/shutdown.sh - deploy/backup.sh - working-directory: JWT + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + script: | + sudo chmod 755 deploy/* + deploy/shutdown.sh + deploy/backup.sh + - name: Send jar file to EC2 run: | jarPath=$(./gradlew -q jarPath) scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" working-directory: JWT + - name: Run new uploaded jar - run: | - ssh -i private_key.pem "${username}@${host}" - deploy/startup.sh - working-directory: JWT + uses: appleboy/ssh-action@v1.0.3 + with: + host: ${{ secrets.EC2_HOST }} + username: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }} + script: | + sudo chmod 755 deploy/* + deploy/startup.sh From 6ca1dab53130b104783f666db8ac10bde2bdfc08 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:46:21 +0900 Subject: [PATCH 32/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 5bcc46f..0841493 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -63,6 +63,7 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | + ls sudo chmod 755 deploy/* deploy/shutdown.sh deploy/backup.sh @@ -80,5 +81,6 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | + ls sudo chmod 755 deploy/* deploy/startup.sh From 1def72413d52d3c3c091df20cf387c0b092fe590 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:49:47 +0900 Subject: [PATCH 33/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 0841493..5ebf632 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -63,7 +63,7 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | - ls + java --version sudo chmod 755 deploy/* deploy/shutdown.sh deploy/backup.sh From 1c3935ff37343b0ce87d29c8b949c89708bffc52 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:51:27 +0900 Subject: [PATCH 34/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 5ebf632..c0c6d81 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -63,7 +63,8 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | - java --version + echo $JAVA_HOME + echo $PATH sudo chmod 755 deploy/* deploy/shutdown.sh deploy/backup.sh From 32ab4e6fcb9ea9f4020360fcaa9faefd54847b2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:53:37 +0900 Subject: [PATCH 35/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index c0c6d81..520eb95 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -63,6 +63,7 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | + source ~/.bashrc echo $JAVA_HOME echo $PATH sudo chmod 755 deploy/* @@ -82,6 +83,5 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | - ls sudo chmod 755 deploy/* deploy/startup.sh From 92f586aa966e9b49e50d0f5e9f911f461fe937e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 16:56:39 +0900 Subject: [PATCH 36/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 2 -- 1 file changed, 2 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 520eb95..4b40bcb 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -63,9 +63,7 @@ jobs: username: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} script: | - source ~/.bashrc echo $JAVA_HOME - echo $PATH sudo chmod 755 deploy/* deploy/shutdown.sh deploy/backup.sh From 40a7fd08fcf10c906b13c5254592ee75f264028a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:09:37 +0900 Subject: [PATCH 37/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 4b40bcb..8a05114 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -55,6 +55,17 @@ jobs: run: | scp -i private_key.pem -r deploy "${username}@${host}:~" working-directory: JWT + + - name: Remote SSH Commands + uses: fifsky/ssh-action@v0.0.6 + with: + command: | + echo $JAVA_HOME + echo $PATH + java --version + host: ${{ secrets.EC2_HOST }} + user: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }} - name: Kill current running Spring process uses: appleboy/ssh-action@v1.0.3 From 1003d1b5251285f532d4d32316939b285f32b871 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=EC=9D=B4=EC=8A=B9=EA=B7=9C?= <156777781+wwingyou@users.noreply.github.com> Date: Mon, 25 Mar 2024 17:12:51 +0900 Subject: [PATCH 38/38] Update auto-deployment.yml --- .github/workflows/auto-deployment.yml | 36 ++++++++------------------- 1 file changed, 10 insertions(+), 26 deletions(-) diff --git a/.github/workflows/auto-deployment.yml b/.github/workflows/auto-deployment.yml index 8a05114..f61f45b 100644 --- a/.github/workflows/auto-deployment.yml +++ b/.github/workflows/auto-deployment.yml @@ -25,13 +25,9 @@ jobs: - name: Setup Java JDK uses: actions/setup-java@v4.2.1 with: - # The Java version to set up. Takes a whole or semver Java version. See examples of supported syntax in README file java-version: 17 - # Java distribution. See the list of supported distributions in README file distribution: temurin - # The package type (jdk, jre, jdk+fx, jre+fx) java-package: jdk - # The architecture of the package (defaults to the action runner's architecture) architecture: x64 cache: gradle @@ -56,41 +52,29 @@ jobs: scp -i private_key.pem -r deploy "${username}@${host}:~" working-directory: JWT - - name: Remote SSH Commands + - name: Kill current running Spring process uses: fifsky/ssh-action@v0.0.6 with: command: | - echo $JAVA_HOME - echo $PATH - java --version + sudo chmod 755 deploy/* + deploy/shutdown.sh + deploy/backup.sh host: ${{ secrets.EC2_HOST }} user: ${{ secrets.EC2_USERNAME }} key: ${{ secrets.EC2_PRIVATE_KEY }} - - name: Kill current running Spring process - uses: appleboy/ssh-action@v1.0.3 - with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_PRIVATE_KEY }} - script: | - echo $JAVA_HOME - sudo chmod 755 deploy/* - deploy/shutdown.sh - deploy/backup.sh - - name: Send jar file to EC2 run: | jarPath=$(./gradlew -q jarPath) scp -i private_key.pem $jarPath "${username}@${host}:~/server.jar" working-directory: JWT - + - name: Run new uploaded jar - uses: appleboy/ssh-action@v1.0.3 + uses: fifsky/ssh-action@v0.0.6 with: - host: ${{ secrets.EC2_HOST }} - username: ${{ secrets.EC2_USERNAME }} - key: ${{ secrets.EC2_PRIVATE_KEY }} - script: | + command: | sudo chmod 755 deploy/* deploy/startup.sh + host: ${{ secrets.EC2_HOST }} + user: ${{ secrets.EC2_USERNAME }} + key: ${{ secrets.EC2_PRIVATE_KEY }}