Merge pull request #131 from Soohyuniii/fix/production-mode #69
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: 빌드 자동화 | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - feat/cicd | |
| jobs: | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Node.js (언어 환경) | |
| uses: actions/setup-node@v2 | |
| with: | |
| node-version: "20" | |
| - name: Install dependencies | |
| run: npm ci # npm install보다 빠르고, package-lock.json을 신뢰 | |
| - name: Create .env.production file # env 파일 생성 단계 추가 | |
| run: | | |
| echo "VITE_GA_MEASUREMENT_ID=${{ secrets.VITE_GA_MEASUREMENT_ID }}" > .env.production | |
| echo "VITE_MODE=production" >> .env.production | |
| - name: Run build | |
| env: | |
| NODE_ENV: production | |
| VITE_MODE: production | |
| run: npm run build -- --mode production --verbose | |
| - name: Check built files (Debugging) | |
| run: grep -r "import.meta.env.MODE" dist/ || echo "No env mode found in built files" | |
| - name: Docker build & push | |
| run: | | |
| docker login -u ${{ secrets.DOCKER_USERNAME }} -p ${{ secrets.DOCKER_PASSWORD }} | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/embitips_front . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/embitips_front | |
| - name: Deploy to GCP | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.HOST_PROD }} | |
| username: ${{ secrets.USERNAME }} | |
| key: ${{ secrets.PRIVATE_KEY }} | |
| script: | | |
| sudo docker stop embitips_front || true | |
| sudo docker rm embitips_front || true | |
| sudo docker pull ${{ secrets.DOCKER_USERNAME }}/embitips_front | |
| sudo docker run -d -p 3000:3000 --name embitips_front ${{ secrets.DOCKER_USERNAME }}/embitips_front | |
| sudo docker image prune -f |