1+ # .github/workflows/ci.yml
2+ name : CI/CD
3+
4+ on :
5+ push :
6+ branches :
7+ - main
8+
9+ jobs :
10+ build :
11+ runs-on : ubuntu-latest
12+ steps :
13+ - name : Checkout code
14+ uses : actions/checkout@v3
15+
16+ - name : Set up Node.js
17+ uses : actions/setup-node@v3
18+ with :
19+ node-version : 16 # Or your desired Node.js version
20+
21+ - name : Install backend dependencies
22+ run : npm install --prefix backend
23+
24+ - name : Install frontend dependencies
25+ run : npm install --prefix frontend
26+
27+
28+ - name : Build backend
29+ run : npm run build --prefix backend
30+
31+ - name : Build frontend
32+ run : npm run build --prefix frontend
33+
34+ - name : Run backend tests
35+ run : npm test --prefix backend
36+
37+ - name : Run frontend tests
38+ run : npm test --prefix frontend
39+
40+ - name : Build Docker images
41+ run : docker-compose build
42+
43+
44+ - name : Run tests on Dockerized application
45+ run : |
46+ docker-compose up -d --build
47+ sleep 30 # Allow time for backend/db to start
48+ docker-compose run --rm backend npm test # run backend tests in the container
49+ docker-compose down -v
50+
51+ deploy :
52+ needs : build
53+ runs-on : ubuntu-latest
54+ if : github.ref == 'refs/heads/main'
55+ steps :
56+ - name : Login to your container registry
57+ uses : docker/login-action@v2
58+ with :
59+ registry : ${{ secrets.DOCKER_REGISTRY }} # Replace with your registry
60+ username : ${{ secrets.DOCKER_USERNAME }}
61+ password : ${{ secrets.DOCKER_PASSWORD }} # Your Docker Hub/registry password
62+
63+ - name : Build and push images
64+ run : |
65+ docker-compose build
66+ docker-compose run --rm backend npm run build # Build backend in the container
67+ docker push ${{ secrets.DOCKER_REGISTRY }}/<your_backend_image_name>:<tag>
68+ docker push ${{ secrets.DOCKER_REGISTRY }}/<your_frontend_image_name>:<tag>
0 commit comments