๐Ÿณ SpringBoot + Docker + DockerCompose๋ฅผ ์ด์šฉํ•œ AWS EC2 ๋ฐฐํฌํ•˜๊ธฐ

์ดํ•˜์–€ยท2023๋…„ 11์›” 30์ผ
1

๐Ÿš— Humax Dreamverse Company Internship

๋ชฉ๋ก ๋ณด๊ธฐ
2/6
post-thumbnail

0. ํ™˜๊ฒฝ

  • ์Šคํ”„๋ง๋ถ€ํŠธ ๋ฒ„์ „ : 2.7.17
  • ํˆด : IntelliJ IDEA CE
  • JDK : 17
  • ์‚ฌ์šฉํ•˜๊ณ  ์žˆ๋Š” ์ปดํ“จํ„ฐ ์ •๋ณด : Macbook Pro(Apple M2 Pro)

1. ์‚ฌ์ „ ์ค€๋น„

๐Ÿงฉ SpringBoot

โ˜ƒ๏ธ SpringBoot jar ํŒŒ์ผ ์ƒ์„ฑํ•˜๊ธฐ

  • Docker์— ์Šคํ”„๋ง๋ถ€ํŠธ๋กœ ์ž‘์„ฑํ•œ ํ”„๋กœ์ ํŠธ๋ฅผ ์˜ฌ๋ฆฌ๋ ค๋ฉด ๋จผ์ € jar file์„ ์ƒ์„ฑํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

๐Ÿง jar file์ด ๋ญ์ฃ ?

  • Java ARchive Files๋ฅผ ์˜๋ฏธํ•˜๋ฉฐ, ์ผ์ข…์˜ ์ž๋ฐ” ํ”„๋กœ์ ํŠธ ์••์ถ• ํŒŒ์ผ์„ ๋œปํ•˜๊ธฐ ๋•Œ๋ฌธ์—, zip๊ณผ ์œ ์‚ฌํ•˜๋‹ค๊ณ  ์ดํ•ดํ•˜์‹œ๋ฉด ์ข‹์Šต๋‹ˆ๋‹ค.
  • .jar์˜ ํ™•์žฅ์ž๋ฅผ ๊ฐ€์ง„ ํŒŒ์ผ์€ ํ”„๋กœ์ ํŠธ์—์„œ ๊ฐ€์žฅ ์ค‘์š”ํ•œ ์ปดํŒŒ์ผ๋œ .class ํŒŒ์ผ์„ ๊ฐ€์ง€๊ณ  ์žˆ๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  • ์šฐ๋ฆฌ๊ฐ€ ์Šคํ”„๋ง๋ถ€ํŠธ๋กœ ๊ฐœ๋ฐœ์„ ํ•˜๊ฒŒ ๋˜๋ฉด, build.gradle ๋“ฑ์˜ ํŒŒ์ผ์— ์—ฌ๋Ÿฌ๊ฐ€์ง€ ์˜์กด์„ฑ์„ ์„ค์ •ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค.
  • ์ด๋•Œ jar ํŒŒ์ผ ๋‚ด๋ถ€์— ์ด ์˜์กด์„ฑ์„ ๋ชจ๋‘ ํฌํ•จ์‹œํ‚ค๊ธฐ ๋•Œ๋ฌธ์— ์‰ฝ๊ฒŒ ๋ฐฐํฌ์— ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒƒ์ž…๋‹ˆ๋‹ค.
  • ๊ทธ๋Ÿผ, ์Šคํ”„๋ง๋ถ€ํŠธ ํ”„๋กœ์ ํŠธ๋ฅผ ์ž‘์„ฑํ•œ IntelliJ์—์„œ jar ํŒŒ์ผ์„ ๋งŒ๋“œ๋Š” ๋ฐฉ๋ฒ•์„ ์†Œ๊ฐœํ•ด๋ณด๋„๋ก ํ• ๊ฒŒ์š”!

1. IntelliJ์˜ ์˜ค๋ฅธ์ชฝ ๋ > gradle > bulid ํด๋” ์ ‘๊ทผ

2. BootJar ๋”๋ธ” ํด๋ฆญ์œผ๋กœ jar ํŒŒ์ผ ์ƒ์„ฑ

  • โš™๏ธBootJar ๋”๋ธ” ํด๋ฆญ


