๋ฐ˜์‘ํ˜•
์„ค๋ช…

์„œ๋ฒ„์—์„œ ํด๋ผ์ด์–ธํŠธ๋กœ ๋ฐ์ดํ„ฐ๋ฅผ ์ˆ˜์‹ ํ•˜๋Š” ๋ฐฉ๋ฒ• (๋‹จ๋ฐฉํ–ฅ ํ†ต์‹ )
WebSocket ์˜ ๊ฒฝ์šฐ, ์„œ๋ฒ„ <-> ํด๋ผ์ด์–ธํŠธ ๊ฐ„ ์–‘๋ฐฉํ–ฅ ํ†ต์‹ ์„ ํ•˜์ง€๋งŒ, SSE ์˜ ๊ฒฝ์šฐ ๋‹จ๋ฐฉํ–ฅ ํ†ต์‹ ์„ ํ•จ!
๋”ฐ๋ผ์„œ ๊ฐ„๋‹จํ•œ ์•Œ๋ฆผ ์ „์†ก ๊ธฐ๋Šฅ ๊ฐœ๋ฐœ๋“ฑ์— ์ ํ•ฉํ•œ ๊ธฐ์ˆ 

 

๊ตฌํ˜„ ์˜ˆ์ œ 
// server-side

// case1) SseEmitter ์ด์šฉ
// https://tecoble.techcourse.co.kr/post/2022-10-11-server-sent-events/ ์ฐธ๊ณ  


// case2) WebFlux ์ด์šฉ 
// ...
@GetMapping(value = "/sse", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<String> sse() {
    return Flux.just("Server time: " + LocalDateTime.now())
            .doFinally(signalType -> {
                if (signalType == SignalType.CANCEL || signalType == SignalType.ON_COMPLETE) {
                    log.info("Closing SSE connection");
                }
            });

    ..
}
<!-- client-side --> 
<!-- server-side ์˜ case2) ๋ฐฉ์‹ ๋Œ€์‘ --> 

<!DOCTYPE html>
<html>
<head>
  <meta charset="UTF-8">
  <title>SSE TEST</title>
</head>
<body>
<h1>SSE TEST</h1>
<div id="sse-data"></div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>

  const eventSource = new EventSource("{server-side์ฃผ์†Œ}/sse");
  eventSource.onmessage = event => {
     $("#sse-data").append(event.data); // ์ด๋ถ€๋ถ„์„ ํ† ์ŠคํŠธ ํŒ์—… ํ˜•ํƒœ๋กœ ํ‘œํ˜„ํ•˜๋ฉด ๋จ!
  };

  eventSource.onerror = error => {
    console.error("SSE error:", error);
    eventSource.close();
  };
</script>
</body>
</html>
๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > etc' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

Vault  (1) 2023.02.07
ํ—ฅ์‚ฌ๊ณ ๋‚  ์•„ํ‚คํ…์ฒ˜ (Hexagonal Architecture)  (2) 2022.09.25
JWT (JSON WEB TOKEN)  (0) 2021.12.22
Rest API  (0) 2021.06.02
HTTP๊ด€๋ จ (https, spdy, ajax, websocket)  (0) 2018.12.09
๋ฐ˜์‘ํ˜•

โญ๏ธ ์ด์Šˆ์ƒํ™ฉ) WebClient ์œผ๋กœ API ํ†ต์‹ ์„ ํ•˜๋Š” ์ƒํ™ฉ์— ๊ฒฐ๊ณผ๊ฐ’์ด ๋ฌด๋ถ„๋ณ„ํ•˜๊ฒŒ ํ˜ธ์ถœ๋˜๋Š” ์ƒํ™ฉ์ด ๋ฐœ์ƒํ•จ
- ์˜ˆ๋ฅผ๋“ค๋ฉด API ํ†ต์‹ ์„ ์œ„ํ•ด webclient ์„ 1๋ฒˆ ํ˜ธ์ถœ → N ๋ฒˆ์˜ ํ˜ธ์ถœ ๊ฒฐ๊ณผ๋กœ ๋…ธ์ถœ์ด ๋œ ์ƒํ™ฉ (โ‰๏ธ)

↓↓↓ ์•„๋ž˜๋Š” ์ž˜๋ชป ๋งŒ๋“  JAVA ์ฝ”๋“œ์˜ ์ผ๋ถ€์ž„.
WebClient ์„ ์ž˜ ๋ชจ๋ฅด๊ณ ! Non-blocking/Asynchronous ์˜ ํŠน์„ฑ์„ ์ƒ๊ฐ ๋ชปํ•˜๊ณ ! subscribe, block ์„ ๋ฌด๋ถ„๋ณ„ํ•˜๊ฒŒ ํ˜ธ์ถœํ•œ ์ƒํ™ฉ (ใ… ใ… )

// 1) testmethod ๋Š” API ํ†ต์‹  ๋ฉ”์†Œ๋“œ ์˜ ์ผ๋ถ€ 
public Mono<dto> testmethod() { 
    Mono<dto> test = WebClient.builder()..build().post().exchangeMono()..;
    return test;
}


// 2) testmethod ์„ ํ˜ธ์ถœํ•œ ์˜์—ญ 
...
Mono<dto> dto = testmethod();

dto.subscribe(res -> {…}, error -> {…});
dto.subscribe(res -> {…}, error -> {…});
dto.block();
dto.block();
dto.block();

// ์ด ๊ฒฐ๊ณผ testmethod()์€ 1๋ฒˆ ํ˜ธ์ถœํ•˜์˜€์œผ๋‚˜ ๊ทธ์— ๋”ฐ๋ฅธ ๊ฒฐ๊ณผ๋Š” 5๋ฒˆ์œผ๋กœ ํ˜ธ์ถœ๋œ ์ƒํ™ฉ. Non-blocking...async..์˜ ์ƒํ™ฉ...

 

โ“โ“โ“โ“์™œโ“โ“โ“โ“

dto.block() ์˜ ๊ฒฝ์šฐ, mono ๊ตฌ๋… ํ›„ ์‘๋‹ต์ด ์˜ฌ๋•Œ๊นŒ์ง€ ๊ธฐ๋‹ค๋ฆผ! 
๊ทธ ์‚ฌ์ด, dto.block() ์„ ๋˜ ์„ ์–ธ์„? ํ•˜์˜€๋‹ค๋ฉด ์Šค๋ ˆ๋“œ๊ฐ€ 2๊ฐœ๊ฐ€ ์‹คํ–‰๋˜๋Š” ์ƒํ™ฉ์ด ๋˜๋ฒ„๋ฆฌ๋Š”๊ฒƒ? 

dto.subscribe(res...) ์˜ ๊ฒฝ์šฐ๋„ ์—ฌ๋Ÿฌ๊ฐœ๊ฐ€ ์„ ์–ธ๋˜๋ฉด ๊ฐ๊ฐ subscribe ๋‚ด์—์„œ ์ฒ˜๋ฆฌ๊ฐ€ ๋๋‚จ. = (๋น„๋™๊ธฐ ์ฒ˜๋ฆฌ - ํ•จ์ˆ˜ํ˜•) x ์—ฌ๋Ÿฌ๊ฐœ = ์ฝœ๋ฐฑ๋Š‘๋‚Œ

 
 
๊ทธ๋Ÿฌ๋ฏ€๋กœ ๋น„๋™๊ธฐ ํŠน์„ฑ์„ ์ž˜ ์ดํ•ดํ•˜์—ฌ ๋กœ์ง์„ ๊ตฌํ˜„ํ•ด์•ผํ•จ.

โ—๏ธsubscribe, block ์„ ๊ฐ™์ด ํ˜น์€ ์—ฌ๋Ÿฌ๊ฐœ!!!!! ์„ ์–ธํ•˜์ง€ ์•Š๋„๋ก ํ•˜๊ธฐ (๋ฌด๋ถ„๋ณ„ํ•˜๊ฒŒ ํ˜ธ์ถœํ•ด์•ผํ•˜๋Š” ์ƒํ™ฉ์ด๋ผ๋ฉด ๋ชจ๋ฅผ๊นŒ)
โ—๏ธsubscribe (ํ•จ์ˆ˜ํ˜•?)์œผ๋กœ ๋ฐ›์•˜๋‹ค๋ฉด ์ ˆ์ฐจ์ง€ํ–ฅํ˜•์˜ ํ”„๋กœ์„ธ์Šค์™€๋Š” ์ƒ๊ด€์—†์ด subscribe ๋‚ด์—์„œ ์ฒ˜๋ฆฌํ•ด๋„ ๋˜๋Š”๊ฒƒ์ธ์ง€ ์ž˜ ๊ณ ๋ฏผํ•ด๋ณด๊ธฐ.
(non-blocking ํŠน์„ฑ์„ ํ™œ์šฉํ•˜๊ธฐ ์œ„ํ•ด webclient ์„ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์ด ์•„๋‹Œ๊ฐ€ ์‹ถ์Œ )

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

โœŽ Vault 

API ์„ ์‚ฌ์šฉํ•˜์—ฌ ๋ฏผ๊ฐ์ •๋ณด๋ฅผ ๊ด€๋ฆฌํ•˜๋Š” ์‹œ์Šคํ…œ.

โœฑ ๋ฏผ๊ฐ์ •๋ณด
๋น„๋ฐ€๋ฒˆํ˜ธ, ํ† ํฐ, ์ธ์ฆ์„œ ๋“ฑ์˜ ์•”ํ˜ธํ™” ํ•ด์•ผํ•˜๋Š” ์–ด๋– ํ•œ ๊ฒƒ๋“ค

https://www.vaultproject.io/ ์—์„œ ๊ฐœ๋ฐœํ•จ.

 

โœŽ Vault ์‚ฌ์šฉ ์ด์œ 

ํ”„๋กœ์ ํŠธ ๋‚ด์— ๋ณด์•ˆ์ ์ธ ์š”์†Œ๋ฅผ ๊ณ ๋ คํ•ด์•ผ ํ•˜๋Š” ๊ฐ’(๊ณ„์ • ๋ฐ ํŒจ์Šค์›Œ๋“œ = ๋ฏผ๊ฐ์ •๋ณด ๋“ฑ)๋“ค์„ HTTP API ํ†ต์‹ ์„ ์ด์šฉํ•˜์—ฌ ์™ธ๋ถ€(=git ์ €์žฅ์†Œ ๋“ฑ)์— ๋…ธ์ถœ์‹œํ‚ค์ง€ ์•Š์€ ์ƒํƒœ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ์— ๋ณด์•ˆ์— ํšจ์œจ์ ์ž„.

 

 

โœŽ ๊ฐ„๋‹จํ•˜๊ฒŒ ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ ์—์„œ ์‚ฌ์šฉํ•ด๋ณธ Vault

1. Vault ์„ค์น˜ ๋ฐ ์‹คํ–‰ ํ™•์ธ

$ brew install vault # vault ์„ค์น˜
$ vault server --dev --dev-root-token-id="00000000-0000-0000-0000-000000000000" # vault ์„œ๋ฒ„ ์‹คํ–‰

โ˜ž https://www.vaultproject.io/docs/commands/server ์— ์ž์„ธํ•œ ์„ค๋ช…์ด ์žˆ๋‹ค.

๋Œ€์ถฉ ์ด๋ ‡๊ฒŒ ๋œธ
http://localhost:8200 ์œผ๋กœ ์ ‘์†ํ–ˆ์„ ์‹œ ๋‚˜์˜ค๋Š” ํ™”๋ฉด


โ‰๏ธ ๋งŒ์•ฝ Get "https://127.0.0.1:8200/v1/sys/internal/ui/mounts/secret/application/db": http: server gave HTTP response to HTTPS client ์ด๋Ÿฌํ•œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•˜์˜€์„ ๊ฒฝ์šฐ
↓↓ ์•„๋ž˜๋‚ด์šฉ ์‹คํ–‰ (ํ„ฐ๋ฏธ๋„)

$ export VAULT_ADDR='http://localhost:8200'

 

2. key/vaule ์ƒ์„ฑ ๋ฐ ํ™•์ธ

$ vault kv put secret/application username=mungmang password=12345 # key, vaule ์ƒ์„ฑ

Key                Value
---                -----
created_time       2022-01-08T15:46:25.89734Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1
$ vault kv get secret/application # path ์œผ๋กœ key, vaule ์กฐํšŒ 

======= Metadata =======
Key                Value
---                -----
created_time       2022-01-08T15:46:25.89734Z
custom_metadata    <nil>
deletion_time      n/a
destroyed          false
version            1

====== Data ======
Key         Value
---         -----
password    12345
username    mungmang

โ˜ž https://learn.hashicorp.com/collections/vault/getting-started ์— vault ์‚ฌ์šฉ ๋ฐฉ๋ฒ•์— ๋Œ€ํ•ด ์ž์„ธํžˆ ์„ค๋ช…ํ•ด์ค€๋‹ค.

 

3. SpringBoot project ์— vault ์—ฐ๋™์—ฌ๋ถ€ ์ ์šฉ

// build.gradle ํŒŒ์ผ์— ์•„๋ž˜์˜ ์ •๋ณด ์ถ”๊ฐ€

ext {
    ...
    set('springCloudVersion', "2021.0.1-SNAPSHOT")
}

dependencies {
	...
	implementation 'org.springframework.cloud:spring-cloud-starter-vault-config'
}
    

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}
// application.yml์— ์•„๋ž˜์˜ ๋‚ด์šฉ ์ถ”๊ฐ€
spring:
  config:
    import: vault:// 
  cloud:
    vault:
      uri: http://localhost:8200
      token: 00000000-0000-0000-0000-000000000000
      kv:
        backend: secret
        default-context: application #secret ์ดํ›„์˜ ๊ฒฝ๋กœ

