fix : 프론트 배포 #216
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 | |
| - feature/back-front-connet | |
| jobs: | |
| deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| - name: Build Frontend | |
| working-directory: ./frontend | |
| run: | | |
| npm install | |
| npm run build | |
| env: | |
| VITE_API_URL: ${{ secrets.VITE_API_URL }} | |
| VITE_GOOGLE_CLIENT_ID: ${{ secrets.VITE_GOOGLE_CLIENT_ID }} | |
| - name: Remove node_modules | |
| run: rm -rf frontend/node_modules | |
| - name: Clean up old files | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| rm -rf /home/ubuntu/rebloom/* | |
| - name: Copy files to EC2 | |
| uses: appleboy/scp-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| source: "./" | |
| target: "/home/ubuntu/rebloom" | |
| - name: Deploy to EC2 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| set -e | |
| cd /home/ubuntu/rebloom | |
| cat <<EOF > .env | |
| DB_PASSWORD=${{ secrets.DB_PASSWORD }} | |
| GMAIL_PASSWORD=${{ secrets.GMAIL_PASSWORD }} | |
| GOOGLE_CLIENT_ID=${{ secrets.GOOGLE_CLIENT_ID }} | |
| GOOGLE_CLIENT_SECRET=${{ secrets.GOOGLE_CLIENT_SECRET }} | |
| JWT_SECRET=${{ secrets.JWT_SECRET }} | |
| VITE_API_URL=${{ secrets.VITE_API_URL }} | |
| VITE_GOOGLE_CLIENT_ID=${{ secrets.VITE_GOOGLE_CLIENT_ID }} | |
| OPENAI_API_KEY=${{ secrets.OPENAI_API_KEY }} | |
| EOF | |
| echo "▶ docker compose down" | |
| docker compose down --remove-orphans -v || true | |
| echo "▶ force cleanup (보험)" | |
| docker rm -f rebloom-db rebloom-backend rebloom-nginx spring-app || true | |
| docker volume rm rebloom_db_data || true | |
| docker network prune -f || true | |
| echo "▶ wait for docker to settle" | |
| sleep 5 | |
| echo "▶ docker compose up" | |
| docker compose up -d --build --remove-orphans |