JEKINS EC2 Docker Nginx Spring Boot

아래 블로그를 따라 실습해본 CI/CD와 무중단 배포에 대하여 제 삽질을 섞어 정리합니다. 무중단 배포 방식은 Blue/Green 방식을 이용합니다. 잘못된 내용 또는 오타가 있을 수도 있습니다. 혹시 그런게 있다면 코멘트 남겨 주세요!

코프링 CI/CD 무중단 배포 (with jenkins,docker,nginx)


필요한 것들


백엔드 어플리케이션 작성

Spring Boot 2.6.9 Java 17 Gradle 7.4.1 actuator

무중단 배포를 위해 아래와 같이 application.yml과 ProfileController를 작성해줍니다. ProfileController는 현재 어떤 어플리케이션이 사용되고 있는지 알려주는 역할을 합니다.

application.yml

spring:
  config:
    activate:
      on-profile: set1
server:
  port: 8081
---
spring:
  config:
    activate:
      on-profile: set2
server:
  port: 8082

ProfileController.java

@RestController
@RequiredArgsConstructor
public class ProfileController {
  private final Environment environment;

  @GetMapping("/profile")
  public String getProfile() {
    return Arrays.stream(environment.getActiveProfiles()).findFirst().orElse("");
  }
}