โœฑ ์ฐธ๊ณ ๋กœ Spring Cloude Vault 3.0 ๋ฐ Spring Boot 2.4 ์ด์ƒ์—์„  bootstrap.yml, bootstrap.properties ๊ฐ€ ๋”์ด์ƒ ์‚ฌ์šฉ๋˜์ง€ ์•Š๋Š”๋‹ค๊ณ ํ•จ. ๊ทธ๋ฆฌ๊ณ   Spring Boot Config Data ์ ‘๊ทผ๋ฐฉ์‹์„ ์‚ฌ์šฉํ•˜๋ ค๋ฉด spring: config: import์— Vault ์‹œ์Šคํ…œ์„ ๋ฐ”์ธ๋”ฉ ํ•˜๊ธฐ ์œ„ํ•œ ์†์„ฑ ์„ค์ •์ด ํ•„์š”ํ•จ. (Spring Boot ์˜ Config Data API
์•„๋‹˜, application.yml์— spring:cloud:bootstrap:enabled: true or pom.xml or build.gradle ํŒŒ์ผ์— spring-cloud-starter-bootstrap import์„ ํ•˜์—ฌ bootstrap.yml ์„ ํ™œ์„ฑํ™”๋ฅผ ํ•  ์ˆ˜ ์žˆ์Œ.

โ˜ž https://docs.spring.io/spring-cloud-vault/docs/current/reference/html/#client-side-usage ์— ์ž์„ธํ•œ ์„ค๋ช…์ด ์žˆ๋‹ค.

 

// config ํŒจํ‚ค์ง€ ์ƒ์„ฑํ›„ ์•„๋ž˜์˜ ํด๋ž˜์Šค ์ƒ์„ฑ 

@Getter
@Configuration
public class VaultData {

    @Value("${username}")
    private String username;

    @Value("${password}")
    private String password;
}
// ํ™•์ธ

@Slf4j
@SpringBootApplication
public class HelloApplication {

    public static void main(String[] args) {

        ConfigurableApplicationContext context = SpringApplication.run(HelloApplication.class, args);

        // vault ํ…Œ์ŠคํŠธ --
        VaultData vaultData = context.getBean(VaultData.class);
        log.info("username:{}", vaultData.getUsername());
        log.info("password:{}", vaultData.getPassword());
    }
}

 

 

 

end ~

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > etc' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

SSE (Server Sent Event)  (1) 2023.08.20
ํ—ฅ์‚ฌ๊ณ ๋‚  ์•„ํ‚คํ…์ฒ˜ (Hexagonal Architecture)  (2) 2022.09.25
JWT (JSON WEB TOKEN)  (0) 2021.12.22
Rest API  (0) 2021.06.02
HTTP๊ด€๋ จ (https, spdy, ajax, websocket)  (0) 2018.12.09
๋ฐ˜์‘ํ˜•
์„ค๋ช…

โ€ฃ ํฌํŠธ ์•ค ์–ด๋Œ‘ํ„ฐ ์•„ํ‚คํ…์ฒ˜์„ ์ด์šฉ
โ€ฃ ์™ธ๋ถ€์˜์—ญ & ๋‚ด๋ถ€์˜์—ญ ์„ ๋‚˜๋ˆ  ๊ณ ์ˆ˜์ค€์˜ ๋‚ด๋ถ€ ์˜์—ญ์ด ์™ธ๋ถ€ ์˜์—ญ์— ์˜์กดํ•˜์ง€ ์•Š๋„๋ก ํ•˜๋Š”๊ฒƒ์ด๋‹ค!
โ€ฃ ์œ ์ง€๋ณด์ˆ˜, ์œ ์—ฐ์„ฑ, ํ™•์žฅ์„ฑ์— ์ข‹์Œ.
โ€ฃ ๋ณต์žกํ• ์ˆ˜๋ก ๋น›์„ ๋ฐœํ•˜์ง€๋งŒ, ๋‹จ์ˆœํ•˜๋‹ค๋ฉด ๊ฒฝ์šฐ ์ด๋ ‡๊ฒŒ๊นŒ์ง€ ๊ตฌ์„ฑํ•  ํ•„์š”๋Š” ์—†์Œ!

๐Ÿ”ธ ์™ธ๋ถ€์˜์—ญ
• ๋น„์ง€๋‹ˆ์Šค ์ฒ˜๋ฆฌ ๊ฒฐ๊ณผ ๋ฆฌํ„ด (REST API ๋ฐœํ–‰)
• ์ธ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ, ์•„์›ƒ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ๋กœ ๊ตฌ์„ฑ

๐Ÿ”ธ ๋‚ด๋ถ€์˜์—ญ
• ์ˆœ์ˆ˜ ๋น„์ง€๋‹ˆ์Šค ๋กœ์ง ๊ตฌ์„ฑ
• ์™ธ๋ถ€์˜์—ญ๊ณผ ์—ฐ๊ณ„๋˜๋Š” ํฌํŠธ๋ฅผ ๊ฐ€์ง€๊ณ  ์žˆ์Œ
• ์ธ๋ฐ”์šด๋“œ ํฌํŠธ, ์•„์›ƒ๋ฐ”์šด๋“œ ํฌํŠธ๋กœ ๊ตฌ์„ฑ
• POJO ์กด์žฌ


โ€ฃ ์•„์›ƒ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ๊ฐ€ ์•„์›ƒ๋ฐ”์šด๋“œ ํฌํŠธ์— ์˜์กดํ•ด์„œ ๊ตฌํ˜„๋จ
โ€ฃ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์ด๋‚˜ ์–ด๋Œ‘ํ„ฐ๊ฐ€ ๋ณ€๊ฒฝ ๋˜์–ด๋„ ๋„๋ฉ”์ธ์€ ์˜ํ–ฅ์„ ๋ฐ›์ง€์•Š์Œ
โ€ฃ ํด๋ฆฐ ์•„ํ‚คํ…์ฒ˜์™€๋„ ์œ ์‚ฌ
โ€ฃ SOLID์˜ ๋‹จ์ผ์ฑ…์ž„์›์น™(Single Reason to Change Principle, SRP), ์˜์กด์„ฑ์—ญ์ „์›์น™(Dependency Inversion Principle, DIP) ์„ ์ด์šฉ

โ€ป ํฌํŠธ ์•ค ์–ด๋Œ‘ํ„ฐ ์•„ํ‚คํ…์ฒ˜
์ธํ„ฐํŽ˜์ด์Šค๋‚˜ ๊ธฐ๋ฐ˜ ์š”์†Œ์˜ ๋ณ€๊ฒฝ์— ์˜ํ–ฅ์„ ๋ฐ›์ง€ ์•Š๋Š” ํ•ต์‹ฌ ์ฝ”๋“œ๋ฅผ ๋งŒ๋“ค๊ณ  ์ด๋ฅผ ๊ฒฌ๊ณ ํ•˜๊ฒŒ ๊ด€๋ฆฌํ•˜๋Š”๊ฒƒ์ด ๋ชฉํ‘œ
์™ธ๋ถ€์˜์—ญ๊ณผ ๋‚ด๋ถ€์˜์—ญ์„ ๋ถ„๋ฆฌํ•จ
์˜์—ญ์˜ ์‚ฌ์ด input, ouput ์ „๋‹ฌ์€ ํฌํŠธ(=์ธํ„ฐํŽ˜์ด์Šค) ์„ ํ†ตํ•ด์„œ๋งŒ ํ•จ.
โ€ป ๋‹จ์ผ์ฑ…์ž„์›์น™(Single Reason to Change Principle, SRP)
ํ•˜๋‚˜์˜ ์ปดํฌ๋„ŒํŠธ๋Š” ์˜ค๋กœ์ง€ ํ•œ ๊ฐ€์ง€ ์ผ๋งŒ ํ•ด์•ผํ•˜๊ณ , ๊ทธ๊ฒƒ์„ ์˜ฌ๋ฐ”๋ฅด๊ฒŒ ์ˆ˜ํ–‰ํ•ด์•ผํ•จ! 
= ์ปดํฌ๋„ŒํŠธ ๋ณ€๊ฒฝ ์ด์œ ๋Š” ์˜ค์ง ํ•˜๋‚˜๋ฟ์ด์—ฌ์•ผํ•จ!!!

โ€ป ์˜์กด์„ฑ์—ญ์ „์›์น™(Dependency Inversion Principle, DIP) 
์ฝ”๋“œ์ƒ์˜ ์–ด๋–ค ์˜์กด์„ฑ์ด๋“  ๊ทธ ๋ฐฉํ–ฅ์„ ๋ฐ”๊ฟ€ ์ˆ˜ ์žˆ๋‹ค.

 

๊ตฌ์กฐ

https://engineering-skcc.github.io/microservice%20inner%20achitecture/inner-architecture-2/

 

https://github.com/wikibook/clean-architecture


๐ŸŒฑ 
์ธ๋ฐ”์šด๋“œ ํฌํŠธ
โ–ช๏ธŽ ์ธ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ๊ฐ€ ํ˜ธ์ถœ(์‚ฌ์šฉํ•จ)

๐ŸŒฑ ์•„์›ƒ๋ฐ”์šด๋“œ ํฌํŠธ
โ–ช๏ธŽ ์•„์›ƒ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ๊ฐ€ ์•„์›ƒ๋ฐ”์šด๋“œ ํฌํŠธ์— ์˜์กดํ•˜์—ฌ ๊ตฌํ˜„
(=์•„์›ƒ๋ฐ”์šด๋“œ ํฌํŠธ๊ฐ€ ์•„์›ƒ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ ๊ตฌํ˜„์ฒด ํ˜ธ์ถœ)

๐ŸŒฑ ์ธ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ
โ–ช๏ธŽ ์™ธ๋ถ€์š”์ฒญ ์ฒ˜๋ฆฌ (API ์š”์ฒญ/์‘๋‹ต ๊ฒฐ๊ณผ)
โ–ช๏ธŽ ์•„์›ƒ๋ฐ”์šด๋“œ ํฌํŠธ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๊ฐ€์ ธ๋‹ค๊ฐ€ ์‚ฌ์šฉํ•˜์—ฌ ์–ด๋Œ‘ํ„ฐ๋ฅผ ์ƒ์„ฑ.
โ–ช๏ธŽ ์Šคํ”„๋ง MVC ์ปจํŠธ๋กค๋Ÿฌ, ์ปค๋งจ๋“œ ํ•ธ๋“ค๋Ÿฌ, ์ด๋ฒคํŠธ ๋ฉ”์„ธ์ง€ ๊ตฌ๋… ํ•ธ๋“ค๋Ÿฌ ๋“ฑ.

๐ŸŒฑ ์•„์›ƒ๋ฐ”์šด๋“œ ์–ด๋Œ‘ํ„ฐ
โ–ช๏ธŽ ๋‚ด๋ถ€ ๋น„์ง€๋‹ˆ์Šค ์˜์—ญ๊ณผ ์™ธ๋ถ€ ์„œ๋น„์Šค๊ฐ„ ๋ฐ์ดํ„ฐ ๊ตํ™˜
โ–ช๏ธŽ ๋ฐ์ดํ„ฐ ์—‘์„ธ์Šค ์ฒ˜๋ฆฌ (DAO), ์ด๋ฒคํŠธ ๋ฉ”์„ธ์ง€ ๋ฐœ์ƒ, ์™ธ๋ถ€ ์„œ๋น„์Šค ํ˜ธ์ถœ ๋“ฑ 

 

 

์ด๋ฅผ ์‚ฌ์šฉํ•˜๊ณ„๋œ ๊ณ„๊ธฐ (๊ณ„์ธตํ˜• ์•„ํ‚คํ…์ฒ˜์˜ ๋‹จ์ )

โ€ฃ ๊ณ„์ธตํ˜• ์•„ํ‚คํ…์ฒ˜๋Š” ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค ์ฃผ๋„ ์„ค๊ณ„๋ฅผ ์œ ๋„ํ•จ. (๋„๋ฉ”์ธ์— ์˜์กด์ด ์•„๋‹Œ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์˜์กด) - ๋น„์ง€๋‹ˆ์Šค ๊ด€์ ์œผ๋กœ๋Š” ๋ณ„๋กœ์ž„
โ€ฃ ORM ํ”„๋ ˆ์ž„์›Œํฌ์˜ ๊ฒฝ์šฐ ๊ณ„์ธตํ˜• ์•„ํ‚คํ…์ฒ˜์™€ ๊ฒฐํ•ฉํ•˜๋ฉด ๋น„์ฆˆ๋‹ˆ์Šค ๊ทœ์น™์„ ์˜์†์„ฑ ๊ด€์ ๊ณผ ์„ž๊ณ  ์‹ถ์€ ์œ ํ˜น์„ ์‰ฝ๊ฒŒ ๋ฐ›์Œ.
โ€ฃ ์˜์†์„ฑ ์ฝ”๋“œ๊ฐ€ ๋„๋ฉ”์ธ์ฝ”๋“œ์— ๋…น์•„๋“ค๋ฉด ๋งˆ์Œ๋Œ€๋กœ ๋ฐ”๊พธ๊ธฐ๊ฐ€ ์‰ฝ์ง€ ์•Š๊ฒŒ ๋จ.
โ€ฃ ์›น ๊ณ„์ธต ํ…Œ์ŠคํŠธ์‹œ ๋„๋ฉ”์ธ ๋ฐ ์˜์†์„ฑ ๋ฒ”์œ„๊นŒ์ง€ ๋ชจํ‚นํ•ด์•ผํ•จ. ์‹œ๊ฐ„์†Œ์š”๊ฐ€ ๋งŽ์•„์ง.
โ€ฃ ๊ทธ์™ธ์—๋„ ํ…Œ์ŠคํŠธ๊ฐ€ ์–ด๋ ต๊ณ  ๋™์‹œ์ž‘์—…์ด ์–ด๋ ค์›€.
โ€ฃ ์œ ์ง€๋ณด์ˆ˜ ์‰ฌ์šด! ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ๋งŒ๋“คํ•„์š”์„ฑ์ด ์žˆ๋‹ค.

 

 

 

 


์ฐธ๊ณ 

- ๋งํฌ: https://engineering.linecorp.com/ko/blog/port-and-adapter-architecture/

- ๋งํฌ: https://velog.io/@youngmin-mo/hexagonalarchitecture

- ์ธํ”„๋Ÿฐ๊ฐ•์˜: https://www.inflearn.com/course/%EC%8B%A4%EB%AC%B4-msa-%EC%9D%B4%EC%95%BC%EA%B8%B0/dashboard

- ์ฑ…: ๋งŒ๋“ค๋ฉด์„œ ๋ฐฐ์šฐ๋Š” ํด๋ฆฐ ์•„ํ‚คํ…์ฒ˜

๋ฐ˜์‘ํ˜•

'๊ฐœ๋ฐœ > etc' ์นดํ…Œ๊ณ ๋ฆฌ์˜ ๋‹ค๋ฅธ ๊ธ€

SSE (Server Sent Event)  (1) 2023.08.20
Vault  (1) 2023.02.07
JWT (JSON WEB TOKEN)  (0) 2021.12.22
Rest API  (0) 2021.06.02
HTTP๊ด€๋ จ (https, spdy, ajax, websocket)  (0) 2018.12.09
๋ฐ˜์‘ํ˜•
๋ชฉ์ 

์†Œ์Šค์ฝ”๋“œ๋ฅผ github์— ๋ฐ˜์˜ & Local ์„œ๋ฒ„(Mac OS) ๋‚ด docker ์— ๋ฐฐํฌํ•ด๋ณด๊ธฐ (+dockerHub์—๋„ ๋ฐ˜์˜)
โ€ฃ jenkins pipeline ์ด์šฉ 

 

โญ๏ธ  https://www.youtube.com/watch?v=PKcGy9oPVXg  ์„ ๋ณด๊ณ  ์‹ค์Šตํ•˜๋ฉด์„œ ์ •๋ฆฌํ•ด๋ด„! โญ๏ธ

 

์ž‘์—…์ˆœ์„œ

1๏ธโƒฃ ํ”„๋กœ์ ํŠธ ์…‹ํŒ… ๋ฐ github push

1-1. ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ
โ€ฃ ๋‚˜์˜ ๊ฒฝ์šฐ, spring Initializr or https://start.spring.io์œผ๋กœ ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ 

# DockerFile
FROM openjdk:11
EXPOSE 8081
ADD build/libs/cicd-study.jar cicd-study.jar
ENTRYPOINT ["java", "-jar", "/cicd-study.jar"]



...
# application.yml
server:
  port: 8081
  
  
  
...
@RestController
@SpringBootApplication
public class MainApplication {

	@GetMapping
	public String message() {
		return "HELLO !!!!!!!!!!";
	}
	public static void main(String[] args) {
		SpringApplication.run(MainApplication.class, args);
	}

}

 

 

1-2. github ํ”„๋กœ์ ํŠธ ์ƒ์„ฑ ๋ฐ push

git repository ์ƒ์„ฑ

 

terminal ์— [...or create a new repository on the command line] ์‹คํ–‰

$ git init
$ add .
$ git commit -m "first commit"
$ git branch -M main
$ git remote add origin git@github.com:mumgmangmange/test2.git
$ push -u origin main

๋งŒ์•ฝ, git add . ๊ฐ€ ์•ˆ๋˜๊ฑฐ๋“ , ./gradlew clean ์‹คํ–‰

โ€ป gradle or gradlew ์‚ฌ์šฉ์˜ ์ฐจ์ด?
Wrapper๋Š” ์„ ์–ธ๋œ ๋ฒ„์ „์˜ Gradle์„ ํ˜ธ์ถœํ•˜๊ณ  ํ•„์š”์— ๋”ฐ๋ผ ๋ฏธ๋ฆฌ ๋‹ค์šด๋กœ๋“œํ•˜๋Š” ์Šคํฌ๋ฆฝํŠธ์ด๋‹ค.
์ž‘์—…ํ™˜๊ฒฝ ๋‚ด ๋‹ค๋ฅธ๋ฒ„์ „์˜ gradle์ด ์žˆ๋”๋ผ๋„ ๋”ฐ๋กœ ์„ค์น˜๊ฐ€ ํ•„์š” ์—†์Œ (์‹œ๊ฐ„ ๋ฐ ๋ˆ ์ ˆ์•ฝ ๊ฐ€๋Šฅ)

http://daplus.net/gradle-gradlew%EC%99%80-gradle-%EC%82%AC%EC%9A%A9%EC%9D%98-%EC%B0%A8%EC%9D%B4%EC%A0%90/

 

2๏ธโƒฃ docker ์‹คํ–‰ (์„œ๋ฒ„ ๋‚ด ์—†์œผ๋ฉด ์„ค์น˜ ํ•„์š”)

 

Install Docker Desktop on Mac

 

docs.docker.com

...์นฉ์…‹ ํ™•์ธ (์ธํ…”์นฉ,,๋งฅ์นฉ,,)

์„ค์น˜ ์™„๋ฃŒํ•˜๋ฉด, docker-compose ๋ฐ docker version ์„ค์น˜๋จ

 

3๏ธโƒฃ jenkins ์‹คํ–‰ (์„œ๋ฒ„ ๋‚ด ์—†์œผ๋ฉด ์„ค์น˜ ํ•„์š”)
โ€ฃ ๋‚˜๋Š” brew ์œผ๋กœ ์„ค์น˜ํ•จ
โ€ฃ ๊ทธ๋ฆฌ๊ณ  jenkins ๊ณ„์ •์ƒ์„ฑ ๊ด€๋ จ → ํ•ด๋‹น ๋งํฌ ๋‚ด 2-5 ํ™•์ธ 

-- jenkins ์„ค์น˜
$ brew install jenkins 

-- jenkins ์‹คํ–‰
$ brew services start jenkins

 

 

4๏ธโƒฃ jenkins ํ”„๋กœ์ ํŠธ ์…‹ํŒ… ๋ฐ ๋ฐฐํฌํ™˜๊ฒฝ ์„ค์ • 

ํŒŒ์ดํ”„๋ผ์ธ ์Šคํฌ๋ฆฝํŠธ ๋‚ด์šฉ

pipeline {
    agent any
    stages { 
        stage('Build Gradle') { // github ์˜ ์†Œ์ŠคํŒŒ์ผ ๋ถˆ๋Ÿฌ์˜ค๊ณ , build clean ๋ฐ build
            steps {
                checkout([$class: 'GitSCM', branches: [[name: '*/main']], extensions: [], userRemoteConfigs: [[url: 'git@github.com:xxxxx/xxx.git']]])
                sh './gradlew clean build'
            }
        }
        stage('Build docker image') { // ๋„์ปค ์ด๋ฏธ์ง€ ๋นŒ๋“œ 
            steps {
                // withEnv ๋ธ”๋ก ๋‚ด ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ • ๊ฐ€๋Šฅํ•˜๋„๋ก ํ•จ 
                withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin']) {
                    sh 'docker rmi -f ๋„์ปค์ด๋ฏธ์ง€๋ช…[:TAG]'
                    sh 'docker build -t ๋„์ปค์ด๋ฏธ์ง€๋ช…[:TAG] .'
                }
            }
        }
        stage('Push image to Hub') { // docker hub ์— image ํ‘ธ์‹œ 
            steps {
                withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin']) { // /usr/local/bin ์‚ฌ์šฉ ์œ„ํ•ด withEnv ์‚ฌ์šฉ 
                    withCredentials([string(credentialsId: 'docker๊ณ„์ •๋ช…', variable: 'dockerpwd')]) {
                        sh 'docker login -u ๋„์ปค๊ณ„์ •์•„์ด๋”” -p ${dockerpwd}'
                    }
                    sh 'docker push [OPTIONS] ๋„์ปค์ด๋ฏธ์ง€๋ช…[:TAG]'
                }
            }
        }
        stage('Image Execute') { // ์ด๋ฏธ์ง€ ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰ 
            steps {
                withEnv(['PATH+EXTRA=/usr/sbin:/usr/bin:/sbin:/bin:/usr/local/bin']) {
                        sh '''docker run --name cicd-study \
    -v //var/run/docker.sock:/var/run/docker.sock  \
    --privileged \
    -p 8081:8081 \
    -d \
     ๋„์ปค์ด๋ฏธ์ง€๋ช…[:TAG]'''
                }
            }
        }
    }
}

 

 

 

 

