다고쳤습니다ㅣ~ #33
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: React CI/CD with Docker Compose | |
| on: | |
| push: | |
| branches: [ "main" ] | |
| pull_request: | |
| branches: [ "main" ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: '20' | |
| cache: 'npm' | |
| - name: Install dependencies | |
| run: npm ci | |
| - name: Build project | |
| run: npm run build | |
| - name: Login to DockerHub | |
| uses: docker/login-action@v3 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and Push Docker Image | |
| uses: docker/build-push-action@v5 | |
| with: | |
| context: . | |
| push: true | |
| build-args: | | |
| VITE_API_URL=${{ secrets.VITE_API_URL }} | |
| tags: ${{ secrets.DOCKERHUB_USERNAME }}/space_front:latest | |
| - name: Deploy to Server | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.LIVE_SERVER_IP }} | |
| username: ubuntu | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| sudo docker stop space_front | |
| sudo docker rm space_front | |
| sudo docker pull ${{ secrets.DOCKERHUB_USERNAME }}/space_front:latest | |
| sudo docker-compose -f docker-compose-react.yml up -d |