Feature/190 : 회원가입 응모권 팝업 렌더링 플래그 API #83
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 -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 }} |