/ci-cd-demo

CI/CD samples with Github Actions

Primary LanguageJava

CI-CD-Demo

๐Ÿ˜ƒํ•ด๋‹น ๋ฆฌํฌ์ง€ํ† ๋ฆฌ๋Š” Github Action์„ ์‚ฌ์šฉํ•˜์—ฌ ๊ฐ„๋‹จํ•œ CI/CD ํŒŒ์ดํ”„๋ผ์ธ์„ ๊ตฌ์„ฑํ•˜๊ธฐ ์œ„ํ•œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ์ž…๋‹ˆ๋‹ค.
๊ฐœ์ธ ์‹ค์Šต์šฉ์œผ๋กœ ์ƒ์„ฑ ํ•˜์˜€๊ธฐ์— ์ž˜๋ชป๋œ ๋ถ€๋ถ„์ด ์กด์žฌํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค, ์ฐธ๊ณ  ํ•ด์ฃผ์„ธ์š”.
์ถ”๊ฐ€์ ์œผ๋กœ Github Action์— ๋Œ€ํ•œ ๋ถ€๋ถ„์€ ์ƒ๋žตํ•˜์˜€์œผ๋‹ˆ ์†Œ์Šค๋ฅผ ์ฐธ๊ณ  ํ•ด์ฃผ์„ธ์š”!

01. ๐Ÿ”จ ์‚ฌ์šฉ ์Šคํƒ

๊ธฐ์ˆ  ๋ฒ„์ „
Java 17
Spring Boot 3.2.2
Docker 23.0.5
AWS EC2 Amazon Linux 2
AWS Code Deploy X

02. ๐Ÿ”ฅ ํ๋ฆ„ ์ •๋ฆฌ

  1. ๊ฐ„๋‹จํ•œ REST API ์ƒ์„ฑ
  2. Dockerfile ์ž‘์„ฑ
  3. Github Action Script ์ž‘์„ฑ(CI/CD)
  4. EC2 ์ƒ์„ฑ ํ›„ ๋ฐฐํฌ ์ง„ํ–‰

03. TEST REST API ๊ตฌ์„ฑ

@Slf4j
@RestController
public class CiCdController {

    @Value("${app.version:1.0.0}")
    private String version;

    @GetMapping("/")
    public ResponseEntity<Response> init(
            @RequestHeader Map<String, String> headerMap,
            @RequestHeader("host") String host) {

        log.info("Hello CICD! version = {}", version);
        log.info("headerMap = {}, host = {}", headerMap, host);

        return ResponseEntity
                .status(HttpStatus.OK)
                .body(Response.builder()
                        .version(version)
                        .host(host)
                        .build()
                );
    }

    @Data
    @Builder
    public static class Response {
        private final String version;
        private final String host;
    }
}
{
  "version": "1.0.0",
  "host": "localhost:8080"
}
  • ํ…Œ์ŠคํŠธ๋ฅผ ์œ„ํ•œ ๊ฐ„๋‹จํ•œ REST API ์ƒ์„ฑ
  • ๋‹ค๋ฅธ๊ฑด ์—†๊ณ  ์œ„์™€ ๊ฐ™๋‹ค app version ๊ณผ host ์ •๋ณด๋ฅผ ๋ฐ˜ํ™˜ํ•œ๋‹ค

04. Dockerfile ๊ด€๋ จ ์ •๋ฆฌ