git commit -m 'updated server' #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: CI/CD Pipeline | |
| on: | |
| push: | |
| branches: ms/Scrun-130-Project-Deployment-dockerfiles | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Install Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| - name: Run frontend tests | |
| run: cd course-matrix/frontend && npm install && npm run test | |
| - name: Run backend tests | |
| run: cd course-matrix/backend && npm install && npm run test | |
| deploy: | |
| needs: test | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout Code | |
| uses: actions/checkout@v3 | |
| - name: Setup SSH Connection | |
| run: | | |
| echo "${{ secrets.GCP_SSH_PRIVATE_KEY }}" > private_key | |
| chmod 600 private_key | |
| - name: Deploy to Google Cloud VM | |
| run: | | |
| ssh -i private_key -o StrictHostKeyChecking=no ${{ secrets.GCP_USERNAME }}@${{ secrets.GCP_VM_IP }} << 'EOF' | |
| cd /home/masahisasekita/term-group-project-c01w25-project-course-matrix || { echo "Error: Directory /root/myapp does not exist!"; exit 1; } | |
| git pull ms/Scrun-130-Project-Deployment-dockerfiles | |
| cd course-matrix | |
| # Update frontend .env | |
| cd frontend | |
| rm -f .env # Delete the existing .env file | |
| echo "VITE_SERVER_URL=\"http://34.130.253.243:8081\"" > .env && \ | |
| echo "VITE_PUBLIC_ASSISTANT_BASE_URL=\"${{ secrets.VITE_PUBLIC_ASSISTANT_BASE_URL }}\"" >> .env && \ | |
| echo "VITE_ASSISTANT_UI_KEY=\"${{ secrets.VITE_ASSISTANT_UI_KEY }}\"" >> .env | |
| # Move to backend | |
| cd ../backend | |
| rm -f .env # Delete the existing .env file | |
| echo "NODE_ENV=\"development\"" > .env && \ | |
| echo "PORT=8081" >> .env && \ | |
| echo "CLIENT_APP_URL=\"http://34.130.253.243:5173\"" >> .env && \ | |
| echo "DATABASE_URL=\"${{ secrets.DATABASE_URL }}\"" >> .env && \ | |
| echo "DATABASE_KEY=\"${{ secrets.DATABASE_KEY }}\"" >> .env && \ | |
| echo "OPENAI_API_KEY=\"${{ secrets.OPENAI_API_KEY }}\"" >> .env && \ | |
| echo "PINECONE_API_KEY=\"${{ secrets.PINECONE_API_KEY }}\"" >> .env && \ | |
| echo "PINECONE_INDEX_NAME=\"course-matrix\"" >> .env && \ | |
| echo "BREVO_API_KEY=\"${{ secrets.BREVO_API_KEY }}\"" >> .env && \ | |
| echo "SENDER_EMAIL=\"${{ secrets.SENDER_EMAIL }}\"" >> .env && \ | |
| echo "SENDER_NAME=\"Course Matrix Notifications\"" >> .env | |
| cd ../ | |
| docker compose build | |
| docker compose up -d --remove-orphans | |
| EOF |