Skip to content

Merge pull request #1 from PatidarAnjali/anj-dev #2

Merge pull request #1 from PatidarAnjali/anj-dev

Merge pull request #1 from PatidarAnjali/anj-dev #2

Workflow file for this run

name: CI/CD Pipeline
on:
push:
branches: [ main, develop ]
pull_request:
branches: [ main ]
jobs:
test:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:15
env:
POSTGRES_DB: events_test
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: '18'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run linter
run: npm run lint || echo "Add linting script to package.json"
- name: Run tests
run: npm test
env:
NODE_ENV: test
DB_HOST: localhost
DB_PORT: 5432
DB_NAME: events_test
DB_USER: postgres
DB_PASSWORD: postgres
REDIS_HOST: localhost
REDIS_PORT: 6379
- name: Build Docker image
run: docker build -f docker/Dockerfile -t event-scraper-api .
build:
needs: test
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- 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 and push API
uses: docker/build-push-action@v4
with:
context: .
file: docker/Dockerfile
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/event-scraper-api:latest
${{ secrets.DOCKER_USERNAME }}/event-scraper-api:${{ github.sha }}
- name: Build and push Worker
uses: docker/build-push-action@v4
with:
context: .
file: docker/Dockerfile.worker
push: true
tags: |
${{ secrets.DOCKER_USERNAME }}/event-scraper-worker:latest
${{ secrets.DOCKER_USERNAME }}/event-scraper-worker:${{ github.sha }}
deploy:
needs: build
runs-on: ubuntu-latest
if: github.ref == 'refs/heads/main'
steps:
- name: Deploy to production
run: |
echo "Add your deployment steps here"
# Example: SSH into server and pull new images
# ssh user@server 'cd /app && docker-compose pull && docker-compose up -d'