3. Project > {ํ”„๋กœ์ ํŠธ ์ตœ์ƒ์œ„ ํด๋”} > bulid > libs ํด๋” ๋‚ด๋ถ€์— jar ํŒŒ์ผ์— ์ƒ์„ฑ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ


๐Ÿ˜… ๋งŒ์•ฝ jar ํŒŒ์ผ์ด ....jar์™€ ํ•จ๊ป˜ ...plain.jar๊ฐ€ ์ €์žฅ๋˜์—ˆ์„ ๊ฒฝ์šฐ์—๋Š” ๋นŒ๋“œ ์‹œ์— ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•  ์ˆ˜ ์žˆ์–ด์š”!

  • ํ•ด๊ฒฐ ๋ฐฉ๋ฒ• : ์šฐ์„  ์ƒ์„ฑํ•œ jar ํŒŒ์ผ 2๊ฐœ๋ฅผ ์‚ญ์ œํ•˜๊ณ , build.gradle์— ๋‹ค์Œ์„ ํฌํ•จํ•ด์ค€๋‹ค์Œ ๋‹ค์‹œ jar ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ฃผ๊ธฐ
  • ์ถœ์ฒ˜ : Plain jar vs Executable jar(feat. plain jar ์ƒ์„ฑ ๋ฐฉ์ง€)
...
jar {
	enabled = false
}
...

  • ์œ„์˜ ๋ฐฉ๋ฒ•์„ ๋”ฐ๋ผํ•˜์‹œ๋ฉด ํŽธํ•˜๊ฒŒ {ํŒจํ‚ค์ง€๋ช…}-0.0.1-SNAPSHOT.jar ํ˜•ํƒœ์˜ jar ํŒŒ์ผ์„ ์ƒ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

๐Ÿณ Docker

โ˜ƒ๏ธ Mac์— Docker ์„ค์น˜ํ•˜๊ธฐ

1. Docker ํ™ˆํŽ˜์ด์ง€์—์„œ dmg ๋‹ค์šด๋กœ๋“œ

  • ์ œ ๊ฒฝ์šฐ M2 ์นฉ์ด๊ธฐ ๋•Œ๋ฌธ์— Docker Desktop Mac With Apple sillicon ํด๋ฆญํ•ด ๋‹ค์šด๋กœ๋“œ ํ–ˆ์Šต๋‹ˆ๋‹ค.
    (Windows ์œ ์ €์˜ ๊ฒฝ์šฐ ์™ผ์ชฝ ์•„๋ž˜์˜ "Install on Windows"์—์„œ ์ง„ํ–‰)


2. ๋‹ค์šด๋ฐ›์€ dmg ์—ด์–ด์„œ Applications์— ์ถ”๊ฐ€ํ•˜๊ธฐ


3. Terminal์—์„œ Docker ๋ฒ„์ „ ํ™•์ธ

  • ๋ช…๋ น์–ด : docker -v
  • ๋ฒ„์ „ ์ •๋ณด๊ฐ€ ๋‚˜์˜ค๋ฉด ์„ฑ๊ณต์ž…๋‹ˆ๋‹ค!

2. Dockerfile Build & Run

๐Ÿ—‚๏ธ Dockerfile

  • Dockerfile์„ ํ†ตํ•ด์„œ jar ํŒŒ์ผ์„ ์˜ฌ๋ฆฌ๊ณ  ์‹คํ–‰ํ•  ์˜ˆ์ •
  1. IntelliJ > {ํ”„๋กœ์ ํŠธ ์ตœ์ƒ์œ„ ํด๋”}์— Dockerfile ๋งŒ๋“ค๊ธฐ


  2. ๋‹ค์Œ ๋‚ด์šฉ ์ž‘์„ฑํ•˜๊ณ  ์ €์žฅํ•˜๊ธฐ


