scientistbodybuilder is running CI/CD on UTSC-CSCC01-Software-Engineering-I/term-group-project-c01s25-project-temptracker #86
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 | |
| run-name: ${{ github.actor }} is running ${{ github.workflow }} on ${{ github.repository }} | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - develop | |
| - feat/deploy-testing | |
| tags: | |
| - 'release/v*' | |
| pull_request: | |
| branches: | |
| - main | |
| - develop | |
| jobs: | |
| test: | |
| runs-on: ubuntu-latest | |
| timeout-minutes: 10 | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v3 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: 18 | |
| # === BACKEND STUFF === | |
| - name: Create server/.env | |
| working-directory: server | |
| run: | | |
| echo "PORT=${{ secrets.PORT }}" >> .env | |
| echo "SUPABASE_URL=${{ secrets.SUPABASE_URL }}" >> .env | |
| echo "SUPABASE_SERVICE_ROLE_KEY=${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}" >> .env | |
| echo "SENDGRID_API_KEY=${{ secrets.SENDGRID_API_KEY }}" >> .env | |
| echo "SENDGRID_SENDER=${{ secrets.SENDGRID_SENDER }}" >> .env | |
| echo "NEXT_PUBLIC_SUPABASE_URL=${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}" >> .env.test | |
| echo "NEXT_PUBLIC_SUPABASE_ANON_KEY=${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}" >> .env.test | |
| echo "TEST_EMAIL=${{ secrets.TEST_EMAIL }}" >> .env.test | |
| echo "TEST_PASSWORD=${{ secrets.TEST_PASSWORD }}" >> .env.test | |
| - name: Install and test backend | |
| working-directory: server | |
| run: | | |
| npm ci | |
| npm test | |
| # === FRONTEND === | |
| - name: Create client/.env.local and .env.test | |
| working-directory: client | |
| run: | | |
| echo "NEXT_PUBLIC_API_URL=${{ secrets.NEXT_PUBLIC_API_URL }}" >> .env.local | |
| echo "NEXT_PUBLIC_SUPABASE_URL=${{ secrets.NEXT_PUBLIC_SUPABASE_URL }}" >> .env.local | |
| echo "NEXT_PUBLIC_SUPABASE_ANON_KEY=${{ secrets.NEXT_PUBLIC_SUPABASE_ANON_KEY }}" >> .env.local | |
| cp .env.local .env.test | |
| - name: Install and test frontend | |
| working-directory: client | |
| run: | | |
| npm ci | |
| npm test | |
| # === DOCKER LOGIN === | |
| - name: Log in to Docker Hub | |
| run: echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "${{ secrets.DOCKER_USERNAME }}" --password-stdin | |
| # === SERVER DOCKER IMAGE === | |
| - name: Build and push server (latest) | |
| working-directory: server | |
| run: | | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp-server:master . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/myapp-server:master | |
| - name: Tag and push server (versioned) | |
| working-directory: server | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/release/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/release/} | |
| else | |
| VERSION="release-v4.0" | |
| fi | |
| echo "Tagging server image with version: $VERSION" | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp-server:$VERSION . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/myapp-server:$VERSION | |
| # === CLIENT DOCKER IMAGES === | |
| - name: Build and push client (latest) | |
| working-directory: client | |
| run: | | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp-client:master . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/myapp-client:master | |
| - name: Tag and push client (versioned) | |
| working-directory: client | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/release/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/release/} | |
| else | |
| VERSION="release-v4.0" | |
| fi | |
| echo "Tagging client image with version: $VERSION" | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp-client:$VERSION . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/myapp-client:$VERSION | |
| # === MAP === | |
| - name: Create map/.env | |
| working-directory: map | |
| run: | | |
| echo "SUPABASE_URL=${{ secrets.SUPABASE_URL }}" >> .env | |
| echo "SUPABASE_KEY=${{ secrets.SUPABASE_SERVICE_ROLE_KEY }}" >> .env | |
| - name: Build and push map (latest) | |
| working-directory: map | |
| run: | | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp-map:master . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/myapp-map:master | |
| - name: Tag and push map (versioned) | |
| working-directory: map | |
| run: | | |
| if [[ "${GITHUB_REF}" == refs/tags/release/* ]]; then | |
| VERSION=${GITHUB_REF#refs/tags/release/} | |
| else | |
| VERSION="release-v4.0" | |
| fi | |
| echo "Tagging map image with version: $VERSION" | |
| docker build -t ${{ secrets.DOCKER_USERNAME }}/myapp-map:$VERSION . | |
| docker push ${{ secrets.DOCKER_USERNAME }}/myapp-map:$VERSION | |
| deploy: | |
| runs-on: ubuntu-latest | |
| needs: [test] | |
| steps: | |
| - name: Pull and restart containers | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.VM_HOST }} | |
| username: ${{ secrets.VM_USER }} | |
| key: ${{ secrets.VM_SSH_KEY }} | |
| script: | | |
| cd ~/temptracker | |
| docker compose down | |
| docker rmi haseeb702/myapp-server:master || true | |
| docker rmi haseeb702/myapp-client:master || true | |
| docker rmi haseeb702/myapp-map:master || true | |
| echo "Cleaning up old Docker resources..." | |
| docker system prune -a --volumes -f | |
| echo "Waiting for Docker Hub to finish image push..." | |
| sleep 10 | |
| docker compose pull | |
| docker compose up -d | |
| - name: Wait for containers to stabilize | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.VM_HOST }} | |
| username: ${{ secrets.VM_USER }} | |
| key: ${{ secrets.VM_SSH_KEY }} | |
| script: | | |
| sleep 5 | |
| - name: Run deployed tests | |
| uses: appleboy/ssh-action@v1.0.0 | |
| with: | |
| host: ${{ secrets.VM_HOST }} | |
| username: ${{ secrets.VM_USER }} | |
| key: ${{ secrets.VM_SSH_KEY }} | |
| script: | | |
| cd ~/temptracker | |
| docker compose exec -T server npm run test-deployed |