โ—๏ธโ—๏ธ dockerHub ์—…๋กœ๋“œ ์ƒ๋žตํ•˜๋ ค๋ฉด ํŒŒ์ดํ”„๋ผ์ธ ์†Œ์Šค ๊ด€๋ จ ์ฃผ์„์ฒ˜๋ฆฌํ•ด๋„๋ ๋“ฏ!
๊ทธ๋ ‡์ง€ ์•Š๋‹ค๋ฉด, 
https://hub.docker.com/settings/security?generateToken=true ์ ‘์† ๋ฐ accessToken ์ƒ์„ฑํ•ด๋‘๊ณ , jenkins credentials ์— ๋“ฑ๋ก

https://hub.docker.com/settings/security?generateToken=true
http://jenkins์ฃผ์†Œ/credentials/store/system/domain/_/newCredentials ์ ‘์† ๋ฐ secret ์— accessToken ๋“ฑ๋ก

 

 

5๏ธโƒฃ ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌ ์„ฑ๊ณต 

jenkins

 

docker container

 

docker hub
๋„์ปค ์ปจํ…Œ์ด๋„ˆ ๋‚ด ๋ฐฐํฌ ์ ์šฉ ๊ฑด ํ˜ธ์ถœ (port 8081 ์œผ๋กœ)

 

 


์ฐธ๊ณ 

https://bcp0109.tistory.com/352

https://chinsun9.github.io/2020/10/22/denied-requested-access-to-the-resource-is-denied/

https://i5i5.tistory.com/527

https://www.inflearn.com/questions/229989

https://m.blog.naver.com/wideeyed/221533279838

https://unix.stackexchange.com/questions/4186/what-is-usr-local-bin

https://m.blog.naver.com/PostView.naver?isHttpsRedirect=true&blogId=special9486&logNo=220274932377

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

Guest OS ์œ ๋ฌด์˜ ์ฐจ์ด๊ฐ€ ์กด์žฌํ•จ.

 

VM(Virtual machine)

โ–ช๏ธŽ ํ•˜์ดํผ๋ฐ”์ด์ €(hypervisor)๋ผ๋Š” ์†Œํ”„ํŠธ์›จ์–ด๋ฅผ ์ด์šฉํ•ด ํ•˜๋‚˜์˜ ์‹œ์Šคํ…œ์—์„œ ์—ฌ๋Ÿฌ๊ฐœ์˜ ์šด์˜์ฒด์ œ๋ฅผ ์‚ฌ์šฉ
โ–ช๏ธŽ ๊ฒŒ์ŠคํŠธ os์„ ๊ด€๋ฆฌ๋กœ ์ธํ•œ ์˜ค๋ฒ„ํ—ค๋“œ ๋ฐœ์ƒ, ์ด๋ฏธ์ง€๋„ ํผ
โ–ช๏ธŽ ๋ฐฐํฌ์†๋„ ๋ฐ ๋ถ€ํŒ…์†๋„ ๋Š๋ฆผ

 

Container

โ–ช๏ธŽ ํ•˜์ดํผ๋ฐ”์ด์ €(hypervisor) ์—†์ด ์ปจํ…Œ์ด๋„ˆ ์—”์ง„์„ ์‚ฌ์šฉํ•ด ๊ฐ€์ƒ์˜ ๊ฒฉ๋ฆฌ๋œ ๊ณต๊ฐ„์„ ์ƒ์„ฑ
โ–ช๏ธŽ ํ˜ธ์ŠคํŠธ์˜ ์ปค๋„ ๊ณต์œ ํ•จ 
โ–ช๏ธŽ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ์‹คํ–‰ ์œ„ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ & ์‹คํ–‰ํŒŒ์ผ๋งŒ ์กด์žฌ
โ–ช๏ธŽ ์šฉ๋Ÿ‰ ์ ๊ณ , ์ปค๋„์„ ํฌํ•จํ•˜์ง€ ์•Š๊ธฐ ๋•Œ๋ฌธ์— ๋ฐฐํฌ ๋น ๋ฅด๊ณ  ์„ฑ๋Šฅ ์†์‹ค์ด ๊ฑฐ์˜ ์—†์Œ
โ–ช๏ธŽ ๋งˆ์ดํฌ๋กœ ์„œ๋น„์Šค์— ์šฉ์ด 
โ–ช๏ธŽ ๊ด€๋ จ ๊ธฐ์ˆ ๋กœ ๋„์ปค(Docker)๋ฅผ ๋งŽ์ด ์‚ฌ์šฉ

 

Docker

โ–ช๏ธŽ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ด€๋ฆฌํ•˜๋Š” ๊ฒƒ๊ณผ ๋™์ผํ•œ ๋ฐฉ์‹์œผ๋กœ ์ธํ”„๋ผ ๊ด€๋ฆฌ ๊ฐ€๋Šฅ.
โ–ช๏ธŽ ์ด์‹์„ฑ, ์‹ ์†์„ฑ, ์žฌ์‚ฌ์šฉ์„ฑ 
โ–ช๏ธŽ Dockerfile ๋กœ ๋„์ปค ์ด๋ฏธ์ง€ ์ƒ์„ฑ ์ž๋™ํ™” 

 