๋‹ค์Œ ๋‚ด์šฉ์€ ๊ฐœ์ธ ์„ค์ •์ด๋ฏ€๋กœ 4๋ฒˆ์œผ๋กœ ๋„˜์–ด๊ฐ€์ฃผ์„ธ์š”!
(3. ํ™˜๊ฒฝ๋ณ€์ˆ˜ ํŽธ์ง‘ํ•˜๊ธฐ)

  1. โš™๏ธ BootJar ํ•œ๋ฒˆ ๋” ๋”๋ธ”ํด๋ฆญํ•ด์„œ ๋นŒ๋“œํ•ด์ฃผ๊ธฐ

  2. IntellJ์˜ ํ„ฐ๋ฏธ๋„์—์„œ ๋‹ค์Œ ์‹คํ–‰

  • ๋„์ปค๋ฅผ ๋นŒ๋“œ(์ด๋ฏธ์ง€ ์ƒ์„ฑ)
    docker build -t hayannn/parking_server:1 ./

  • ๋„์ปค ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
    docker run -it -p8080:8080 hayannn/parking_server:1

  1. Docker Desktop์—์„œ ํ™•์ธ
  • ์ด๋ฏธ์ง€ ํ™•์ธ

  • ์ปจํ…Œ์ด๋„ˆ ํ™•์ธ

  1. ๋นŒ๋“œ ์„ฑ๊ณต!

  2. ํฌ๋กฌ์—์„œ ํ™•์ธ(ํ•„์š”ํ•œ ๊ฒฝ์šฐ)

    -> ์ž˜ ๋ฆฌ๋‹ค์ด๋ ‰ํŒ…๋จ ํ™•์ธ!

  1. ์ข…๋ฃŒํ•˜๊ณ  ์‹ถ๋‹ค๋ฉด?
  • ๋ช…๋ น์–ด ์‹คํ–‰ํ•ด๋„ ๋˜์ง€๋งŒ, ๊ธฐ์™• Docker Desktop์ด ์žˆ๋Š” ๊น€์— ์—ฌ๊ธฐ์„œ ์ •์ง€!
  1. ์ข…๋ฃŒ ํ™•์ธ

3. Docker-compose ์‚ฌ์šฉํ•˜๊ธฐ

docker-compose.yml

version: '3'

services:
  web:
    container_name: web
    image: {docker username}/{docker ์ด๋ฏธ์ง€ ์ด๋ฆ„}
    expose:
      - "8080"
    ports:
      - "3000:8080"

ํ˜„์žฌ ์ €ํฌ๋Š” 3000๋ฒˆ ํฌํŠธ๋ฅผ ํ†ตํ•ด ์™ธ๋ถ€์—์„œ ์„œ๋ฒ„ API์— ์ ‘๊ทผํ•˜๊ธฐ ๋•Œ๋ฌธ์— expose ์„ค์ •์„ ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.


4. Github Actions๋กœ CI/CD ๋ฐฐํฌ ์ž๋™ํ™” ์ง„ํ–‰

์ฐธ๊ณ  ๋ ˆํผ๋Ÿฐ์Šค : ์ฝ”๋“œ Push๋กœ ๋ฐฐํฌ๊นŒ์ง€! Spring Boot + Github Actions + Docker
๊ทธ ๋‹ค์Œ Github Actions๋ฅผ ์‚ฌ์šฉํ•˜๊ธฐ ์œ„ํ•ด ์ƒˆ๋กœ์šด ํŒจํ‚ค์ง€๋ฅผ ๋งŒ๋“ค์–ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

  1. ์ธํ…”๋ฆฌ์ œ์ด์—์„œ ๋ฃจํŠธ ํด๋”์— .github ํด๋”๋ฅผ ๋งŒ๋“ค๊ณ , ๊ทธ ์•ˆ์— workflows ํด๋”๋ฅผ ๋งŒ๋“ค์–ด ์ค๋‹ˆ๋‹ค.

  2. ๊ทธ ๋‹ค์Œ ~~~.yml ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด์ค€ ๋‹ค์Œ, ๋‹ค์Œ ๋‚ด์šฉ์„ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.
    ์•„์ง commit ํ•˜์ง€ ๋งˆ์„ธ์š”!
    ์˜ˆ์‹œ) deploy.yml

name: CD with Gradle

on:
  push:
    branches: [ "์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๋ธŒ๋žœ์น˜ ์ด๋ฆ„" ]


permissions:
  contents: read


jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: checkout
        uses: actions/checkout@v3


      - name: Set up JDK 17
        uses: actions/setup-java@v3
        with:
          java-version: '17'
          distribution: "adopt"


      - name: Make application.yml
        run: |
          cd ./src/main/resources
          touch ./application.yml
          echo "${{ secrets.PROPERTIES }}" > ./application.yml
        shell: bash

      - name: Build with Gradle
        run: |
          chmod +x ./gradlew
          ./gradlew clean build -x test

      - name: Docker build & push to docker repo
        run: |
          docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
          docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} .
          docker push ${{ secrets.DOCKER_REPO }}

      - name: Deploy to server
        uses: appleboy/ssh-action@master
        id: deploy
        with:
          host: ${{ secrets.HOST }}
          username: ec2-user
          key: ${{ secrets.KEY }}
          envs: GITHUB_SHA
          script: |
            sudo docker rm -f $(docker ps -qa)
            sudo docker pull ${{ secrets.DOCKER_REPO }}
            docker-compose up -d
            docker image prune -f

  1. ํ™˜๊ฒฝ๋ณ€์ˆ˜๋กœ ์ง€์ •ํ•œ ๊ฐ’๋“ค์„ ๋‹ค์ด๋ ‰ํŒ…ํ•ด์ฃผ๊ธฐ ์œ„ํ•ด ๊นƒํ—ˆ๋ธŒ ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ > settings > Security > Actions์—์„œ ๊ฐ ๊ฐ’์„ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.

    DOCKER_PASSWORD : ๋„์ปค ๋กœ๊ทธ์ธ ์‹œ ๋น„๋ฐ€๋ฒˆํ˜ธ
    DOCKER_REPO : ๋„์ปค์˜ ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ ์ด๋ฆ„
    DOCKER_USERNAME : ๋„์ปค ๋กœ๊ทธ์ธ ์‹œ ์ด๋ฆ„ ๋˜๋Š” ์ด๋ฉ”์ผ
    HOST : AWS EC2 IP
    KEY : AWS EC2 ์ƒ์„ฑ ์‹œ ์‚ฌ์šฉํ•œ pem ํ‚ค
    (pem ํ‚ค๋ฅผ ๋ฉ”๋ชจ์žฅ ๋“ฑ์œผ๋กœ ์—ด์–ด ๋‚ด์šฉ์„ ๋ชจ๋‘ ๋ณต์‚ฌ-๋ถ™์—ฌ๋„ฃ๊ธฐ ํ•ด์ฃผ์–ด์•ผ ํ•จ)

  2. ์ด์ œ ์•ž์„œ ์ž‘์„ฑํ•œ ~~~.yml๋ฅผ commit&push ํ•ด์ค๋‹ˆ๋‹ค.

on:
  push:
    branches: [ "์‚ฌ์šฉํ•˜๊ณ ์ž ํ•˜๋Š” ๋ธŒ๋žœ์น˜ ์ด๋ฆ„" ]

๋‹ค์Œ๊ณผ ๊ฐ™์ด ์„ค์ •ํ•ด์ฃผ์—ˆ๊ธฐ ๋•Œ๋ฌธ์—, push ์‹œ์— Github Actions์—์„œ ๊ฐ์ง€ํ•˜๊ณ  ๋ฐฐํฌ๋ฅผ ์ง„ํ–‰ํ•˜๊ฒŒ ๋ฉ๋‹ˆ๋‹ค!

  1. ๋ฐฐํฌ ํ™•์ธ
    ๊นƒํ—ˆ๋ธŒ ๋ ˆํฌ์ง€ํ„ฐ๋ฆฌ > Actions > All workflows์—์„œ ์›ํ•˜๋Š” ์ปค๋ฐ‹ ๊ธฐ๋ก์„ ํด๋ฆญํ•ด ํ™•์ธํ•ฉ๋‹ˆ๋‹ค.

์‚ฌ์ง„์—์„œ ์–ด๋ ดํ’‹์ด ๋ณด์ด๋“ฏ, ์ด ๋ถ€๋ถ„์—์„œ ์—๋Ÿฌ๊ฐ€ ๋ฐœ์ƒํ•ด ์‹œ๊ฐ„์„ ๋งŽ์ด ์ผ๋Š”๋ฐ์š”!

