added sleep for 10sec to start #14
This file contains 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: | |
- main | |
pull_request: | |
branches: | |
- main | |
jobs: | |
linting: | |
name: Lint | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Set up Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: 18 | |
- name: Install dependencies | |
run: npm install | |
- name: Run linter | |
run: npm run lint | |
- name: Report errors to Slack/Discord | |
if: failure() | |
run: | | |
curl -X POST -H 'Content-type: application/json' --data '{"content":"Linting failed in CI pipeline for commit ${{ github.sha }}. Check the logs for details."}' ${{ secrets.WEBHOOK_URL }} | |
testing: | |
name: Test | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Use Node.js | |
uses: actions/setup-node@v3 | |
with: | |
node-version: "20" | |
- name: Clean install dependencies | |
run: | | |
rm -rf node_modules | |
rm -f package-lock.json | |
npm install | |
- name: Run Vitest(unit) tests | |
run: npm run vitest:test | |
- name: Run Cypress(integration) tests | |
uses: cypress-io/github-action@v5 | |
with: | |
build: npm run build | |
start: npm run dev | |
wait-on: "http://localhost:5175" | |
- name: Report errors to Slack/Discord | |
if: failure() | |
run: | | |
curl -X POST -H 'Content-type: application/json' --data '{"content":"Testing failed in CI pipeline for commit ${{ github.sha }}. Check the logs for details."}' ${{ secrets.WEBHOOK_URL }} | |
build-docker-image: | |
name: Build Docker Image | |
runs-on: ubuntu-latest | |
needs: [linting, testing] | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Log in to Docker Hub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKER_USERNAME }} | |
password: ${{ secrets.DOCKER_PASSWORD }} | |
- name: Build Docker image | |
run: docker build -t ${{ secrets.DOCKER_USERNAME }}/sportbuzz:${{ github.sha }} . | |
- name: Push Docker image to Docker Hub | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/sportbuzz:${{ github.sha }} | |
- name: Tag the Docker image with 'latest' | |
run: docker tag ${{ secrets.DOCKER_USERNAME }}/sportbuzz:${{ github.sha }} ${{ secrets.DOCKER_USERNAME }}/sportbuzz:latest | |
- name: Push 'latest' Docker image to Docker Hub | |
run: docker push ${{ secrets.DOCKER_USERNAME }}/sportbuzz:latest | |
- name: Report errors to Slack/Discord | |
if: failure() | |
run: | | |
curl -X POST -H 'Content-type: application/json' --data '{"content":"Docker image build failed in CI pipeline for commit ${{ github.sha }}. Check the logs for details."}' ${{ secrets.WEBHOOK_URL }} | |
deploy: | |
name: Deploy Application | |
runs-on: ubuntu-latest | |
needs: build-docker-image | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Pull Docker image | |
run: docker pull ${{ secrets.DOCKER_USERNAME }}/sportbuzz:latest | |
- name: Run Docker container | |
run: | | |
docker stop sportbuzz || true | |
docker rm sportbuzz || true | |
docker run -d -p 5000:5000 --name sportbuzz ${{ secrets.DOCKER_USERNAME }}/sportbuzz:latest | |
- name: Wait for application to start | |
run: sleep 10 | |
- name: Verify application is running | |
run: curl --fail http://localhost:5000 || exit 1 | |
- name: Report errors to Slack/Discord | |
if: failure() | |
run: | | |
curl -X POST -H 'Content-type: application/json' --data '{"content":"Docker image deploy failed in CI pipeline for commit ${{ github.sha }}. Check the logs for details."}' ${{ secrets.WEBHOOK_URL }} |