โ‰ ๋„์ปค ์ด๋ฏธ์ง€๋Š” ์‹คํ–‰ํ™˜๊ฒฝ, ์†Œ์Šค์ฝ”๋“œ, ์‰˜ ์Šคํฌ๋ฆฝํŠธ ๋“ฑ์„ ํŒŒ์ผ์„ ๋ฌถ์€ ํ˜•ํƒœ์ด๊ณ , ์ปจํ…Œ์ด๋„ˆ๋Š” ์ด๋ฏธ์ง€๋ฅผ ์‹คํ–‰ํ•œ ์ƒํƒœ

 

+ ๊ทธ๋ฆฌ๊ณ  ์ปจํ…Œ์ด๋„ˆ๋“ค์„ ๊ด€๋ฆฌํ•˜๊ธฐ ์œ„ํ•œ ๊ธฐ์ˆ ์ด ์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜!
์ปจํ…Œ์ด๋„ˆ ์˜ค์ผ€์ŠคํŠธ๋ ˆ์ด์…˜ ๊ด€๋ จ ๋„๊ตฌ๋กœ ์œ ๋ช…ํ•œ๊ฒƒ์ด k8s (์ฟ ๋ฒ„๋„คํ‹ฐ์Šค!)

 

 

 


์ฐธ๊ณ 

- ์ฑ…: ๋„๋ฉ”์ธ ์ฃผ๋„ ์„ค๊ณ„๋กœ ์‹œ์ž‘ํ•˜๋Š” ๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค ๊ฐœ๋ฐœ 
- ๋งํฌ: http://koushki.net/2018/06/the-difference-between-vm-and-container/

 

The difference between VM and Container? - The blog on Virtualization and Cloud solutions

One of the most interesting terms in virtualization that is appeared recently is containers. The containers offering a new layer of virtualization that are fit for packaging application. This type of virtualization allows to quickly build and deploy a larg

koushki.net

- ๋งํฌ: https://docs.docker.com/get-docker/

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
CI/CD ๋ž€
์„ค๋ช…

• ๊ฐ๊ฐ์˜ ๊ฐœ๋ฐœ์ž๋“ค์ด ๊ฐœ๋ฐœํ•˜๋Š” ํ™˜๊ฒฝ์„ ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์šฉ ๊ฐ€๋Šฅํ•œ ์„œ๋น„์Šค๋กœ ์ „๋‹ฌํ•˜๋Š” ๋ชจ๋“  ๊ณผ์ •์„ 
์ง€์† ๊ฐ€๋Šฅํ•œ ํ˜•ํƒœ๋กœ ํ˜น์€ ์ž๋™์œผ๋กœ ํ•˜์—ฌ ๊ฐœ๋ฐœ์ž ๋ฐ ์‚ฌ์šฉ์ž ์‚ฌ์ด์˜ ๊ฒฉ์ฐจ๋ฅผ ์—†์• ๋Š”๊ฒƒ
• ๋นŒ๋“œ ๋ฐ ๋ฐฐํฌ๋ฅผ ํ•จ!

๊ฐœ๋ฐœ์ž → ์ฝ”๋“œ์ž‘์„ฑ → ๋นŒ๋“œ(webpack, javac..) → ํ…Œ์ŠคํŠธ(junit..) → ๋ฐฐํฌ(ecs update,,) → ์‚ฌ์šฉ์ž  

โ–บ Continuous Integration (์ง€์†์  ํ†ตํ•ฉ)
• ํ†ตํ•ฉ์˜ ๋Œ€์ƒ? ์ฝ”๋“œ!
• ์—ฌ๋Ÿฌ ๊ฐœ๋ฐœ์ž๋“ค์˜ ์ฝ”๋“œ๋ฒ ์ด์Šค๋ฅผ ๊ณ„์†ํ•ด์„œ ํ†ตํ•ฉํ•˜๋Š”๊ฒƒ.

โ–บ Continuous Delivery (์„œ๋น„์Šค ๋ฐฐ๋‹ฌ)
• ์‚ฌ์šฉ์ž์—๊ฒŒ ์ œํ’ˆ์„ ์„œ๋น„์Šค๋ฅผ ์ง€์†์ ์œผ๋กœ ๋ฐฐ๋‹ฌ!
• ์ฝ”๋“œ๋ฒ ์ด์Šค๊ฐ€ ํ•ญ์ƒ ๋ฐฐํฌ๊ฐ€๋Šฅํ•œ ์ƒํƒœ๋ฅผ ์œ 
• Blue/green, Rolling update, Canary

โ–บ Continuous Deployment 
• ์ฝ”๋“œ๋ฒ ์ด์Šค๋ฅผ ์‚ฌ์šฉ์ž๊ฐ€ ์‚ฌ์šฉ๊ฐ€๋Šฅํ•œ ํ™˜๊ฒฝ์— ๋ฐฐํฌํ•˜๋Š” ๊ฒƒ์„ ์ž๋™ํ™”ํ•จ.
• ํ”ผ๋“œ๋ฐฑ ๋ฐ˜์˜ํ•˜๋Š” ๊ฐœ๋ฐœ ๋ฌธํ™”๋ฅผ ๊ฐ•์กฐ

 

CI/CD ํ•ด์•ผํ•˜๋Š” ์ด์œ 

• ์ฝ”๋“œ ๊ด€๋ฆฌ์˜ ์–ด๋ ค์›€ ๋•Œ๋ฌธ (์—ฌ๋Ÿฌ๋ช…์˜ ๊ฐœ๋ฐœ์ž๊ฐ€ ๊ฐ™์€์˜์—ญ์„ ๊ฐœ๋ฐœํ• ๋•Œ ์ถฉ๋Œ๋“ฑ์ด ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ๊ธฐ ๋•Œ๋ฌธ. ์ด๋ฅผ๋ฐฉ์ง€)
• ๋นจ๋ฆฌ ์ฝ”๋“œ๋ฅผ ์ฝ”๋“œ๋ฒ ์ด์Šค์— ์•ˆ์ฐฉ!

 

 

Jenkins
์„ค๋ช…

• Java Runtime ์œ„์—์„œ ๋™์ž‘ํ•˜๋Š” ์ž๋™ํ™” ์„œ๋ฒ„
• ๋นŒ๋“œ, ํ…Œ์ŠคํŠธ, ๋ฐฐํฌ ๋“ฑ ๋ชจ๋“ ๊ฒƒ์„ ์ž๋™ํ™” ํ•ด์ฃผ๋Š” ์ž๋™ํ™” ์„œ๋ฒ„
• ๋‹ค์–‘ํ•œ ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค์„ ํ™œ์šฉํ•ด์„œ ๊ฐ์ข… ์ž๋™ํ™” ์ž‘์—…์„ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์Œ
• ์ผ๋ จ์˜ ์ž๋™ํ™” ์ž‘์—…์˜ ์ˆœ์„œ๋“ค์˜ ์ง‘ํ•ฉ์ธ Pipeline์„ ํ†ตํ•ด CI/CD ํŒŒ์ดํ”„๋ผ์ธ์„ ๊ตฌ์ถ•ํ•จ
• Credentials Plugins(์ค‘์š”์ •๋ณด aws token, git acccess token ๋“ฑ ์ €์žฅํ•ด์ฃผ๋Š” ํ”Œ๋Ÿฌ๊ทธ์ธ), Gid Plugin, Pipeline, Docker plugin ๋“ฑ์˜ ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์กด์žฌ

 

 

Pipeline
์„ค๋ช…

• CI/CD ํŒŒ์ดํ”„๋ผ์ธ์„ ์  ํ‚จ์Šค์— ๊ตฌํ˜„ํ•˜๊ธฐ ์œ„ํ•œ ์ผ๋ จ์˜ ํ”Œ๋Ÿฌ๊ทธ์ธ๋“ค์˜ ์ง‘ํ•ฉ์ด์ž ๊ตฌ์„ฑ. 
• ํŒŒ์ดํ”„๋ผ์ธ์„ ํ†ตํ•ด ์„œ๋น„์Šค๊ฐ€ ๋ฐฐํฌ๋จ.
• ์ž‘์—…๋ช…์„ธ์„œ.
DSL(Domain Specific Language) ์œผ๋กœ ์ž‘์„ฑ.
๋‘๊ฐ€์ง€ ํ˜•ํƒœ์˜ Pipeline syntax๊ฐ€ ์กด์žฌ (Declarative, Scripted Pipeline)

 

Pipeline ๊ตฌ์„ฑ ์š”์†Œ

โ— Sections
 Agent section : ์–ด๋–ค ์  ํ‚จ์Šค์—๊ฒŒ ์ผ์„ ์‹œํ‚ฌ์ง€ ์ง€์ •! (์  ํ‚จ์Šค ๋…ธ๋“œ ์ƒˆ๋กœ ๋„์šฐ๊ฑฐ๋‚˜, docker ์ด๋ฏธ์ง€๋ฅผ ํ†ตํ•ด ์‚ฌ์šฉ)
 Post section : ์Šคํ…Œ์ด์ง€ ๋๋‚œ ํ›„ ํ›„์†์กฐ์น˜ ์ทจํ•  ์ˆ˜ ์žˆ์Œ.
 Stages section : ์–ด๋–ค์ผ์„ ์ฒ˜๋ฆฌํ• ์ง€ stage ์ •์˜
 Step section : ๋‹จ๊ณ„๋ณ„ ์Šคํ… ์ •์˜ 

โ— Declaratives
 Environment : ์–ด๋–ค ํŒŒ์ดํ”„๋ผ์ธ์ด๋‚˜ stage scope์˜ ํ™˜๊ฒฝ๋ณ€์ˆ˜ ์„ค์ •
 Parameter : ํŒŒ์ดํ”„๋ผ์ธ ์‹คํ–‰ ์‹œ ํŒŒ๋ผ๋ฏธํ„ฐ ๋ฐ›์Œ
 Triggers : ์–ด๋–ค ์ฃผ๊ธฐ๋กœ ์‹คํ–‰
 When : ์–ธ์ œ ์‹คํ–‰๋˜๋Š”๊ฐ€

โ— Steps
 ์—ฌ๋Ÿฌ ์ž‘์—…๋“ค ์‹คํ–‰ ๊ฐ€๋Šฅ.

 

 

๋ฌด์ค‘๋‹จ ๋ฐฐํฌ ๋ฐฉ์‹ 3๊ฐ€์ง€

โ– Rolling Update
์ปจํ…Œ์ด๋„ˆ ์ด๋ฏธ์ง€๋ฅผ ์ƒˆ ๋ฒ„์ „์œผ๋กœ ํ•˜๋‚˜์”ฉ ๊ต์ฒด
 ์ตœ์†Œํ•œ์˜ ์˜ค๋ฒ„ํ—ค๋“œ/์„ฑ๋Šฅ ์˜ํ–ฅ/์ค‘๋‹จ

โ– Canary
์ƒˆ๋กœ์šด ๋ฐฐํฌ ๋ฒ„์ „๊ณผ ํ˜„ํ–‰ ๋ฒ„์ „์„ Prod ํ™˜๊ฒฝ์—์„œ ๋™์‹œ์— ๊ฒ€์ฆํ•˜๊ณ ์ž ํ• ๋•Œ ํ™œ์šฉ
์œ„ํ—˜ ๊ฐ์ง€ ๋ฐฐํฌ ๊ธฐ๋ฒ•

โ– Blue/Green
์™„์ „ํ•˜๊ฒŒ ์ค€๋น„๋œ ์ƒํ™ฉ์—์„œ ์„œ๋น„์Šค ๊ต์ฒด 
 ๋†’์€ ์˜ค๋ฒ„ํ—ค๋“œ์™€ ์„œ๋น„์Šค ์žฅ์•  ์ตœ์†Œํ™” ๊ฐ„ ์กฐ์œจ 

 

 

 


์ฐธ๊ณ 

- ๋งํฌ: https://www.youtube.com/watch?v=JPDKLgX5bRg&list=PL9mhQYIlKEhfgLHvRBRKmTg6HmfSDe8tr&index=1 

- ๋งํฌ: https://onlywis.tistory.com/10

 

๋ฐฐํฌ ์ „๋žต: Rolling, Blue/Green, Canary

์˜ˆ์ „์—๋Š” ์ˆ˜ ๊ฐœ์›”(ํ˜น์€ ์ˆ˜ ๋…„)์— ํ•œ ๋ฒˆ์”ฉ ์„œ๋น„์Šค๋ฅผ ๋ฆด๋ฆฌ์ฆˆ ํ–ˆ์—ˆ์ง€๋งŒ, ์ตœ๊ทผ์—๋Š” ์„œ๋น„์Šค๋ฅผ ๋” ์ž‘๊ฒŒ ๋งŒ๋“ค๊ณ (๋งˆ์ดํฌ๋กœ์„œ๋น„์Šค) ๋” ์ž์ฃผ ๋ฐฐํฌ(Deployment) ํ•˜๋Š” ๋ฐฉ์‹์œผ๋กœ ๋ณ€ํ™”ํ•˜๊ณ  ์žˆ๋‹ค. ์ด๋Ÿฌํ•œ ํŠธ๋ Œ๋“œ์—

onlywis.tistory.com

- ๊ฐ•์˜: https://www.inflearn.com/course/%EC%8B%A4%EB%AC%B4-msa-%EC%9D%B4%EC%95%BC%EA%B8%B0

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
๋ฐฐ์น˜ ์ฒ˜๋ฆฌ 

