<aside>
</aside>
AWS CodePipeline | Github Actions | |
---|---|---|
ํธ์์ฑ | IAM ๊ถํ, ์ฐ๊ฒฐ ๋ฆฌ์์ค ์ค์ ๋ฑ ๋ณต์กํ ์ ์ฐจ๊ฐ ํ์ | GitHub ์ ์ฅ์ ๋ด์์ ๋ฐ๋ก CI/CD ์ค์ ๊ฐ๋ฅ |
์คํ ๋ฐฉ์ | Stage ๋จ์ ์์ฐจ์ ์คํ | Job ๋จ์ ๋ณ๋ ฌ ์ฒ๋ฆฌ |
๊ด๋ฆฌ | AWS์์ ๋ฐ๋ก ๊ด๋ฆฌ | GitHub์์ ์ค์ ์ง์คํ ๊ด๋ฆฌ |
ํ์ฅ์ฑ | AWS ์๋น์ค ์ฐ๋์ ์ ๋ฆฌ | AWS ์ธ์ ์ธ๋ถ ํด๋ผ์ฐ๋ ์ฐ๋์ ์ ๋ฆฌ |
๋น์ฉ ๊ตฌ์กฐ | ์ฌ์ฉ๋ ๊ธฐ๋ฐ ๊ณผ๊ธ | ๋๋ถ๋ถ ๋ฌด๋ฃ, ๊ณ ์ฑ๋ฅ์ฉ ์ฌ์ฉ ์ ๊ณผ๊ธ |
GitHub Actions Workflow ํธ๋ฆฌ๊ฑฐ ์ค์
on:
pull_request:
branches: [ main ]
types: [closed]
๋น๋ ์, ํ ์คํธ์ ํ์ํ ์๋น์ค๋ฅผ ๊ตฌ์ฑ
jobs:
build:
runs-on: ubuntu-latest
services:
# Redis ์๋น์ค ์ปจํ
์ด๋ ์คํ
redis:
image: redis:7.2
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping" # Redis๊ฐ ์๋ตํ๋์ง ํฌ์ค์ฒดํฌ
--health-interval 10s # 10์ด๋ง๋ค ํฌ์ค์ฒดํฌ
--health-timeout 5s # 5์ด ์ด์ ์๋ต ์์ผ๋ฉด ์คํจ
--health-retries 5 # 5๋ฒ ์ฐ์ ์คํจ ์ unhealthy ํ์
# Elasticsearch ์๋น์ค ์ปจํ
์ด๋ ์คํ
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.13.4
env:
discovery.type: single-node
xpack.security.enabled: "false" # ํ
์คํธ ๊ฐํธํ
ES_JAVA_OPTS: "-Xms512m -Xmx512m" # JVM ๋ฉ๋ชจ๋ฆฌ ์ ํ
ports: [ "9200:9200" ] # ํธ์คํธ <-> ์ปจํ
์ด๋ ํฌํธ ๋งคํ
options: >-
--health-cmd "curl -fsS <http://localhost:9200/_cluster/health> || exit 1"
--health-interval 10s # 10์ด๋ง๋ค ํฌ์ค์ฒดํฌ
--health-timeout 5s # 5์ด ์ด์ ์๋ต ์์ผ๋ฉด ์คํจ
--health-retries 10 # 10๋ฒ ์ฐ์ ์คํจ ์ unhealthy ํ์
CI ํ์ดํ๋ผ์ธ ๊ตฌ์ฑ
steps:
# ์ ์ฅ์์ ์์ค์ฝ๋๋ฅผ ์ํฌํ๋ก์ฐ ์คํ ํ๊ฒฝ์ผ๋ก ์ฒดํฌ์์
- name: Checkout source code
uses: actions/checkout@v4
# JDK 17์ ์ค์น
- name: Set up JDK
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: '17'
# Linuxํ๊ฒฝ์์ gradlew ์คํ ๊ถํ ๋ถ์ฌ
- name: Grant permission to gradlew
run: chmod +x ./gradlew
# Gradle ๋น๋ ๋ฐ ํ
์คํธ ์คํ
- name: Run tests
run: ./gradlew build --no-daemon
# ๋น๋ ๊ฒฐ๊ณผ๋ฌผ์ GitHub Actions ์ํฐํฉํธ๋ก ์
๋ก๋
- name: Upload JAR
uses: actions/upload-artifact@v4
with:
name: app
path: build/libs/*.jar
๋ฐฐํฌ ์๋ํ
deploy:
needs: build
runs-on: ubuntu-latest
steps:
# ๋น๋ ๋จ๊ณ์์ ์
๋ก๋ํ๋ JAR ์ํฐํฉํธ๋ฅผ ๋ค์ด๋ก๋
- name: Download JAR
uses: actions/download-artifact@v4
with:
name: app
# EC2 ์๋ฒ๋ก JAR ํ์ผ ์ ์ก
- name: Deploy to EC2
uses: appleboy/scp-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
source: "*.jar"
target: "/home/ubuntu/app"
# EC2 ์๋ฒ์์ ๋ฐฐํฌ ์คํฌ๋ฆฝํธ ์คํ
- name: Run app via SSH
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.EC2_HOST }}
username: ubuntu
key: ${{ secrets.EC2_KEY }}
script: |
bash /home/ubuntu/app/run-deploy.sh