Merge pull request #143 from satyansh911/feat/role-based-scoping #55
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 - Docker Build and Push | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - docker-automate-feature | |
| - github-actions-automate | |
| jobs: | |
| test-and-push: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout repository | |
| uses: actions/checkout@v3 | |
| - name: Set up Docker Buildx | |
| uses: docker/setup-buildx-action@v2 | |
| - name: Login to Docker Hub | |
| uses: docker/login-action@v2 | |
| with: | |
| username: ${{ secrets.DOCKER_USERNAME }} | |
| password: ${{ secrets.DOCKER_PASSWORD }} | |
| - name: Build Frontend Docker image | |
| run: docker build -t ${{ secrets.DOCKER_USERNAME }}/frontend:latest ./frontend | |
| - name: Scan Frontend Docker image with Trivy | |
| uses: aquasecurity/trivy-action@master | |
| with: | |
| image-ref: ${{ secrets.DOCKER_USERNAME }}/frontend:latest | |
| format: 'table' | |
| exit-code: '1' | |
| ignore-unfixed: 'true' | |
| - name: Test Frontend Container | |
| run: | | |
| docker run --rm -d --name frontend_test -p 3000:80 ${{ secrets.DOCKER_USERNAME }}/frontend:latest | |
| sleep 5 | |
| curl --fail http://localhost:3000 || (echo "Frontend container failed to respond!" && exit 1) | |
| docker stop frontend_test | |
| - name: Push Frontend Docker image | |
| run: docker push ${{ secrets.DOCKER_USERNAME }}/frontend:latest | |
| - name: Build Backend Docker image | |
| run: docker build -t ${{ secrets.DOCKER_USERNAME }}/backend:latest ./backend | |
| - name: Run backend container | |
| run: | | |
| docker run -d \ | |
| --name backend_test \ | |
| -e MONGODB_URI=${{ secrets.MONGODB_URI }} \ | |
| -e JWT_SECRET_TOKEN=${{ secrets.JWT_SECRET_TOKEN }} \ | |
| -e FRONTEND_URL=${{ secrets.FRONTEND_URL }} \ | |
| -e BACKEND_URL=${{ secrets.BACKEND_URL }} \ | |
| -p 8000:8000 \ | |
| ${{ secrets.DOCKER_USERNAME }}/backend:latest | |
| echo "Waiting for backend to start..." | |
| sleep 15 | |
| echo "Checking backend container logs:" | |
| docker logs backend_test | |
| - name: Push Backend Docker image | |
| run: docker push ${{ secrets.DOCKER_USERNAME }}/backend:latest |