์ž์„ธํ•œ ๋‚ด์šฉ์€ ์•„๋ž˜์˜ 2๊ฐ€์ง€ ํŠธ๋Ÿฌ๋ธ”์ŠˆํŒ…์œผ๋กœ ์†Œ๊ฐœํ•˜๋„๋ก ํ•˜๊ฒ ์Šต๋‹ˆ๋‹ค.

๐Ÿš€ ์ฒซ๋ฒˆ์งธ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…

  • ERROR: invalid tag "***/์ด๋ฏธ์ง€์ด๋ฆ„:ํƒœ๊ทธ": invalid reference format


-> Docker์— ๋กœ๊ทธ์ธ์€ ์„ฑ๊ณต์ ์œผ๋กœ ๋˜์—ˆ์ง€๋งŒ, ์‹ค์ œ image:ํƒœ๊ทธ๋ฅผ ํ™•์ธํ•˜์ง€ ๋ชปํ•˜๋Š” ๊ฒƒ์œผ๋กœ ๋ณด๊ณ  ํ•ด๊ฒฐ์ ์„ ์ฐพ์•„๋ณด์•˜์Šต๋‹ˆ๋‹ค.

์ด์ „์˜ deploy.yml ํŒŒ์ผ ์ผ๋ถ€

 - name: Docker build & push to docker repo
        run: |
          docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
          docker build -f Dockerfile -t ${{ secrets.DOCKER_USERNAME }}/์ด๋ฏธ์ง€์ด๋ฆ„:ํƒœ๊ทธ .
          docker push ${{ secrets.DOCKER_USERNAME }}/์ด๋ฏธ์ง€์ด๋ฆ„:ํƒœ๊ทธ
      ...
          script: |
            sudo docker rm -f $(docker ps -qa)
            sudo docker pull ${{ secrets.DOCKER_USERNAME }}/์ด๋ฏธ์ง€์ด๋ฆ„:ํƒœ๊ทธ
            docker-compose up -d
            docker image prune -f

๐Ÿ˜€ํ•ด๊ฒฐ

/์ด๋ฏธ์ง€์ด๋ฆ„:ํƒœ๊ทธ๋ถ€๋ถ„์„ ๋ณด๋ฉด, ํ˜„์žฌ ์ €ํฌ๊ฐ€ ๋ถˆ๋Ÿฌ์˜ค๊ณ ์ž ํ•˜๋Š” docker image์™€์˜ ๋งค์นญ์ด ์•ˆ๋˜๋Š” ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ•œ ๊ฒƒ์œผ๋กœ ํŒ๋‹จํ–ˆ์Šต๋‹ˆ๋‹ค.
๋˜ํ•œ, ๊ทธ ์•ž์˜ ${{ secrets.DOCKER_USERNAME }}์„ ${{ secrets.DOCKER_REPO }}๋กœ ์ˆ˜์ •ํ•ด์ฃผ์—ˆ์Šต๋‹ˆ๋‹ค.

๋ณ€๊ฒฝ ํ›„ deploy.yml

      - name: Docker build & push to docker repo
        run: |
          docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }}
          docker build -f Dockerfile -t ${{ secrets.DOCKER_REPO }} .
          docker push ${{ secrets.DOCKER_REPO }}

      - name: Deploy to server
        uses: appleboy/ssh-action@master
        id: deploy
        with:
          host: ${{ secrets.HOST }}
          username: ec2-user
          key: ${{ secrets.KEY }}
          envs: GITHUB_SHA
          script: |
            sudo docker rm -f $(docker ps -qa)
            sudo docker pull ${{ secrets.DOCKER_REPO }}
            docker-compose up -d
            docker image prune -f

๐Ÿš€ ๋‘๋ฒˆ์งธ ํŠธ๋Ÿฌ๋ธ” ์ŠˆํŒ…

  • ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