ใƒป ์ผ์ •๋Ÿ‰์˜ ๋ฐ์ดํ„ฐ๋ฅผ ๋ชจ์•„์„œ ํ•œ๋ฒˆ์— ์ฒ˜๋ฆฌํ•˜๋Š”๊ฒƒ 
ใƒป ์ผ์ •ํ•œ ์ˆœ์„œ์— ๋”ฐ๋ผ ์ฒ˜๋ฆฌ๊ฐ€ ์ด๋ฃจ์–ด์ง
ใƒป ์‘๋‹ต์„ฑ๋ณด๋‹ค ์‹œ๊ฐ„๋‹น ์ฒ˜๋ฆฌ๋Ÿ‰์„ ์šฐ์„ ์‹œํ•˜๋Š” ์ฒ˜๋ฆฌ๋ฐฉ์‹!

โฐ ์žก ์Šค์ผ€์ค„๋Ÿฌ, ์…ธ ์Šคํฌ๋ฆฝํŠธ, ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด๋“ฑ์œผ๋กœ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ๋‹ค.

 

๋ฐฐ์น˜์ฒ˜๋ฆฌ ์ถฉ์กฑ ์กฐ๊ฑด

ใƒป ๋Œ€๋Ÿ‰์˜ ๋ฐ์ดํ„ฐ๋ฅผ ์ œํ•œ๋œ ๋ฆฌ์†Œ์Šค๋กœ ํšจ์œจ์ ์œผ๋กœ ์ฒ˜๋ฆฌํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ
ใƒป ๊ฐ€๋Šฅํ•œ ํ•œ ์ค‘๋‹จ๋œ ์ž‘์—…์„ ๋‹ค์‹œ ๊ณ„์†ํ•  ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ
ใƒป ๋‹ค์–‘ํ•œ ์‹คํ–‰ ์กฐ๊ฑด์„ ์ง€์›ํ•ด์•ผ ํ•จ.
ใƒป ๋‹ค์–‘ํ•œ ์ž…์ถœ๋ ฅ ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ๋‹ค๋ฃฐ ์ˆ˜ ์žˆ์–ด์•ผ ํ•จ

 

์Šคํ”„๋ง ๋ฐฐ์น˜

ใƒป ์Šคํ”„๋ง์—์„œ ์ œ๊ณตํ•ด์ฃผ๋Š” ๋ฐฐ์น˜ ํ”„๋ ˆ์ž„์›Œํฌ
ใƒป ์Šคํ”„๋ง์ด ๊ฐ€์ง€๊ณ  ์žˆ๋˜ DI ์ปจํ…Œ์ด๋„ˆ, AOP, ํŠธ๋žœ์žญ์…˜ ๊ด€๋ฆฌ ๊ธฐ๋Šฅ์„ ๊ธฐ๋ณธ์œผ๋กœ ๊ฐ€์ง€๊ณ  ์žˆ์Œ.

๐Ÿ’ฅ ์ฐธ๊ณ ๋กœ ์Šคํ”„๋ง ๋ฐฐ์น˜๋Š” ๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ๋ฅผ ํ•œ๋ฒˆ์— ์ฒ˜๋ฆฌ ํ•˜๊ณ 
์Šคํ”„๋ง ์Šค์ผ€์ค„๋Ÿฌ๋Š” ์Šคํ”„๋ง ๋ฐฐ์น˜๋ฅผ ์ผ์ •ํ•œ ์‹œ๊ฐ„๊ฐ„๊ฒฉ or ์ผ์ •ํ•œ ์‹œ๊ฐ„์— !!์‹คํ–‰!!์‹œ์ผœ์ฃผ๋Š” ์—ญํ• ์„ ํ•จ! (๋ฐฐ์น˜๋ž‘ ์Šค์ผ€์ค„๋Ÿฌ ๋‹ค๋ฆ„!!)

์Šค์ผ€์ค„๋Ÿฌ ํ”„๋ ˆ์ž„์›Œํฌ๋กœ..
- Spring Scheduler (๋ณ„๋„์˜ ์˜์กด์„ฑ ํ•„์š”ํ•˜์ง€ ์•Š์Œ! spring boot starter ์— ๊ธฐ๋ณธ ์˜์กด์„ฑ ์ œ๊ณต๋จ)
- Spring Quartz (์˜์กด์„ฑ ์ถ”๊ฐ€ ํ•„์š”, ์Šค์ผ€์ค„๋ง์˜ ์„ธ๋ฐ€ํ•œ ์ œ์–ด๊ฐ€ ํ•„์š”ํ• ๋•Œ ์‚ฌ์šฉ..)
๋“ฑ์ด ์กด์žฌํ•จ.

์  ํ‚จ์Šค๋กœ๋„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

์Šคํ”„๋ง ๋ฐฐ์น˜ ํŠน์ง•

ใƒป Tasklet ๋ฐฉ์‹ (SQL ํ•œ๋ฒˆ ์‹คํ–‰, ๋ช…๋ น ์‹คํ–‰ ๋“ฑ ๋‹จ์ˆœ ์ฒ˜๋ฆฌ) / Chunk ๋ฐฉ์‹ ์กด์žฌํ•จ (๋Œ€๋Ÿ‰ ๋ฐ์ดํ„ฐ ์ฒ˜๋ฆฌ, ํŠธ๋žœ์žญ์…˜์€ ์Šคํ”„๋ง ๋ฐฐ์น˜๊ฐ€ ์ฒ˜๋ฆฌ)
ใƒป ๋‹ค์–‘ํ•œ ์‹คํ–‰ ๋ฐฉ๋ฒ•์„ ์ œ๊ณตํ•œ๋‹ค. (๋ช…๋ นํ–‰ ์‹คํ–‰, ์„œ๋ธ”๋ฆฟ ์‹คํ–‰ ๋“ฑ)
ใƒป ๋‹ค์–‘ํ•œ ๋ฐ์ดํ„ฐ ํ˜•์‹์œผ๋กœ ์ž…์ถœ๋ ฅํ•  ์ˆ˜ ์žˆ๋‹ค. (ํŒŒ์ผ, ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค, ๋ฉ”์„ธ์ง€ํ ๋“ฑ)
ใƒป ๋ฐฐ์น˜ ์ฒ˜๋ฆฌ๋ฅผ ํšจ์œจ์ ์œผ๋กœ ์ˆ˜ํ–‰ํ•  ์ˆ˜ ์žˆ๋‹ค. (๋‹ค์ค‘์‹คํ–‰, ๋ณ‘๋ ฌ์‹คํ–‰, ์กฐ๊ฑด๋ถ„๊ธฐ ๋“ฑ)
ใƒป Job์„ ๊ด€๋ฆฌํ•  ์ˆ˜ ์žˆ๋‹ค. (Job์ด ์‹คํ–‰๋˜๋˜ ์ƒํ™ฉ์„ ์ €์žฅ or ์žฌ์‹œ์ž‘ ๊ฐ€๋Šฅ)

 

์Šคํ”„๋ง ๋ฐฐ์น˜ ๊ตฌ์กฐ

  • JobLauncher
    ๋ฐฐ์น˜ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ธฐ๋™ํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค. ๋ชจ๋“  ๋ฐฐ์น˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์€ ์ด ํด๋ž˜์Šค๋ฅผ ํ†ตํ•ด ์‹คํ–‰. 
    ์ธ์ˆ˜์ „๋‹ฌ ๋“ฑ๋„ ์—ฌ๊ธฐ์„œ ์ฒ˜๋ฆฌ!

  • Job
    ๋ฐฐ์น˜ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ ์ผ๋ จ์˜ ์ฒ˜๋ฆฌ ๊ณผ์ •์„ ํ•˜๋‚˜์˜ ๋‹จ์œ„๋กœ ๋งŒ๋“  ์‹คํ–‰ ๋‹จ์œ„

  • Step
    ์žก์„ ๊ตฌ์„ฑํ•˜๋Š” ์„ธ๋ถ€ ์ฒ˜๋ฆฌ ๋‹จ์œ„. ํ•˜๋‚˜์˜ Job์€ N๊ฐœ์˜ Step์œผ๋กœ ๊ตฌ์„ฑ๋  ์ˆ˜ ์žˆ๋‹ค.
    ํ•˜๋‚˜์˜ Job ์ฒ˜๋ฆฌ๋ฅผ ์—ฌ๋Ÿฌ๊ฐœ์˜ Step์œผ๋กœ ๋ถ„ํ• ํ•˜๋ฉด ์„ธ๋ถ€ ์ฒ˜๋ฆฌ๋ฅผ ์žฌ์‚ฌ์šฉํ•˜๊ฑฐ๋‚˜ ๋ณ‘๋ ฌ ์ฒ˜๋ฆฌ๋ฅผ ์ ์šฉํ•  ์ˆ˜ ์žˆ๊ณ , ์กฐ๊ฑด ๋ถ„๊ธฐ์— ๋”ฐ๋ฅธ ์ œ์–ด๋„ ํ• ์ˆ˜์žˆ๋‹ค.
    Chunk๋ฐฉ์‹์ด๋‚˜ Step๋ฐฉ์‹ ์ค‘ ํ•œ๊ฐ€์ง€ ํ˜•ํƒœ๋กœ ์‹คํ–‰๋จ.

  • ItemReader, ItemProcessor, ItemWriter
    Step์„ ๋ฐ์ดํ„ฐ์˜ ์ž…๋ ฅ, ๊ฐ€๊ณต, ์ถœ๋ ฅ์˜ ์„ธ๊ฐ€์ง€ ํŒจํ„ด ์ฒ˜๋ฆฌ๋กœ ๋ถ„ํ• ํ•˜๊ธฐ ์œ„ํ•œ ์ธํ„ฐํŽ˜์ด์Šค
    Chunk๋ฐฉ์‹์„ ๊ตฌํ˜„ํ•  ๋•Œ ์ด ์„ธ๊ฐ€์ง€ ํŒจํ„ด์„ ํ™œ์šฉํ•จ.

  • JobRepository
    Job or Step ์ƒํƒœ๋ฅผ ๊ด€๋ฆฌํ•จ. ์ด๋Ÿฌํ•œ ์ •๋ณด๋Š” ์Šคํ”„๋ง ๋ฐฐ์น˜๊ฐ€ ์ •์˜ํ•œ ํ…Œ์ด๋ธ” ์Šคํ‚ค๋งˆ ํ˜•ํƒœ๋กœ ๋ฐ์ดํ„ฐ๋ฒ ์ด์Šค์— ์ €์žฅ๋จ.

 

์Šคํ”„๋ง ๋ฐฐ์น˜ ์•„ํ‚คํ…์ฒ˜

 

 


์ฐธ๊ณ 

https://terasoluna-batch.github.io/guideline/5.0.0.RELEASE/en/Ch02_SpringBatchArchitecture.html

 

Spring Batch Architecture

Spring Batch architecture acting as a base for TERASOLUNA Server Framework for Java (5.x) is explained. What is Spring Batch Spring Batch, as the name implies is a batch application framework. Following functions are offered based on DI container of Spring

terasoluna-batch.github.io

https://sabarada.tistory.com/113

 

[Spring] Scheduler ์–ด๋–ค๊ฑธ ์‚ฌ์šฉํ•ด์•ผ ํ• ๊นŒ ? - Spring Scheduler์™€ Spring Quartz

์ผ์ •ํ•œ ์‹œ๊ฐ„๊ฐ„๊ฒฉ ๋˜๋Š” ์ผ์ •ํ•œ ์‹œ๊ฐ์— ํŠน์ • ๋กœ์ง์„ ๋Œ๋ฆฌ๊ธฐ ์œ„ํ•ด์„œ ์‚ฌ์šฉํ•˜๋Š” ๊ฒƒ์„ Scheduler๋ผ๊ณ  ํ•ฉ๋‹ˆ๋‹ค. ์ด๋Ÿฐ Scheduler๋Š” Spring์—์„œ Spring Scheduler์™€ Spring Quartz๋ผ๋Š” 2๊ฐ€์ง€ ๋ฐฉ์‹์œผ๋กœ ์ œ๊ณต๋ฉ๋‹ˆ๋‹ค. 1๊ฐ€์ง€ ์ผ

sabarada.tistory.com

https://blog.junu.dev/34

 

[์šฐ์•„ํ•œํ…Œํฌ์„ธ๋ฏธ๋‚˜] ์šฐ์•„ํ•œ ์Šคํ”„๋ง ๋ฐฐ์น˜ ํ›„๊ธฐ

์šฐ์•„ํ•œ ์Šคํ”„๋ง ๋ฐฐ์น˜ ์ง€๋‚œ๋‹ฌ์— ์ด์–ด์„œ ์šด ์ข‹๊ฒŒ9์›” ์šฐ์•„ํ•œ ํ…Œํฌ ์„ธ๋ฏธ๋‚˜์—๋„ ๋‹น์ฒจ๋˜์–ด ์„ธ๋ฏธ๋‚˜์— ๋‹ค๋…€์™”์Šต๋‹ˆ๋‹ค. ์ทจ์—…์ค€๋น„๋ฅผ ํ•  ๋•Œ ๊ฐ€์žฅ ๋งŽ์€ ๋„์›€์„ ๋ฐ›์€ ๋ธ”๋กœ๊ทธ ์ด๊ธฐ๋„ ํ•˜๊ณ , ํ˜„์žฌ ์ œ๊ฐ€ ๋‹ค๋‹ˆ๋Š” ํšŒ

blog.junu.dev

https://jojoldu.tistory.com/325?category=902551 

 

2. Spring Batch ๊ฐ€์ด๋“œ - Batch Job ์‹คํ–‰ํ•ด๋ณด๊ธฐ

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” ๊ฐ„๋‹จํ•œ Spring Batch Job์„ ์ƒ์„ฑ & ์‹คํ–‰ํ•˜๋ฉด์„œ ์ „๋ฐ˜์ ์ธ ๋‚ด์šฉ์„ ๊ณต๋ถ€ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค. ์ž‘์—…ํ•œ ๋ชจ๋“  ์ฝ”๋“œ๋Š” Github์— ์žˆ์œผ๋‹ˆ ์ฐธ๊ณ ํ•˜์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค. 2-1. Spring Batch ํ”„๋กœ์ ํŠธ ์ƒ์„ฑํ•˜๊ธฐ ๊ธฐ๋ณธ์ ์ธ

