Skip to content

Feature/194 : Scouter Agent ์„ค์ • #85

Feature/194 : Scouter Agent ์„ค์ •

Feature/194 : Scouter Agent ์„ค์ • #85

Workflow file for this run

name: Daily Phrase Dev API CI/CD
on:
pull_request:
branches:
- develop
types:
- closed
workflow_dispatch:
jobs:
build-and-deploy:
runs-on: ubuntu-latest
if: github.event.pull_request.merged == true
steps:
- name: ์ฝ”๋“œ ์ฒดํฌ์•„์›ƒ
uses: actions/checkout@v3
- name: JDK 17 ์„ค์ •
uses: actions/setup-java@v3
with:
java-version: '17'
distribution: 'temurin'
- name: application.yml ์ƒ์„ฑ
run: |
mkdir -p ./src/main/resources/
echo "${{ secrets.APPLICATION_YML }}" > ./src/main/resources/application.yml
- name: firebase ๋””๋ ‰ํ† ๋ฆฌ ์ƒ์„ฑ
run: mkdir -p ./src/main/resources/firebase/
- name: JSON ์ƒ์„ฑ
uses: jsdaniell/[email protected]
with:
name: "firebase-adminsdk.json"
json: ${{ secrets.SECRET_JSON }}
dir: "./src/main/resources/firebase/"
- name: Gradlew ์‹คํ–‰ ๊ถŒํ•œ ๋ถ€์—ฌ
run: chmod +x ./gradlew
- name: Gradle๋กœ ๋นŒ๋“œ
run: ./gradlew bootJar -x test -Pprofile=dev
- name: ๋นŒ๋“œ ์•„ํ‹ฐํŒฉํŠธ ์—…๋กœ๋“œ
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: build/libs/*.jar
- name: ๋นŒ๋“œ ์•„ํ‹ฐํŒฉํŠธ ๋‹ค์šด๋กœ๋“œ
uses: actions/download-artifact@v3
with:
name: build-artifact
path: .
- name: Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ๋ฅผ ์œ„ํ•œ app.jar ์ค€๋น„
run: |
JAR_FILE=$(ls build/libs/*.jar | head -n 1)
cp $JAR_FILE app.jar
- name: AWS CLI ์„ค์น˜ ๋˜๋Š” ์—…๋ฐ์ดํŠธ
run: |
curl "https://awscli.amazonaws.com/awscli-exe-linux-x86_64.zip" -o "awscliv2.zip"
unzip awscliv2.zip
sudo ./aws/install --update
- name: AWS CLI ๊ตฌ์„ฑ
run: |
aws configure set aws_access_key_id ${{ secrets.DEV_AWS_ACCESS_KEY_ID }}
aws configure set aws_secret_access_key ${{ secrets.DEV_AWS_SECRET_ACCESS_KEY }}
aws configure set default.region ${{ secrets.AWS_REGION }}
- name: AWS ECR ๋กœ๊ทธ์ธ
run: |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.DEV_AWS_ECR_REPOSITORY_URL }}
- name: Docker ์ด๋ฏธ์ง€ ๋นŒ๋“œ
run: |
docker build --build-arg SPRING_PROFILES_ACTIVE=dev --build-arg COLLECTOR_IP=${{ secrets.DEV_EC2_HOST }} -t ${{ secrets.DEV_AWS_ECR_REPOSITORY_URL }}:${{ github.sha }} .
- name: Docker ์ด๋ฏธ์ง€ ECR์— ํ‘ธ์‹œ
run: |
docker push ${{ secrets.DEV_AWS_ECR_REPOSITORY_URL }}:${{ github.sha }}
- name: EC2 ์ธ์Šคํ„ด์Šค์— ๋ฐฐํฌ
uses: appleboy/ssh-action@master
with:
host: ${{ secrets.DEV_EC2_HOST }}
username: ${{ secrets.DEV_EC2_USERNAME }}
key: ${{ secrets.DEV_EC2_SSH_KEY }}
port: 22
script: |
aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | docker login --username AWS --password-stdin ${{ secrets.DEV_AWS_ECR_REPOSITORY_URL }}
# Docker ์ด๋ฏธ์ง€ pull
docker pull ${{ secrets.DEV_AWS_ECR_REPOSITORY_URL }}:${{ github.sha }}
# ๊ธฐ์กด ์ปจํ…Œ์ด๋„ˆ ์ค‘์ง€ ๋ฐ ์ œ๊ฑฐ
docker stop dailyphrase-dev-api || true
docker rm dailyphrase-dev-api || true
# ์ƒˆ๋กœ์šด Docker ์ปจํ…Œ์ด๋„ˆ ์‹คํ–‰
docker run -d --name dailyphrase-dev-api -e SPRING_PROFILES_ACTIVE=dev -p 80:8080 ${{ secrets.DEV_AWS_ECR_REPOSITORY_URL }}:${{ github.sha }}