chore: fix unit test #163
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: | |
| - "*" | |
| pull_request: | |
| branches: | |
| - main | |
| jobs: | |
| terraform: | |
| runs-on: ubuntu-latest | |
| env: | |
| TF_AWS_ACCESS_KEY_ID: ${{ secrets.TF_AWS_ACCESS_KEY_ID }} | |
| TF_AWS_SECRET_ACCESS_KEY: ${{ secrets.TF_AWS_SECRET_ACCESS_KEY }} | |
| DB_USER_PROD: ${{ secrets.DB_USER_PROD }} | |
| DB_PASSWORD: ${{ secrets.DB_PASSWORD }} | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v2 | |
| - name: Configure AWS CLI | |
| run: | | |
| aws configure set aws_access_key_id ${{ secrets.TF_AWS_ACCESS_KEY_ID }} | |
| aws configure set aws_secret_access_key ${{ secrets.TF_AWS_SECRET_ACCESS_KEY }} | |
| aws configure set region us-west-1 | |
| - name: Set up Terraform | |
| uses: hashicorp/setup-terraform@v1 | |
| with: | |
| terraform_version: 1.3.0 | |
| - name: Terraform Init | |
| run: terraform -chdir=infra init | |
| - name: Terraform Plan | |
| if: github.event_name == 'pull_request' | |
| run: terraform -chdir=infra plan -var="db_username=${{ secrets.DB_USER_PROD }}" -var="db_password=${{ secrets.DB_PASSWORD }}" | |
| - name: Terraform Apply (for push to main) | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| run: terraform -chdir=infra apply -auto-approve -var="db_username=${{ secrets.DB_USER_PROD }}" -var="db_password=${{ secrets.DB_PASSWORD }}" | |
| backend_deploy: | |
| runs-on: ubuntu-latest | |
| needs: terraform | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Log in to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKERHUB_USERNAME }} | |
| password: ${{ secrets.DOCKERHUB_TOKEN }} | |
| - name: Build and push Docker image | |
| run: | | |
| docker build -t lqla/bitmatch-backend:latest ./backend | |
| docker push lqla/bitmatch-backend:latest | |
| - name: Set up SSH and SSH into EC2 | |
| uses: appleboy/ssh-action@v0.1.9 | |
| with: | |
| host: ${{ secrets.EC2_IP }} | |
| username: ec2-user | |
| key: ${{ secrets.EC2_SSH_PRIVATE_KEY_PEM }} | |
| script: | | |
| docker pull lqla/bitmatch-backend:latest | |
| if [ "$(docker ps -q)" ]; then | |
| docker stop $(docker ps -q) | |
| docker rm $(docker ps -aq) | |
| fi | |
| docker image prune -a -f | |
| docker run -d -p 8000:8000 --env-file .env --name bitmatch-backend lqla/bitmatch-backend:latest | |
| frontend_deploy: | |
| runs-on: ubuntu-latest | |
| needs: backend_deploy | |
| if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
| env: | |
| AWS_ACCESS_KEY_ID: ${{ secrets.TF_AWS_ACCESS_KEY_ID }} | |
| AWS_SECRET_ACCESS_KEY: ${{ secrets.TF_AWS_SECRET_ACCESS_KEY }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v2 | |
| - name: Set up Node.js | |
| uses: actions/setup-node@v3 | |
| with: | |
| node-version: "20" | |
| - name: Install dependencies | |
| run: | | |
| npm install | |
| working-directory: frontend/bitmatch | |
| - name: Build frontend | |
| run: npm run build | |
| env: | |
| VITE_CLERK_PUBLISHABLE_KEY: ${{ secrets.VITE_CLERK_PUBLISHABLE_KEY }} | |
| VITE_SERVER_HOST: ${{ secrets.VITE_SERVER_HOST }} | |
| VITE_GEMINI_API_KEY: ${{ secrets.VITE_GEMINI_API_KEY }} | |
| working-directory: frontend/bitmatch | |
| - name: Sync build to S3 | |
| run: | | |
| aws s3 sync ./dist s3://bitmatch-frontend-bucket --delete | |
| working-directory: frontend/bitmatch | |
| - name: Invalidate CloudFront cache | |
| run: | | |
| aws cloudfront create-invalidation --distribution-id E29MAKOIPEX4G3 --paths "/*" |