jojoldu.tistory.com

์ฑ… ์Šคํ”„๋ง ์ฒ ์ € ์ž…๋ฌธ 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•

 

RESTful, ๋น„ํšจ์œจ์  ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ๋ฉ”์„ธ์ง€ ํ”„๋กœํ† ์ฝœ

RESTful ์„œ๋น„์Šค๋Š” HTTP 1.x ์™€ ๊ฐ™์€ ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ์ „์†ก ํ”„๋กœํ† ์ฝœ๋กœ ๊ตฌ์ถ•๋˜๊ณ , JSON ์ฒ˜๋Ÿผ ์‚ฌ๋žŒ์ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ํ…์ŠคํŠธ ํฌ๋งท์„ ํ™œ์šฉํ•จ.
๊ทธ๋Ÿฐ๋ฐ, ์„œ๋น„์Šค๊ฐ„ ํ†ต์‹ ์„ ํ•  ๊ฒฝ์šฐ(common server - user server ์ด๋Ÿฐ์‹?) ์‚ฌ๋žŒ์ด ์ฝ์„ ์ˆ˜ ์žˆ๋Š” ํ…์ŠคํŠธ ๊ธฐ๋ฐ˜ ํฌ๋งท์„ ์‚ฌ์šฉํ•  ํ•„์š”๊ฐ€ ์—†์Œ!
→ ๋น„ํšจ์œจ์ ์ด๋ผ ํŒ๋‹จํ•จ. 

ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์„œ๋ฒ„๋กœ ์ „์†กํ•  ๋ฐ”์ด๋„ˆ๋ฆฌ ์ฝ˜ํ…์ธ ๋ฅผ ๋งŒ๋“  ํ›„, ๋ฐ”์ด๋„ˆ๋ฆฌ ๊ตฌ์กฐ์ฒด๋ฅผ ํ…์ŠคํŠธ๋กœ ๋ณ€ํ™˜ํ•จ.
๊ทธ๋ฆฌ๊ณ  ๋„คํŠธ์›Œํฌ๋ฅผ ํ†ตํ•ด ํ…์ŠคํŠธ๋กœ ์ „์†กํ•˜๊ณ  ์„œ๋น„์Šค์ธก์—์„œ ๋‹ค์‹œ ๋ฐ”์ด๋„ˆ๋ฆฌ ๊ตฌ์กฐ๋กœ ๋ณ€ํ™˜ํ•จ.
→ ์ด๋Ÿด๋ฐ”์— ๋น„์ฆˆ๋‹ˆ์Šค ๋กœ์ง์œผ๋กœ ๋ฐ”๋กœ ๋งคํ•‘๋  ์ˆ˜ ์žˆ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ํ˜•์‹์œผ๋กœ ์‰ฝ๊ฒŒ ์ „์†กํ•˜๋Š”๊ฒƒ์ด ๋‚ซ๋‹ค๊ณ  ํŒ๋‹จ!

 

 

RPC
์„ค๋ช…

ํด๋ผ์ด์–ธํŠธ - ์„œ๋น„์Šค ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ๊ตฌ์ถ•ํ•˜๋Š” ๋ฐ ๋„๋ฆฌ ์‚ฌ์šฉ๋˜๋Š” ํ”„๋กœ์„ธ์Šค๊ฐ„ ํ†ต์‹  ๊ธฐ์ˆ 
RPC์„ ํ†ตํ•ด ํด๋ผ์ด์–ธํŠธ๋Š” ๋กœ์ปฌ ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ์ฒ˜๋Ÿผ ์›๊ฒฉ์œผ๋กœ ๋ฉ”์„œ๋“œ ๊ธฐ๋Šฅ์„ ํ˜ธ์ถœํ•  ์ˆ˜ ์žˆ๋‹ค.

 

 

gRPC
์„ค๋ช…

๊ตฌ๊ธ€์—์„œ ๋งŒ๋“  ์˜คํ”ˆ์†Œ์Šค ์›๊ฒฉ ํ”„๋กœ์‹œ์ € ํ˜ธ์ถœ ์‹œ์Šคํ…œ.

โ€ป ์›๊ฒฉ ํ”„๋กœ์‹œ์ €
๋ณ„๋„์˜ ์›๊ฒฉ ์ œ์–ด๋ฅผ ์œ„ํ•œ ์ฝ”๋”ฉ ์—†์ด ๋‹ค๋ฅธ ์ฃผ์†Œ ๊ณต๊ฐ„์—์„œ ํ•จ์ˆ˜๋‚˜ ํ”„๋กœ์‹œ์ €๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒํ•˜๋Š” ํ”„๋กœ์„ธ์Šค ๊ฐ„ ํ†ต์‹  ๊ธฐ์ˆ ์ด๋‹ค.
๋‹ค์‹œ ๋งํ•ด, ์›๊ฒฉ ํ”„๋กœ์‹œ์ € ํ˜ธ์ถœ์„ ์ด์šฉํ•˜๋ฉด ํ”„๋กœ๊ทธ๋ž˜๋จธ๋Š” ํ•จ์ˆ˜๊ฐ€ ์‹คํ–‰ ํ”„๋กœ๊ทธ๋žจ์— ๋กœ์ปฌ ์œ„์น˜์— ์žˆ๋“  ์›๊ฒฉ ์œ„์น˜์— ์žˆ๋“  ๋™์ผํ•œ ์ฝ”๋“œ๋ฅผ ์ด์šฉํ•  ์ˆ˜ ์žˆ๋‹ค.

๋กœ์ปฌํ•จ์ˆ˜๋ฅผ ํ˜ธ์ถœํ•˜๋Š” ๊ฒƒ ๋งŒํผ ์‰ฝ๊ฒŒ ๋ถ„์‚ฐ๋œ ์ด๊ธฐ์ข… ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์„ ์—ฐ๊ฒฐ/ํ˜ธ์ถœ/์šด์˜/๋””๋ฒ„๊น… ํ•  ์ˆ˜ ์žˆ๋Š” ํ”„๋กœ์„ธ์Šค ๊ฐ„ ํ†ต์‹  ๊ธฐ์ˆ .
์ฃผ๋กœ ํ†ต์‹ ์— ๋™๊ธฐ์‹ ์š”์ฒญ-์‘๋‹ต ์Šคํƒ€์ผ์„ ์‚ฌ์šฉํ•˜๋‚˜, ์ดˆ๊ธฐ ํ†ต์‹ ์ด ์„ค์ •๋˜๋ฉด ์™„์ „ ๋น„๋™๊ธฐ์‹์ด๊ฑฐ๋‚˜ ์ŠคํŠธ๋ฆฌ๋ฐ ๋ชจ๋“œ์—์„œ ์ž‘๋™ํ•  ์ˆ˜ ์žˆ๋‹ค.
ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ์™€ HTTP/2 ํ”„๋กœํ† ์ฝœ ์œ„์— ๊ตฌ์ถ•๋จ.

โ€ป ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ
๊ตฌ์กฐํ™”๋œ ๋ฐ์ดํ„ฐ๋ฅผ ์ง๋ ฌํ™”ํ•˜๊ณ ์ž ์–ธ์–ด์— ๊ตฌ์•  ๋ฐ›์ง€ ์•Š๊ณ  ํ”Œ๋žซํผ ์ค‘๋ฆฝ์ ์ด๋ฉฐ ํ™•์žฅ ๊ฐ€๋Šฅํ•œ ๋ฉ”์ปค๋‹ˆ์ฆ˜์ธ ๋ฐ์ดํ„ฐ ์ง๋ ฌํ™” ํ”„๋กœํ† ์ฝœ.
๋ฐ์ดํ„ฐ๊ฐ€ ์ง๋ ฌํ™”๋˜๋ฉด ์ด ํ”„๋กœํ† ์ฝœ์€ ์ผ๋ฐ˜ JSON ํŽ˜์ด๋กœ๋“œ๋ณด๋‹ค ํฌ๊ธฐ๊ฐ€ ์ž‘๊ณ  ๊ฐ•๋ ฅํ•œ ํ˜•์‹์˜ ๋ฐ”์ด๋„ˆ๋ฆฌ ํŽ˜์ด๋กœ๋“œ๋ฅผ ์ƒ์„ฑํ•จ.
→ HTTP/2๋ผ๋Š” ๋ฐ”์ด๋„ˆ๋ฆฌ ์ „์†ก ํ”„๋กœํ† ์ฝœ์„ ํ†ตํ•ด ์ „์†ก!

 

๊ตฌ์„ฑ ํ”„๋กœ์ ํŠธ

โ— ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
โ€ฃ ์„œ๋น„์Šค๋ฅผ ์‚ฌ์šฉํ•˜๋Š” ๋ฐฉ๋ฒ•, ์›๊ฒฉ์œผ๋กœ ํ˜ธ์ถœ๋˜๋Š” ๋ฉ”์„œ๋“œ ์ข…๋ฅ˜, ํ•ด๋‹น ๋ฉ”์„œ๋“œ๋ฅผ ํ˜ธ์ถœํ•˜๊ธฐ ์œ„ํ•œ ํŒŒ๋ผ๋ฏธํ„ฐ, ๋ฉ”์„ธ์ง€ ํ˜•์‹๋“ฑ์„ ํฌํ•จ.
โ€ฃ *.proto ํŒŒ์ผ๋กœ ์ •์˜(=์ธํ„ฐํŽ˜์ด์Šค ์ •์˜ ์–ธ์–ด), ์ด๋Š” ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ ๋ฉ”์„ธ์ง€๋กœ RPC ๋ฉ”์„œ๋“œ ํŒŒ๋ผ๋ฏธํ„ฐ ๋ฐ ๋ฐ˜ํ™˜ ํƒ€์ž…๊ณผ ํ•จ๊ป˜ gRPC ์„œ๋น„์Šค๋ฅผ ์ผ๋ฐ˜ ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ ํ˜•์‹์œผ๋กœ ์ •์˜ํ•จ.
โ€ฃ ํ”„๋กœํ†  ํŒŒ์ผ์—์„œ ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•˜๊ณ ์ž gRPC ํ”Œ๋Ÿฌ๊ทธ์ธ์ด ์‚ฌ์šฉ๋œ๋‹ค.

โ€ป gRPC ํ”Œ๋Ÿฌ๊ทธ์ธ
gRPC ์„œ๋ฒ„์ธก, ํด๋ผ์ด์–ธํŠธ์ธก ์ฝ”๋“œ ๋ฟ๋งŒ์ด ์•„๋‹ˆ๋ผ
์ •์˜๋œ ๋ฉ”์„ธ์ง€ ํƒ€์ž…์˜ ๋ฐ์ดํ„ฐ ์ง€์ •, ์ง๋ ฌํ™”, ๋ฐ์ดํ„ฐ ์ทจ๋“์˜ ์ผ๋ฐ˜ ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ ์ฝ”๋“œ๋„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.

โ— ์„œ๋ฒ„
โ€ฃ ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜๊ฐ€ ์™„๋ฃŒ๋˜๋ฉด, protoc์„ ์‚ฌ์šฉํ•ด ์„œ๋ฒ„์ธก์ด๋‚˜ ํด๋ผ์ด์–ธํŠธ ์ธก ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ๋‹ค.
โ€ฃ ์Šค์ผˆ๋ ˆํ†ค(server skeleton) ์ด๋ผ๋Š” ์„œ๋ฒ„์ธก ์ฝ”๋“œ ์ƒ์„ฑ๊ฐ€๋Šฅ. ์ €์ˆ˜์ค€์˜ ํ†ต์‹  ์ถ”์ƒํ™”๋ฅผ ํ†ตํ•ด ์„œ๋ฒ„ ์ธก ๋กœ์ง ๋‹จ์ˆœํ™” ๊ฐ€๋Šฅ.
  (gRPC ๊ด€๋ จ ์ƒ์œ„ ์„œ๋น„์Šค ํด๋ž˜์Šค๋ฅผ ์˜ค๋ฒ„๋ผ์ด๋“œ ํ•˜์—ฌ ์Šค์ผˆ๋ ˆํ†ค(server skeleton) ์ด๋ผ๋Š” ์„œ๋ฒ„์ธก ์ฝ”๋“œ ๊ตฌํ˜„!)
โ€ฃ ๋กœ์ง ๊ตฌํ˜„ ํ›„, ์„œ๋ฒ„ ์‹คํ–‰ํ•˜์—ฌ ํด๋ผ์ด์–ธํŠธ ์š”์ฒญ ์ˆ˜์‹  ๋ฐ ์‘๋‹ต!

โ— ํด๋ผ์ด์–ธํŠธ
โ€ฃ ์Šคํ…(client stub) ์ด๋ผ๋Š” ์ฝ”๋“œ๋ฅผ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Œ. ๋ฉ”์†Œ๋“œ ํ•จ์ˆ˜ ํ˜ธ์ถœํ•˜๋Š”๊ฒƒ์ฒ˜๋Ÿผ ์‰ฝ๊ฒŒ ํด๋ผ์ด์–ธํŠธ์ธก์—์„œ ์›๊ฒฉ ํ˜ธ์ถœ ๊ฐ€๋Šฅ.
โ€ฃ ์Šคํ…(client stub)์€ ์„œ๋ฒ„์™€ ๋™์ผํ•œ ๋ฉ”์„œ๋“œ๋ฅผ ์ œ๊ณตํ•˜๋Š”๋ฐ, ํด๋ผ์ด์–ธํŠธ ์ฝ”๋“œ์—์„œ ๋ฉ”์„œ๋“œ๋“ค์˜ ํ˜ธ์ถœ์„ ๋„คํŠธ์›Œํฌ์ƒ ์›๊ฒฉ ํ•จ์ˆ˜ ํ˜ธ์ถœ๋กœ ๋ณ€ํ™˜ํ•จ.

