Skip to content

Commit

Permalink
Add CI/CD Pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
ShrujanaReddy committed Aug 9, 2024
1 parent 2b5df23 commit bdeb457
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: Node.js CI

on:
push:
branches: ["main"]
pull_request:
branches: ["main"]

jobs:
build:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v3

- name: Build Docker image
run: cd todo-app && docker-compose build

- name: Run Docker Compose file
run: cd todo-app && docker-compose up -d & sleep 5

- name: Run unit tests
run: cd todo-app && docker-compose run app npm test

- name: Run integration tests
run: |
cd todo-app
docker-compose run app npx sequelize-cli db:drop
docker-compose run app npx sequelize-cli db:create
docker-compose run app npx sequelize-cli db:migrate
docker-compose run app npm run start:dev &
sleep 5
docker-compose run app npm install cypress cypress-json-results
docker-compose run app npx cypress run
- name: Stop and remove Docker containers
run: cd todo-app && docker-compose down

- name: Setup SSH
run: |
mkdir -p ~/.ssh
echo "${{ secrets.SERVER_SSH_KEY }}" > ~/.ssh/id_rsa
chmod 600 ~/.ssh/id_rsa
ssh-keyscan github.com >> ~/.ssh/known_hosts
- name: Deploy to the server
uses: appleboy/[email protected]
with:
host: ${{ secrets.SERVER_HOST }}
username: ${{ secrets.SERVER_USER }}
key: ${{ secrets.SERVER_SSH_KEY }}
script: |
docker todo-app:latest
docker stop todo-app || true
docker rm todo-app || true
docker run -d --name todo-app -p 80:80 todo-app:latest

0 comments on commit bdeb457

Please sign in to comment.