Feature/194 : Scouter Agent ์ค์ #85
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} |