์œผ๋กœ ๊ตฌ์„ฑ.

 

ํด๋ผ์ด์–ธํŠธ-์„œ๋ฒ„ ํ๋ฆ„

ProductInfo Service ๊ฐ€ ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜๋ถ€, Consumer๊ฐ€ ํด๋ผ์ด์–ธํŠธ, Product Info ๊ฐ€ ์„œ๋ฒ„


โ–ถ๏ธŽ ๋„คํŠธ์›Œํฌ ํ†ต์‹ ์€ HTTP/2๋ฅผ ํ†ตํ•ด ์ด๋ฃจ์–ด์ง
โ–ถ๏ธŽ (java ๊ธฐ์ค€) *.proto ํŒŒ์ผ ์ƒ์„ฑ ํ›„, ๋นŒ๋“œํ•˜๋ฉด(๋ฌผ๋ก  ๊ด€๋ จ ํŒจํ‚ค์ง€ importํ•˜๊ณ ,,) grpc ์‚ฌ์šฉ๊ด€๋ จ ํด๋ž˜์Šค๋“ค์ด ์ƒ์„ฑ๋˜๊ณ , ์ด๋ฅผ ์„œ๋ฒ„์™€ ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์‚ฌ์šฉํ•˜๋Š”๊ฒƒ์œผ๋กœ ํ™•์ธ

 

gRPC ์žฅ์ 

• ํ”„๋กœ์„ธ์Šค๊ฐ„ ํ†ต์‹  ํšจ์œจ์„ฑ์ด ์ฆ๋Œ€
ํ…์ŠคํŠธ ํ˜•์‹ ๋Œ€์‹  ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ ๊ธฐ๋ฐ˜ ๋ฐ”์ด๋„ˆ๋ฆฌ ํ”„๋กœํ† ์ฝœ์„ ์‚ฌ์šฉํ•˜์—ฌ gRPC ์„œ๋น„์Šค ๋ฐ ํด๋ผ์ด์–ธํŠธ์™€ ํ†ต์‹ ํ•˜๋ฉฐ,
HTTP/2 ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ๋กœ ๊ตฌํ˜„๋˜๊ธฐ์— ํ”„๋กœ์„ธ์Šค ๊ฐ„ ํ†ต์‹  ์†๋„๊ฐ€ ๋งค์šฐ ๋นจ๋ผ์ง„๋‹ค.

 ๊ฐ„๋‹จ ๋ช…ํ™•ํ•œ ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค ์Šคํ‚ค๋งˆ
๋จผ์ € ์„œ๋น„์Šค ์ธํ„ฐํŽ˜์ด์Šค๋ฅผ ์ •์˜ ํ•˜๊ณ ๋‚˜์„œ ๊ตฌํ˜„ ์„ธ๋ถ€ ์‚ฌํ•ญ์„ ์ž‘์—…ํ•œ๋‹ค. (๊ตฌํ˜„์ด ๊ฐ„๋‹จ)

 ์—„๊ฒฉํ•œ ํƒ€์ž… ์ ๊ฒ€ ํ˜•์‹
ํ”„๋กœํ† ์ฝœ ๋ฒ„ํผ๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ์— gRPC ์„œ๋น„์Šค ๊ณ„์•ฝ์€ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜๊ฐ„ ํ†ต์‹ ์— ์‚ฌ์šฉํ•  ๋ฐ์ดํ„ฐ ํƒ€์ž…์„ ๋ช…ํ™•ํ•˜๊ฒŒ ์ •์˜ํ•œ๋‹ค.

• ํด๋ฆฌ๊ธ€๋ž
์—ฌ๋Ÿฌ ํ”„๋กœ๊ทธ๋ž˜๋ฐ ์–ธ์–ด์™€ ์ž‘๋™ํ•˜๋„๋ก ์„ค๊ณ„๋จ. ํŠน์ •์–ธ์–ด์— ๊ตฌ์•  ์•ˆ๋ฐ›์Œ!

• ์ด์ค‘ ์ŠคํŠธ๋ฆฌ๋ฐ

• ์œ ์šฉํ•œ ๋‚ด์žฅ ๊ธฐ๋Šฅ ์ง€์›

• ํด๋ผ์šฐ๋“œ ๋„ค์ดํ‹ฐ๋ธŒ ์ƒํƒœ๊ณ„์™€ ํ†ตํ•ฉ
๋„ทํ”Œ๋ฆญ์Šค ๋„์ปค ์‹œ์Šค์ฝ” ๋“ฑ์—์„œ ์ฑ„ํƒ

 

gRPC ๋‹จ์ 

 ์™ธ๋ถ€ ์„œ๋น„์Šค ๋ถ€์ ํ•ฉ
์™ธ๋ถ€ ํด๋ผ์ด์–ธํŠธ์— ์ œ๊ณตํ•˜๋ ค๋Š” ๊ฒฝ์šฐ๋Š” ์ ํ•ฉํ•˜์ง€ ์•Š์„ ์ˆ˜ ์žˆ์Œ.
๊ณ„์•ฝ ๊ธฐ๋ฐ˜์ด๊ณ , ๊ฐ•๋ ฅํ•œ ํƒ€์ž… ์†์„ฑ์„ ๊ฐ–๊ธฐ ๋•Œ๋ฌธ
๊ทธ๋ž˜์„œ gRPC ๊ฒŒ์ดํŠธ์›จ์ด๋Š” ์ด ๋ฌธ์ œ๋ฅผ ํ•ด๊ฒฐ์ฑ…์œผ๋กœ ์„ค๊ณ„๋จ.

• ์„œ๋น„์Šค ์ •์˜์˜ ๊ธ‰๊ฒฉํ•œ ๋ณ€๊ฒฝ์— ๋”ฐ๋ฅธ ๊ฐœ๋ฐœ ํ”„๋กœ์„ธ์Šค ๋ณต์žก์„ฑ
gRPC ์„œ๋น„์Šค๊ฐ€ ์žฌ์ •์˜๋˜๋ฉด, ํด๋ผ์ด์–ธํŠธ ๋ฐ ์„œ๋ฒ„ ์ฝ”๋“œ ๋ชจ๋‘ ๋ณ€๊ฒฝ์„ ํ•ด์•ผํ•จ;

• ์ƒ๋Œ€์ ์œผ๋กœ ์ž‘์€ ์ƒํƒœ๊ณ„
๋ธŒ๋ผ์šฐ์ € ๋ฐ ๋ชจ๋ฐ”์ผ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜์—์„œ gRPC ์ง€์›์€ ์ดˆ๊ธฐ ๋‹จ๊ณ„๋ผ๊ณ ํ•จ.

 

 

..

 

 


์ฐธ๊ณ 

์ฑ…: http://www.kyobobook.co.kr/product/detailViewKor.laf?mallGb=KOR&ejkGb=KOR&barcode=9791161754635
๋งํฌ: https://thenewstack.io/grpc-remote-procedure-calls-in-a-nutshell/

 

gRPC Remote Procedure Calls in a Nutshell

gRPC (gRPC Remote Procedure Calls) is one of the most popular inter-process communication protocols in the modern microservices and cloud native era.

thenewstack.io

 

gRPC ์‹œ์ž‘์—์„œ ์šด์˜๊นŒ์ง€ - ๊ต๋ณด๋ฌธ๊ณ 

๋„์ปค์™€ ์ฟ ๋ฒ„๋„คํ‹ฐ์Šค๋ฅผ ์œ„ํ•œ ํด๋ผ์šฐ๋“œ ๋„ค์ดํ‹ฐ๋ธŒ ์• ํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ตฌ์ถ• | โ˜… ์ด ์ฑ…์—์„œ ๋‹ค๋ฃจ๋Š” ๋‚ด์šฉ โ˜…โ–  gRPC์˜ ๊ธฐ๋ณธ ์‚ฌํ•ญ์„ ์ดํ•ดํ•˜๊ณ  ์œ ์‚ฌํ•œ ๊ธฐ์ˆ ๊ณผ ๋น„๊ตํ•˜๊ธฐโ–  ์‹ค์ œ ์‚ฌ๋ก€๋ฅผ ํ†ตํ•œ gRPC ํ†ต์‹  ํŒจํ„ด ํ™•์ธ

www.kyobobook.co.kr

๋งํฌ: https://grpc.io/

 

gRPC

A high-performance, open source universal RPC framework

grpc.io

๋งํฌ: https://ko.wikipedia.org/wiki/%EC%9B%90%EA%B2%A9_%ED%94%84%EB%A1%9C%EC%8B%9C%EC%A0%80_%ED%98%B8%EC%B6%9C

 

์›๊ฒฉ ํ”„๋กœ์‹œ์ € ํ˜ธ์ถœ - ์œ„ํ‚ค๋ฐฑ๊ณผ, ์šฐ๋ฆฌ ๋ชจ๋‘์˜ ๋ฐฑ๊ณผ์‚ฌ์ „

์›๊ฒฉ ํ”„๋กœ์‹œ์ € ํ˜ธ์ถœ(์˜์–ด: remote procedure call, ๋ฆฌ๋ชจํŠธ ํ”„๋กœ์‹œ์ € ์ฝœ, RPC)์€ ๋ณ„๋„์˜ ์›๊ฒฉ ์ œ์–ด๋ฅผ ์œ„ํ•œ ์ฝ”๋”ฉ ์—†์ด ๋‹ค๋ฅธ ์ฃผ์†Œ ๊ณต๊ฐ„์—์„œ ํ•จ์ˆ˜๋‚˜ ํ”„๋กœ์‹œ์ €๋ฅผ ์‹คํ–‰ํ•  ์ˆ˜ ์žˆ๊ฒŒํ•˜๋Š” ํ”„๋กœ์„ธ์Šค ๊ฐ„ ํ†ต์‹  ๊ธฐ์ˆ ์ด

ko.wikipedia.org

 

๋ฐ˜์‘ํ˜•
๋ฐ˜์‘ํ˜•
๋ชฉ์ 

์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ(Springboot jar file, gradle ์ด์šฉ)์„ AWS EC2์— ๋ฐ˜์˜ํ•ด๋ณด๊ธฐ
โ€ฃ jenkins ์„œ๋ฒ„์— ์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ์„ ๋นŒ๋“œ / ๋ฐฐํฌํ•˜๋Š” ์…ˆ.
โ€ฃ ์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ์€ ๊ฐœ์ธ github ์—์„œ ๊ฐ€์ ธ์˜ด! (github ์˜ webhook ๊ธฐ๋Šฅ ์ด์šฉ) 

 

์ž‘์—…์ˆœ์„œ

1๏ธโƒฃ EC2 ์ƒ์„ฑ ๋ฐ ํ„ฐ๋ฏธ๋„ ์ ‘์†
โ€ฃ EC2 ์ƒ์„ฑ๋ฐฉ๋ฒ•์€ ์ƒ๋žตํ•จ. (t2.micro ์ด์šฉ (๋ฉ”๋ชจ๋ฆฌ 1GB..jenkins ๋ฐฐํฌ๋Š” ๋˜๊ธดํ•จ!..), aws linux ์ด์šฉ)
โ€ฃ pem key ์†Œ์ค‘ํ•˜๊ฒŒ ๋ณด๊ด€ํ•˜๋„๋กํ•˜๊ธฐ (ssh ํด๋”์— ์ด๋™์‹œํ‚ค๋Š” ๋“ฑ)

1-1. EC2 ๋ณด์•ˆ๊ทธ๋ฃน ์„ค์ •ํ•˜๊ธฐ (์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ ์„ค์ •)

EC2 > ์ธ์Šคํ„ด์Šค ํ™”๋ฉด
๋ณด์•ˆ๊ทธ๋ฃน > ์ธ๋ฐ”์šด๋“œ ๊ทœ์น™
์ธ๋ฐ”์šด๋“œ ๊ทœ์น™ ์„ค์ • (ํฌํŠธํ—ˆ์šฉ ์„ค์ •)



1-2. EC2 ์ธ์Šคํ„ด์Šค ์„œ๋ฒ„ ์ ‘์† ์‹œ๋„ (2๊ฐ€์ง€)

- pem key ์„ .ssh ํด๋”๋กœ ์˜ฎ๊ฒจ์ฃผ๋Š” ์ž‘์—…์„ ์ถ”๊ฐ€ํ•จ.

$ sudo mv {pem key ์œ„์น˜๊ฒฝ๋กœ}/jenkins.pem ~/.ssh

โญ๏ธ ์ฐธ๊ณ ๋กœ ์‹ค์Šต์˜ ์ƒํ™ฉ์ด๊ธฐ์— EC2 ์„œ๋ฒ„๋ฅผ ๋‚ด๋ฆฌ๊ณ  ์˜ฌ๋ฆฌ๋Š” ๊ฒฝ์šฐ๊ฐ€ ์กด์žฌํ•œ๋‹ค๋ฉด
[1. ssh ์œผ๋กœ ์ ‘์†ํ•˜๋Š” ๋ฐฉ๋ฒ•] ์œผ๋กœ ํ•˜๋Š”๊ฒƒ์ด ๋งž์„๋“ฏ. (IPv4๊ฐ€ ์„œ๋ฒ„ ์žฌ์‹œ์ž‘์‹œ ๋ฐ”๋€œ)

  1-2-1. ssh ์œผ๋กœ ์ ‘์†ํ•˜๋Š” ๋ฐฉ๋ฒ•

