Skip to content

Merge pull request #57 from prgrms-web-devcourse-final-project/fix/#4โ€ฆ #35

Merge pull request #57 from prgrms-web-devcourse-final-project/fix/#4โ€ฆ

Merge pull request #57 from prgrms-web-devcourse-final-project/fix/#4โ€ฆ #35

Workflow file for this run

name: Main Branch CI Pipeline
on:
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
- name: Gradle ์˜์กด์„ฑ ์บ์‹ฑ
uses: actions/cache@v4
with:
path: |
~/.gradle/caches
~/.gradle/caches/build-cache
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*', '**/gradle-wrapper.properties') }}
restore-keys: |
${{ runner.os }}-gradle-
- name: Gradle ๊ถŒํ•œ ๋ถ€์—ฌ
run: chmod +x ./gradlew
shell: bash
- name: Gradle ํ…Œ์ŠคํŠธ
run: ./gradlew clean build
- name: AWS Resource์— ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๊ฒŒ AWS credentials ์„ค์ •
uses: aws-actions/configure-aws-credentials@v4
with:
aws-region: ${{ secrets.AWS_REGION }}
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
- name: Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ
run: docker build -t bottler-backend:${{ github.sha }} .
- name: Docker ์ด๋ฏธ์ง€ ํƒœ๊ทธ
run: docker tag bottler-backend:${{ github.sha }} ${{ secrets.ECR_URI }}/bottler-backend:${{ github.sha }}
- name: AWS ECR ๋กœ๊ทธ์ธ
uses: aws-actions/amazon-ecr-login@v2
- name: Docker ์ด๋ฏธ์ง€ Push
run: docker push ${{ secrets.ECR_URI }}/bottler-backend:${{ github.sha }}
- name: .env ํŒŒ์ผ ์ž‘์„ฑ
run: |
echo "DB_URL=${{ secrets.DB_URL }}" >> docker-compose/.env
echo "DB_USERNAME=${{ secrets.DB_USERNAME }}" >> docker-compose/.env
echo "DB_PASSWORD=${{ secrets.DB_PASSWORD }}" >> docker-compose/.env
echo "AWS_ACCESS_KEY=${{ secrets.AWS_ACCESS_KEY_ID }}" >> docker-compose/.env
echo "AWS_SECRET_KEY=${{ secrets.AWS_SECRET_ACCESS_KEY }}" >> docker-compose/.env
echo "AWS_REGION=${{ secrets.AWS_REGION }}" >> docker-compose/.env
echo "BUCKET_NAME=${{ secrets.BUCKET_NAME }}" >> docker-compose/.env
echo "BASE_URL=${{ secrets.BASE_URL }}" >> docker-compose/.env
echo "ECR_URI=${{ secrets.ECR_URI }}" >> docker-compose/.env
echo "OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }}" >> docker-compose/.env
echo "TAG=${{ github.sha }}" >> docker-compose/.env
- name: .env ํŒŒ์ผ EC2๋กœ ๋ณต์‚ฌ
run: |
scp -i ${{ secrets.EC2_SSH_KEY }} .env ubuntu@${{ secrets.EC2_PUBLIC_IP }}:~/docker-compose/.env
- name: EC2๋กœ Docker Compose ๋ฐฐํฌ
run: |
ssh -i ${{ secrets.EC2_SSH_KEY }} ubuntu@${{ secrets.EC2_PUBLIC_IP }} <<EOF
docker pull ${{ secrets.ECR_URI }}:${{ github.sha }}
cd ~/docker-compose
TAG=${{ github.sha }} docker-compose -f docker-compose.yml down
TAG=${{ github.sha }} docker-compose -f docker-compose.yml up -d
EOF