์ด์ œ ์„ฑ๊ณต์ ์œผ๋กœ Docker๋ฅผ ๋ถˆ๋Ÿฌ์˜ค์ง€๋งŒ, ์ด๋ฒˆ์—๋Š” ์„œ๋ฒ„ ์ •๋ณด๋ฅผ ๋ถˆ๋Ÿฌ์˜ค๋Š”๋ฐ์— ๋ฌธ์ œ๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค๐Ÿ˜‚
์ด ๋ถ€๋ถ„์„ ํ•ด๊ฒฐ์€ ์•„์ฃผ ๊ฐ„๋‹จํ–ˆ๋Š”๋ฐ์š”!
์ €ํฌ๋Š” ํ˜„์žฌ ์—…๋ฌด๋ฅผ ์œ„ํ•ด ๋ถ€์—ฌ๋ฐ›์€ EC2 ์„œ๋ฒ„์—์„œ ์ž‘์—…์„ ํ•ด์•ผ ํ•˜๋Š”๋ฐ, ์ด EC2 ์„œ๋ฒ„๊ฐ€ Ubuntu๊ฐ€ ์•„๋‹Œ Amazon Linux 2์˜€์Šต๋‹ˆ๋‹ค.
๊ทธ๋ ‡๊ธฐ ๋•Œ๋ฌธ์— ๋‹ค์‹œ ํ•œ๋ฒˆ deploy.yml ํŒŒ์ผ์—์„œ ์ˆ˜์ •์ด ํ•„์š”ํ–ˆ์Šต๋‹ˆ๋‹ค..!!
๋ณ€๊ฒฝ ์ด์ „ deploy.yml ์ค‘ ์„œ๋ฒ„์— ์—ฐ๊ฒฐํ•˜๋Š” "Deploy to server" ๋ถ€๋ถ„

      - name: Deploy to server
        uses: appleboy/ssh-action@master
        id: deploy
        with:
          host: ${{ secrets.HOST }}
          username: ubuntu
          key: ${{ secrets.KEY }}
          envs: GITHUB_SHA
          script: |
            sudo docker rm -f $(docker ps -qa)
            sudo docker pull ${{ secrets.DOCKER_REPO }}
            docker-compose up -d
            docker image prune -f

๋ณ€๊ฒฝ ์ด์ „์˜ yml์„ ๋ณด๋ฉด, ๋‹ค์Œ๊ณผ ๊ฐ™์ด username์ด ubuntu๋กœ ๋˜์–ด์žˆ๋Š” ๊ฒƒ์„ ํ™•์ธํ•˜์‹ค ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
์ด๊ฒƒ์ด ๋ฌธ์ œ๊ฐ€ ๋˜๋Š” ์ด์œ ๋Š” ubuntu๋ฅผ ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์„œ๋ฒ„์™€ ๋‹ฌ๋ฆฌ amazon linux 2๋Š” ๊ธฐ๋ณธ ์œ ์ € ์ด๋ฆ„์ด ec2-user์ด๊ธฐ ๋•Œ๋ฌธ์ž…๋‹ˆ๋‹ค.
๋”ฐ๋ผ์„œ, yml์„ ํ†ตํ•ด AWS EC2 ์„œ๋ฒ„๊ฐ€ ์‚ฌ์šฉ์ž๋ฅผ ์ธ์‹ํ•˜๊ธฐ ์œ„ํ•ด ์ด ๋ถ€๋ถ„์„ ec2-user๋กœ ๋ฐ”๊ฟ”์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค!
์„œ๋ฒ„์— ๋”ฐ๋ฅธ ์œ ์ €์˜ ๋””ํดํŠธ ์ด๋ฆ„ ์ฐพ๊ธฐ
๋ณ€๊ฒฝ ํ›„

      - name: Deploy to server
        uses: appleboy/ssh-action@master
        id: deploy
        with:
          host: ${{ secrets.HOST }}
          username: ec2-user
          key: ${{ secrets.KEY }}
          envs: GITHUB_SHA
          script: |
            sudo docker rm -f $(docker ps -qa)
            sudo docker pull ${{ secrets.DOCKER_REPO }}
            docker-compose up -d
            docker image prune -f

์ž, ๊ทธ๋Ÿผ ์ด์ œ ๋‹ค์‹œ ์ž˜ ๋˜๋Š”์ง€ ํ™•์ธํ•ด๋ณผ๊นŒ์š”?

์ž˜ ์ง„ํ–‰๋˜์—ˆ์Šต๋‹ˆ๋‹ค!

