This document outlines the Continuous Integration and Continuous Deployment (CI/CD) setup for the User Service, a Node.js application. This CI/CD pipeline is designed to ensure code quality, run unit and end-to-end tests, and automate deployments.
The CI/CD workflow consists of the following key steps:
-
Unit Tests (unit-test job):
- This job runs whenever there is a push or pull request to the
main
branch. - It checks out the code, sets up Node.js, installs dependencies, and runs unit tests.
- If the unit tests fail, the pipeline will stop, and the pull request cannot be merged.
- This job runs whenever there is a push or pull request to the
-
Build and Deploy (build and deploy jobs):
- The build job runs after successful unit tests on a push to the
main
branch. - It checks out the code, sets up Node.js, and installs dependencies.
- The deploy job, triggered after the build job, deploys the code to a production environment.
- The build job runs after successful unit tests on a push to the
-
End-to-End Tests (test job):
- This job runs after a successful deployment.
- It checks out a separate test repository, installs dependencies, and runs end-to-end tests.
- When code is pushed to the main branch or a pull request is raised against the main branch, the unit-test job is triggered.
- If the unit tests pass, the build job runs to prepare the code.
- After a successful build, the deploy job is triggered to deploy the code.
- Finally, the test job runs end-to-end tests on the deployed code.
To execute the CI/CD workflow, follow these steps:
-
Clone the Repository:
- Clone the User Service repository to your local machine using Git:
git clone https://github.com/raghumntv/user-micro-service.git
- Change your working directory to the cloned repository:
cd user-micro-service
- Clone the User Service repository to your local machine using Git:
-
Push Code to
main
Branch or Raise a Pull Request:- Make changes to the code as needed.
- Push your changes to the
main
branch:git add . git commit -m "Your commit message" git push origin main
- Alternatively, create a new branch, make changes, and raise a pull request against the
main
branch.
-
GitHub Actions Workflow:
- Once you push to the
main
branch or raise a pull request, GitHub Actions will automatically trigger the workflow.
- Once you push to the
-
Monitor Workflow Execution:
- Visit the "Actions" tab on your GitHub repository to monitor the progress and status of the workflow.
- If any of the jobs fail (e.g., unit tests or deployment), you'll receive feedback through GitHub Actions.
-
Merge Pull Requests:
- If you raised a pull request, it can only be merged if the unit tests pass successfully.
- The build and deployment steps will run automatically on the
main
branch after a successful merge.
-
End-to-End Tests:
- After deployment to production, the end-to-end tests will run to verify the functionality of the deployed code.