Merge pull request #24 from HeartForecast/feat/#23 #98
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 Frontend to EC2 | |
| on: | |
| push: | |
| branches: [ "develop" ] | |
| pull_request: | |
| branches: [ "develop" ] | |
| jobs: | |
| build-and-deploy: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Setup Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - name: Install pnpm | |
| run: npm install -g pnpm | |
| - name: Install dependencies | |
| run: pnpm install --frozen-lockfile | |
| - name: Build Next.js | |
| run: pnpm build | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Create .env file | |
| run: | | |
| echo "NEXT_PUBLIC_API_BASE_URL=https://heartforecast.co.kr" >> .env | |
| echo "NEXT_PUBLIC_KAKAO_LOGIN_URL=https://heartforecast.co.kr/oauth2/authorization/kakao" >> .env | |
| echo "NEXT_PUBLIC_FRONTEND_URL=https://heartforecast.co.kr" >> .env | |
| echo "NEXT_PUBLIC_ENVIRONMENT=production" >> .env | |
| - name: Build and push Docker image | |
| run: | | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/heart-forecast-client:latest . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/heart-forecast-client:latest | |
| - name: Deploy to EC2 via SSH | |
| uses: appleboy/ssh-action@v0.1.7 | |
| with: | |
| host: ${{ secrets.EC2_HOST }} | |
| username: ${{ secrets.EC2_USER }} | |
| key: ${{ secrets.EC2_SSH_KEY }} | |
| script: | | |
| cd ~/HeartForecast | |
| docker compose pull | |
| docker compose up -d --remove-orphans |