deploy 1.17 #49
This file contains hidden or 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: Deploy To EC2 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: GitHub Repository checkout | |
| uses: actions/checkout@v4 | |
| - name: EC2 서버에 SSH 접속해서 애플리케이션 배포 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_PRIVATE_KEY }} | |
| script: | | |
| # 1. 작업 디렉토리로 이동 | |
| cd ~/BackEnd | |
| # 2. 최신 코드 받아오기 | |
| git reset --hard | |
| git checkout main | |
| git pull origin main | |
| # 3. application.properties 설정 | |
| echo "${{ secrets.APPLICATION_DB_PROPERTIES }}" > ./src/main/resources/application-db.properties | |
| echo "${{ secrets.APPLICATION_JWT_PROPERTIES }}" > ./src/main/resources/application-jwt.properties | |
| echo "${{ secrets.APPLICATION_KAFKA_PROPERTIES }}" > ./src/main/resources/application-kafka.properties | |
| echo "${{ secrets.APPLICATION_S3_PROPERTIES }}" > ./src/main/resources/application-s3.properties | |
| echo "${{ secrets.APPLICATION_ML_PROPERTIES }}" > ./src/main/resources/application-ml.properties | |
| # 4. 빌드 권한 확보 | |
| chmod +x ./gradlew | |
| # 5. nginx 권한 확보 | |
| sudo chmod -R 755 nginx | |
| # 5. 빌드 | |
| ./gradlew clean build | |
| # 6. 기존 컨테이너 중지 및 삭제 | |
| docker compose down -v || true | |
| # 7. 도커 이미지 생성 및 실행 | |
| docker compose up -d --build |