# ssh -i {pem key ๊ฒฝ๋กœ} {ec2 ์ธ์Šคํ„ด์Šค ๊ณ„์ •ID}@{ํผ๋ธ”๋ฆญ IPv4 DNS or ํผ๋ธ”๋ฆญ IPv4 IP}
$ ssh -i ~/.ssh/jenkins.pem ec2-user@ec2-2-3-4-5.ap-northeast-2.compute.amazonaws.com

# root ๊ถŒํ•œ์ด ์•„๋‹Œ ๊ฒฝ์šฐ 
$ sudo ssh -i ~/.ssh/jenkins.pem ec2-user@ec2-2-3-4-5.ap-northeast-2.compute.amazonaws.com

 

  1-2-2. ~/.ssh/config file ์— ์ ‘์†์ •๋ณด ์ถ”๊ฐ€ ํ›„, Host ๋ช…์œผ๋กœ ์ ‘์†ํ•˜๋Š” ๋ฐฉ๋ฒ•

$ vi ~/.ssh/config 

# ์—ด์–ด์„œ ์•„๋ž˜๋‚ด์šฉ ์ถ”๊ฐ€
Host test_jenkins

 User ec2-user
 HostName ec2-2-3-4-5.ap-northeast-2.compute.amazonaws.com
 IdentityFile ~/.ssh/jenkins.pem
 
# ๊ทธ๋ฆฌ๊ณ  ์ €์žฅ (:wq!)
 
# ์ ‘์†์‹œ๋„๋Š” ์•„๋ž˜์™€ ๊ฐ™์ด ํ•จ. (root ๊ถŒํ•œ ์•„๋‹Œ ๊ฒฝ์šฐ sudo ssh ~)
$ ssh test_jenkins

 

๐Ÿ’ฅ ๊ทธ๋Ÿฐ๋ฐ, Host ๋ช…์œผ๋กœ ์ ‘์† ์‹œ๋„์ค‘ ์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ๋‹ค๋ฉด ? 

> pem key ๊ถŒํ•œ์„ ๋ณ€๊ฒฝํ•ด์ฃผ๋‹ˆ ์ ‘์†์ด ๊ฐ€๋Šฅํ•จ! (chmod 400 ~ ๋‚˜์—๊ฒŒ๋งŒ ์ฝ๊ธฐ ๊ถŒํ•œ ์„ค์ •) 

 

2๏ธโƒฃ EC2 ์„œ๋ฒ„ ์ ‘์† ํ›„, ํ”„๋กœ๊ทธ๋žจ ์„ค์น˜ ๋ฐ ์„œ๋ฒ„ ์…‹ํŒ…

2-1. java ์„ค์น˜
   โ€ฃ ๋‚˜์˜ ๊ฒฝ์šฐ, aws linux์„ ์‚ฌ์šฉํ–ˆ๊ธฐ์— ํ•ด๋‹น๋ฌธ์„œ ← ๋ฅผ ์ฐธ๊ณ ํ•˜์—ฌ ์„ค์น˜ํ•จ 

2-2. ํƒ€์ž„์กด ๋ณ€๊ฒฝ (ํ•œ๊ตญ ์‹œ๊ฐ„)

$ sudo rm /etc/localtime
$ sudo ln -s /usr/share/zoneinfo/Asia/Seoul /etc/localtime

# ๋‚ ์งœ ํ™•์ธ
$ date


2-3. ํ˜ธ์ŠคํŠธ๋„ค์ž„ ๋ณ€๊ฒฝ

$ sudo hostnamectl set-hostname mungmang-jenkins
$ sudo reboot

# ๋ช‡๋ถ„ ํ›„ ๋‹ค์‹œ์ ‘์†

# ํ™•์ธ
$ hostname


2-4. jenkins ์„ค์น˜

# jenkins repository ์— ์„ค์ •ํŒŒ์ผ ์ƒ์„ฑ 
$ sudo wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo
$ sudo rpm --import https://pkg.jenkins.io/redhat-stable/jenkins.io.key

# jenkins ์„ค์น˜
$ sudo yum install jenkins

# jenkins ์‹คํ–‰
$ sudo systemctl start jenkins

# ๋งŒ์•ฝ ๋ถ€ํŒ…์‹œ ๊ฐ€๋Šฅํ•˜๊ฒŒ ์„ค์ •ํ•˜๋ ค๋ฉด ๋‹ค์Œ๋„ ์ถ”๊ฐ€
$ sudo systemctl enable jenkins

 

 

2-5. jenkins ์ ‘์† ๋ฐ ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜

๋นจ๊ฐ„๋ฐ•์Šค ๊ฒฝ๋กœ์˜ ๊ฐ’์„ ํ™•์ธํ•˜์—ฌ ์ž…๋ ฅํ•ด์ฃผ๊ธฐ
ํ•œ๊ธ€๋กœ ๋ฒˆ์—ญํ•จ. ์ถ”์ฒœ ํ”Œ๋Ÿฌ๊ทธ์ธ์„ ์„ค์น˜ํ•˜์˜€์Œ. (๋ญ๊ฐ€ ํ•„์š”ํ•œ์ง€๋ฅผ ์ •ํ™•ํ•˜๊ฒŒ ๋ชจ๋ฅด๊ธฐ ๋•Œ๋ฌธ!)


.. ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ ํ›„,
jenkins ์œ ์ € ๋“ฑ๋ก ํ™”๋ฉด์—์„œ ๋กœ๊ทธ์ธํ•  ๊ณ„์ •์ •๋ณด ์ž…๋ ฅ ↓  ↓ (๊ณ„์ •๋ช… ๋ฐ ์•”ํ˜ธ๋กœ jenkins ๋กœ๊ทธ์ธ ๊ฐ€๋Šฅ!)

 


2-6. gradle ์„ค์น˜ https://docs.gradle.org/6.9.1/userguide/installation.html ์ฐธ๊ณ ํ•จ

$ mkdir /opt/gradle
$ unzip -d /opt/gradle gradle-6.9.1-bin.zip
$ ls /opt/gradle/gradle-6.9.1

$ export PATH=$PATH:/opt/gradle/gradle-6.9.1/bin
$ gradle -version

 

2-7. git ์„ค์น˜ https://gamoo12.tistory.com/205 ์ฐธ๊ณ ํ•จ

$ sudo yum update -y
$ sudo yum install git -y
$ git version

 

3๏ธโƒฃ github ์„ค์ •

3-0. ๋ฐ˜์˜ํ•  ํ”„๋กœ์ ํŠธ๋Š” ์žˆ๋‹ค๊ณ  ๊ฐ€์ • (์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ)
3-1. EC2์—์„œ ssh key ์ƒ์„ฑ

$ cd ~/.ssh
$ ssh-keygen

# id_rsa key ์ƒ์„ฑ



3-2. github project ๋‚ด XXX.pub key ๋“ฑ๋ก ํ•„์š”

    3-2-1. https://github.com/{git๊ณ„์ •}/{gitํ”„๋กœ์ ํŠธ}/settings/keys/new ์ด๋™ 

$ cat ~/.ssh/id_rsa.pub

# ssh-rsa ~ ๋‚ด์šฉ์„ ๋ณต์‚ฌ

github > ํ”„๋กœ์ ํŠธ > Settings > Deploy keys > Add deploy key


3-3. github ํ”„๋กœ์ ํŠธ ๋‚ด webhook ์„ค์ •ํ•„์š”
    3-2-1.https://github.com/{git๊ณ„์ •}/{gitํ”„๋กœ์ ํŠธ}/settings/hooks/new ์ด๋™ 
        • Payload URL : http://{ec2์— jenkins ๋„์šด ์ฃผ์†Œ (ex. ec2~~:8080}/github-webhook/ ์ž…๋ ฅ
        • Content type :  application/json

jenkins์—์„œ build ๋ฒ„ํŠผ ํด๋ฆญ์‹œ, github์˜ webhook ๊ธฐ๋Šฅ ์ด์šฉํ•˜์—ฌ ์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ ํ”„๋กœ์ ํŠธ๋ฅผ ๋•ก๊ฒจ๊ฐ€๋„๋ก ํ• ๊ฒƒ์ž„

 

4๏ธโƒฃ jenkins ์„ค์ •

1. Credentials ๋“ฑ๋ก ํ•„์š” (github ๐Ÿ”› jenkins ์—ฐ๊ฒฐ์œ ๋„)

Jenkins ๊ด€๋ฆฌ > Manage Credentials > Stores scoped Jenkins ์˜ Jenkins ํด๋ฆญ > Global credentials
 
Kind : SSH Username with private key ์„ ํƒ
Private Key: .ssh/id_rsa ์„ ์ž…๋ ฅ

 

2. ๋นŒ๋“œ ๋ฐ ์‹คํ–‰ (Dashboard > ๋Œ€์ƒ ํ”„๋กœ์ ํŠธ > ๊ตฌ์„ฑ) 

๋นŒ๋“œ์œ ๋ฐœ
GitHub hook trigger for GITScm polling ์„ ํƒ 

[ํ”Œ๋Ÿฌ๊ทธ์ธ ์„ค์น˜ ํ•„์š”] post build task (์•„๋ž˜์˜ ๋‚ด์šฉ ๊ธฐ์ž…, ์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ jar ํŒŒ์ผ๋กœ ๋งŒ๋“  ๊ฒƒ์„ ์‹คํ–‰)
JAR=$(ls -tr /var/lib/jenkins/workspace/{jenkins working directory ๋ช…}/build/libs | grep jar | tail -n 1)
echo $JAR
nohup java -jar /var/lib/jenkins/workspace/{jenkins working directory ๋ช…}/build/libs/$JAR &

$(ls -tr /var/lib/jenkins/workspace/{jenkins working directory ๋ช…}/build/libs | grep jar | tail -n 1) : jar ํŒŒ์ผ๋ช… ์ถ”์ถœ ์œ„ํ•จ.
nohup java -jar /var/lib/jenkins/workspace/{jenkins working directory ๋ช…}/build/libs/$JAR & : jar ์‹คํ–‰์œ„ํ•จ, nohup ์„ ๋ถ™์ž„์œผ๋กœ์จ ๋ฐฑ๊ทธ๋ผ์šด๋“œ์—์„œ ์‹คํ–‰! (ํ„ฐ๋ฏธ๋„ ์ข…๋ฃŒ ํ•˜๋”๋ผ๋„ ์ž‘์—… ๊ฒฐ๊ณผ๋ฌผ์€ ๊ณ„์† ์„œ๋ฒ„์— ์‹คํ–‰๋˜์–ด ์žˆ๋„๋ก ํ•˜๊ธฐ์œ„ํ•จ)

 

 

๋Š๋‚€์ 

โ€ฃ ์‚ฝ์งˆ์„ ์ค„์ผ ํ•„์š”์„ฑ์ด์žˆ๊ฒ ๋‹ค.
โ€ฃ ํŒŒ์ดํ”„๋ผ์ธ ์ž‘์„ฑ์„ ์ด์šฉํ•œ ๋ฐฐํฌ๋„ ํ•œ๋ฒˆ ํ•ด๋ณด์•„์•ผ ํ• ๊ฒƒ๊ฐ™๋‹ค. 
โ€ฃ docker..kubernetes ๋“ฑ์„ ์ด์šฉํ•œ ๋ฐฐํฌ๋ฐฉ๋ฒ•๋„ ํ•ด๋ณด์•„์•ผ ํ• ๊ฒƒ๊ฐ™๋‹ค. + ๋‹ค๋ฅธ ์„œ๋ฒ„์— ๋ฐฐํฌํ•˜๋Š” ๋ฐฉ๋ฒ• ๋“ฑ 

 


์ฐธ๊ณ 

์ฑ…: ์Šคํ”„๋ง ๋ถ€ํŠธ์™€ AWS๋กœ ํ˜ผ์ž ๊ตฌํ˜„ํ•˜๋Š” ์›น ์„œ๋น„์Šค

 

์Šคํ”„๋ง ๋ถ€ํŠธ์™€ AWS๋กœ ํ˜ผ์ž ๊ตฌํ˜„ํ•˜๋Š” ์›น ์„œ๋น„์Šค - YES24

๊ฐ€์žฅ ๋น ๋ฅด๊ณ  ์‰ฝ๊ฒŒ ์›น ์„œ๋น„์Šค์˜ ๋ชจ๋“  ๊ณผ์ •์„ ๊ฒฝํ—˜ํ•œ๋‹ค. ๊ฒฝํ—˜์ด ์‹ค๋ ฅ์ด ๋˜๋Š” ์ˆœ๊ฐ„!์ด ์ฑ…์€ ์ œ๋ชฉ ๊ทธ๋Œ€๋กœ ์Šคํ”„๋ง ๋ถ€ํŠธ์™€ AWS๋กœ ์›น ์„œ๋น„์Šค๋ฅผ ๊ตฌํ˜„ํ•œ๋‹ค. JPA์™€ JUnit ํ…Œ์ŠคํŠธ, ๊ทธ๋ ˆ์ด๋“ค, ๋จธ์Šคํ…Œ์น˜, ์Šคํ”„๋ง

www.yes24.com

๋งํฌ: https://lemontia.tistory.com/656

 

[Linux] centos7 ์  ํ‚จ์Šค ์„ค์น˜

1. jenkins repository๋ฅผ ์„ค์ •ํŒŒ์ผ์„ ์ƒ์„ฑ wget -O /etc/yum.repos.d/jenkins.repo https://pkg.jenkins.io/redhat-stable/jenkins.repo 2. /etc/yum.repos.d/jenkins.repo ๊ฒฝ๋กœ์— ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์•˜๋Š”์ง€ ํ™•์ธ..

lemontia.tistory.com

 

๋ฐ˜์‘ํ˜•

+ Recent posts