Skip to content

chore: cd self-hosted λ³€κ²½ #29

chore: cd self-hosted λ³€κ²½

chore: cd self-hosted λ³€κ²½ #29

Workflow file for this run

name: Main Branch CI Pipeline
on:
pull_request:
branches:
- main
push:
branches:
- main
jobs:
build:
runs-on: ubuntu-latest
env:
# λ°μ΄ν„°λ² μ΄μŠ€ ν™˜κ²½λ³€μˆ˜ (RDS)
DB_URL: ${{ secrets.DB_URL }}
DB_USERNAME: ${{ secrets.DB_USERNAME }}
DB_PASSWORD: ${{ secrets.DB_PASSWORD }}
## Redis ν™˜κ²½λ³€μˆ˜
REDIS_HOST: ${{ secrets.REDIS_HOST }}
REDIS_PORT: ${{ secrets.REDIS_PORT }}
# FCM ν™˜κ²½λ³€μˆ˜
BOTTLER_FCM_BASE64: ${{ secrets.BOTTLER_FCM_BASE64 }}
# AWS ν™˜κ²½λ³€μˆ˜
AWS_ACCESS_KEY: ${{ secrets.AWS_ACCESS_KEY }}
AWS_SECRET_KEY: ${{ secrets.AWS_SECRET_KEY }}
AWS_REGION: ${{ secrets.AWS_REGION }}
# ECR ν™˜κ²½λ³€μˆ˜
ECR_URI: ${{ secrets.ECR_URI }}
# S3 ν™˜κ²½λ³€μˆ˜
BUCKET_NAME: ${{ secrets.BUCKET_NAME }}
BASE_URL: ${{ secrets.BASE_URL }}
# gpt ν™˜κ²½λ³€μˆ˜
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
steps:
- name: μ½”λ“œ κ°€μ Έμ˜€κΈ°
uses: actions/checkout@v4
- name: JDK 17 μ„€μ •
uses: actions/setup-java@v4
with:
java-version: 17
distribution: temurin
deploy:
# μš°λ¦¬κ°€ λ“±λ‘ν•œ Github Self Hosted Runner μ—μ„œ μ‹€ν–‰ν•©λ‹ˆλ‹€
runs-on: self-hosted
# 작의 ꡬ체적인 λ‹¨κ³„μž…λ‹ˆλ‹€
steps:
# 처음 _work 폴더에 github actions ν”„λ‘œκ·Έλž¨μ΄ νŒŒμΌμ„ μˆ˜μ •ν•  κΆŒν•œμ΄ μ—†μ–΄μ„œ, κΆŒν•œμ„ λΆ€μ—¬ν•΄ μ£ΌκΈ° μœ„ν•œ μž‘μ—…μž…λ‹ˆλ‹€
# 이 λͺ…령을 ν†΅ν•΄μ„œ 이미 μžˆλŠ” 폴더에 git pull 을 μ‚¬μš©ν•  수 μžˆμŠ΅λ‹ˆλ‹€
- name: change permission
# λ§ˆμ§€λ§‰ jwp-shopping-order λŠ” repository μ΄λ¦„μž…λ‹ˆλ‹€.
run: |
sudo chown -R ubuntu:ubuntu /home/ubuntu/actions-runner/_work/WEB1_1_Postman_BE
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'corretto'
# git clone, git pull, git fetch 같은 μž‘μ—…μ„ λ‹¨μˆœν™” ν•˜κΈ° μœ„ν•œ action μž…λ‹ˆλ‹€. actions/checkout@v3
# 미리 λ‹€λ₯Έ κ°œλ°œμžκ°€ λ§Œλ“€μ–΄λ‘” action 을 μ‚¬μš©ν•œλ‹€λŠ” μ˜λ―Έμž…λ‹ˆλ‹€
- uses: actions/checkout@v3
# bootjar λ₯Ό λ§Œλ“€κ³ , μ‹€ν–‰μ‹œν‚€λŠ” 과정을 λ‹΄κ³  μžˆμŠ΅λ‹ˆλ‹€
- name: gradle build
# μ²˜μŒμ— ./gradlew νŒŒμΌμ„ μ‹€ν–‰ν•  수 μ—†μ–΄μ„œ, chmod 둜 μ‹€ν–‰ κ°€λŠ₯ν•˜λ„λ‘ λ°”κΏ”μ€λ‹ˆλ‹€
run: |
chmod +x ./gradlew
./gradlew build -x test
# 80 번 ν¬νŠΈκ°€ 이미 μžˆλ‹€λ©΄, κ·Έ ν”„λ‘œκ·Έλž¨μ„ μ’…λ£Œν•©λ‹ˆλ‹€
- name: kill 80 port if exist
run: |
if sudo lsof -i :80; then
echo "Port 80 is already in use. Killing the process..."
sudo lsof -i :80 | awk 'NR!=1 {print $2}' | sudo xargs kill -9
fi
# μŠ€ν”„λ§ ν”„λ‘œκ·Έλž¨μ„ μ‹€ν–‰ν•©λ‹ˆλ‹€
- name: deploy
run: |
sudo java -jar build/libs/WEB1_1_Postman_BE.jar --spring.profiles.active=prod &