๐Ÿณ ๊ฒฐ๊ณผ

์‹ค์ œ๋กœ ๋ถ€์—ฌ๋ฐ›์€ ip๋ฅผ ํ†ตํ•ด ์ ‘์†ํ•ด๋ดค์Šต๋‹ˆ๋‹ค.
์„ฑ๊ณต์ ์œผ๋กœ ์ž˜ ๋“ค์–ด๊ฐ€์ง€๋„ค์š”!

  • Github Actions๋ฅผ ํ†ตํ•œ ๋ฐฐํฌ๊ฐ€ ๋˜์—ˆ๋Š”์ง€ ํ™•์ธ

  • ip๋ฅผ ํ†ตํ•œ API ์ ‘์†
    ํ˜„์žฌ ํ”„๋กœ์ ํŠธ๋Š” ์นด์นด์˜ค ์†Œ์…”๋กœ๊ทธ์ธ์„ ์‚ฌ์šฉํ•˜๊ธฐ ๋•Œ๋ฌธ์—, ์นด์นด์˜ค ์†Œ์…œ๋กœ๊ทธ์ธ์ด ์ž˜ ์ง„ํ–‰๋˜๋Š”์ง€ ํ…Œ์ŠคํŠธํ•ด๋ณด์•˜์Šต๋‹ˆ๋‹ค.
    ํฌ๋กฌ ์ฐฝ์—์„œ {ip์ฃผ์†Œ}/kakao/login ์ž…๋ ฅ

  • ํฌํŠธ 3000๋ฒˆ์„ ์—ด์–ด์ฃผ์ง€ ์•Š์•„ ๋ฌธ์ œ๊ฐ€ ์ƒ๊ฒผ๊ณ , AWS EC2์—์„œ ํฌํŠธ ์ ‘๊ทผ์„ ํ—ˆ์šฉํ•ด์ค€ ๋‹ค์Œ ๋‹ค์‹œ ์‹œ๋„ํ•˜๋‹ˆ ์ž˜ ์—ด๋ ธ์Šต๋‹ˆ๋‹ค.

    • ์ ์šฉ ์ด์ „

    • 3000 ํฌํŠธ ์ ์šฉ ํ›„

  • ๋กœ๊ทธ์ธ์„ ์œ„ํ•œ ํ™”๋ฉด ์ถœ๋ ฅ ์™„๋ฃŒ!


  • ์‹ค์ œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋ณด์ด๋Š” API ์ ‘๊ทผ ์‹œ, ์—๋Ÿฌ์—†์ด ๋ฐ์ดํ„ฐ๊ฐ€ ๋ณด์—ฌ์ง€๋Š” ๊ฒƒ์„ ํ™•์ธ!
    (๋‚ด์šฉ ๋ชจ๋‘๋ฅผ ๋ณด์—ฌ๋“œ๋ฆด ์ˆ˜ ์—†๋Š” ์  ์–‘ํ•ด ๋ถ€ํƒ๋“œ๋ ค์š”!)

์ฐธ๊ณ ํ•œ ๋ ˆํผ๋Ÿฐ์Šค
๐Ÿ”— ์ฝ”๋“œ Push๋กœ ๋ฐฐํฌ๊นŒ์ง€! Spring Boot + Github Actions + Docker
๐Ÿ”— [ํ”„๋ก ํŠธ ์„œ๋ฒ„ ๋ฐฐํฌ] ์‚ฌ์ดํŠธ ์—ฐ๊ฒฐ ๊ฑฐ๋ถ€
๐Ÿ”— ๋ฆฌ๋ˆ…์Šค ํฌํŠธ ์ƒํƒœ ํ™•์ธ ๋ฐ ์—ด๊ธฐ

profile
์šฐ๋ฆฌ๊ฐ€ 'ํ•จ๊ป˜' ๊ฟˆ๊พธ๋Š” ์„ธ์ƒ์„ ์œ„ํ•ด ๊ธฐ๋กํ•˜๋ฉฐ ๊ฐœ๋ฐœํ•˜๋Š” BE ์ดํ•˜์–€์ž…๋‹ˆ๋‹ค๐Ÿณ

0๊ฐœ์˜ ๋Œ“๊ธ€