Merge master into release-based sync #19
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: build-and-deploy | |
| on: | |
| push: | |
| branches: [master] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout source code | |
| uses: actions/checkout@v4 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: 20 | |
| - name: Install node modules | |
| run: yarn install --frozen-lockfile | |
| - name: Generate Environment Variables File for Production | |
| run: | | |
| echo "VITE_KAKAO_REDIRECT_URI=$VITE_KAKAO_REDIRECT_URI" >> .env | |
| echo "VITE_KAKAO_CLIENT_ID=$VITE_KAKAO_CLIENT_ID" >> .env | |
| echo "VITE_API_URL=$VITE_API_URL" >> .env | |
| echo "VITE_KAKAO_JAVASCRIPT_KEY=$VITE_KAKAO_JAVASCRIPT_KEY" >> .env | |
| env: | |
| VITE_KAKAO_REDIRECT_URI: ${{ secrets.VITE_KAKAO_REDIRECT_URI }} | |
| VITE_KAKAO_CLIENT_ID: ${{ secrets.VITE_KAKAO_CLIENT_ID }} | |
| VITE_API_URL: ${{ secrets.VITE_API_URL }} | |
| VITE_KAKAO_JAVASCRIPT_KEY: ${{ secrets.VITE_KAKAO_JAVASCRIPT_KEY }} | |
| - name: Build application | |
| run: yarn build | |
| - name: Compress source code with build files | |
| run: tar -czf build.tar.gz dist | |
| - name: Upload artifact (optional) | |
| uses: actions/upload-artifact@v4 | |
| with: | |
| name: build-artifact | |
| path: build.tar.gz | |
| - name: Deploy to EC2 | |
| uses: appleboy/[email protected] | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
| source: 'build.tar.gz' | |
| target: '/home/ubuntu/' | |
| - name: Extract and Deploy on EC2 | |
| uses: appleboy/ssh-action@master | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USERNAME }} | |
| key: ${{ secrets.EC2_SSH_PRIVATE_KEY }} | |
| script: | | |
| cd /home/ubuntu/ | |
| tar -xzf build.tar.gz | |
| sudo rm -rf /etc/nginx/html/* | |
| sudo mv dist/* /etc/nginx/html/ | |
| cd /etc/nginx/html | |
| pm2 restart to-hero | |
| sudo docker exec nginx nginx -s reload | |
| rm -f /home/ubuntu/build.tar.gz |