Research on CI CD - SubarnaSaha08/JUMCMS-Jahangirnagar-University-Medical-Center-Management-System GitHub Wiki
What is Travis CI?
Travis CI is a Continuous Integration (CI) service used to build and test software projects hosted on GitHub, Bitbucket, or GitLab. It automates the testing and deployment of project by running tests in a cloud environment whenever code is pushed to the repository.
Why Travis CI?
1. Simple syntax:
Travis CI’s user-friendly YAML syntax requires fewer lines of configuration. Perfect for developers in small-to-midsize teams who need to maximize the impact of automation and quality control in minutes.
Example
language: python
python:
- "3.8"
install:
- pip install -r requirements.txt
script:
- python3 pytest.py
2. Build Matrix:
Run unit and integration tests across any combination of environments for comprehensive automation and absolute quality.
3. Parallel Builds:
Stop waiting for your pipeline to finish before you can get back to building features or squashing bugs—get faster visual feedback on commits and pull requests with intuitive parallelization.
4. Continuous analysis:
By default, Travis CI runs pipeline with every change to a branch or pull request, with automatic deployments for passing builds.
5. Build stages and conditionals:
Catch failures faster with stages, or layer in smart conditionals, to minimize build minutes and catch edge cases other CI/CD tools lose track of.
6. Configuration simplicity:
No matter how sophisticated your pipelines become, they remain encapsulated within a human-readable, maintainable, and minimal .travis.yml
file.
7. Securely-hosted and scoped secrets:
Access credentials in HashiCorp Vault instance with just a few lines of YAML, or self-encrypt sensitive files and sensitive data for complete control.
8. Docker compatibility:
Run, build, and push Docker images to any registry to test exactly how containerized services will run in production-like environments.
9. Static code and security analyses:
Connect your pipelines to DeepSource, Coveralls, Coverity Scan, SourceClear, and others for deeper guarantees of production viability.
10. Secured builds from the start:
Travis CI uses clean VMs and isolated containers with every build for absolute protection against interference or secret leakage.
11. Others:
- Identify and debug quality issues faster with flexible tooling
- Enable nuanced features for your essential—and unique—pipelines
- Travis CI supports 30+ languages with preconfigured environments that require no setup or additional dependency management tasks
- multi-architecture support
- Leverage the build matrix to test a single codebase against multiple OSs
- Accelerate builds with fine-tuned VMs
Why Not Travis CI?
While Travis CI offers numerous advantages, there are several reasons developers might consider alternatives. Here are a few reasons to not use Travis CI:
1. Limited Free Tier for Open-Source Projects:
- Travis CI significantly reduced its free tier for open-source projects. The limited free minutes (10,000 credits) can be a constraint, especially for larger open-source communities or projects with frequent builds.
2. Slower Build Queues:
- For non-paying users, Travis CI often places jobs in a queue, leading to slower build times. This can be frustrating when compared to CI/CD services that provide faster or more consistent build times without long waits.
3. Complex Pipeline Support:
- Travis CI, though simple to configure, is not as feature-rich as some of its competitors when it comes to managing complex pipelines with dynamic dependencies or workflows. For advanced pipeline orchestration, tools like GitLab CI or Jenkins might be preferable.
4. Less Customization in Build Environments:
- While Travis CI supports Docker and offers some flexibility, it may not provide the same depth of environment customization and control as self-hosted solutions like Jenkins or cloud-hosted alternatives like CircleCI, which offer more options for configuring and managing custom environments.
5. Monorepo Limitations:
- Projects using monorepos may face challenges with Travis CI, as it can be harder to selectively trigger builds based on changes in specific parts of the repository. Other tools like GitHub Actions or CircleCI offer more granular control for monorepos.
6. Scaling Issues for Large Teams:
- For large-scale teams or enterprises, scaling Travis CI may not be as cost-effective compared to other CI/CD platforms that offer better pricing, infrastructure flexibility, or faster execution for larger pipelines, such as GitLab CI or CircleCI.
7. Third-Party Integrations:
- Travis CI supports integrations with various external tools, but other services like GitHub Actions offer a much broader marketplace of pre-built actions and better integration with GitHub repositories, making it easier to use for GitHub-centric projects.
8. Dependency on HashiCorp Vault for Secrets:
- Although Travis CI offers integration with HashiCorp Vault for secrets management, this adds complexity and requires a separate Vault setup. Competing tools like GitHub Actions or GitLab CI offer built-in secrets management without requiring external tools.
9. Resource Constraints for Free Users:
- Travis CI limits the types of VM instances available to non-paying users, which might slow down build times for resource-heavy projects, especially compared to platforms like GitLab CI or CircleCI, which provide larger, more flexible free-tier build environments.
10. Lack of Native Support for Self-Hosting:
- Unlike Jenkins or GitLab CI, Travis CI doesn’t offer an official, easy-to-use self-hosted option. For organizations that require complete control over their CI/CD infrastructure, other tools may be a better fit.
How To Use Travis CI?
1. Sign in to Travis CI
- Go to Travis CI and sign in using your GitHub, Bitbucket, or GitLab account.
- Once signed in, authorize Travis CI to access your repositories.
2. Enable Repository on Travis CI
- After logging in, you’ll see a list of repositories associated with your GitHub (or other source control platform) account.
- Find the repository you want to set up with Travis CI, and click on the toggle to enable Travis CI for that repository.
.travis.yml
File
2. Create a The .travis.yml
file defines the build configuration and the tasks Travis CI will perform. This file must be placed in the root directory of your repository.
Here’s an example of a basic .travis.yml
file for a Python/Django project:
language: python
python:
- "3.8" # Specify the Python version
# Commands to install dependencies
install:
- pip install -r requirements.txt
# Commands to run the tests
script:
- python manage.py test # or pytest if you're using pytest
For other languages or frameworks, you can configure accordingly (e.g., JavaScript, Java, Ruby, etc.).
.travis.yml
to Your Repository
3. Push Once you have created your .travis.yml
file, commit and push it to your repository:
git add .travis.yml
git commit -m "Add Travis CI configuration"
git push
4. Travis CI Build Process
After you push the .travis.yml
file to your repository, Travis CI will automatically start building and testing your code every time a change is pushed to the repository.
You can check the build status on the Travis CI dashboard for your repository or on GitHub itself (Travis CI integrates with GitHub’s checks API to display build results).
5. Build Notifications
Travis CI can send you notifications when a build passes or fails. By default, it sends notifications via email, but you can configure it to use other services like Slack, or disable it altogether in your .travis.yml
file.
Here’s how you can set up notifications:
notifications:
email:
recipients:
- [email protected]
on_success: change # Only notify when the build status changes from fail to pass
on_failure: always # Always notify on failure
6. Deploying from Travis CI
Travis CI can be used for Continuous Deployment (CD) as well. You can configure it to deploy your application automatically to services like Heroku, AWS, GitHub Pages, etc., after a successful build.
Example of deployment to Heroku in .travis.yml
:
deploy:
provider: heroku
api_key:
secure: "<encrypted_api_key>"
app: my-heroku-app-name
on:
repo: mygithubuser/myrepository
To encrypt sensitive information like API keys, you can use the Travis CLI.
Resources:
What is CircleCI?
CircleCI is a Continuous Integration and Continuous Delivery (CI/CD) platform that automates the build, test, and deployment of code changes for software projects hosted on GitHub or Bitbucket. It provides a scalable, cloud-based solution for running automated workflows, enabling development teams to focus on feature creation and bug resolution.
Why CircleCI?
- Efficient Configuration with YAML:
CircleCI uses a single .circleci/config.yml file to define pipelines, jobs, and workflows, making it easy to customize while remaining readable. This syntax is ideal for teams needing both flexibility and clarity in their CI/CD configurations.
Example:
version: 2.1
jobs:
build:
docker:
- image: circleci/python:3.8
steps:
- checkout
- run: pip install -r requirements.txt
- run: pytest
- Workflows and Job Sequencing:
CircleCI’s workflows allow multiple jobs to run sequentially or in parallel, with dependencies and conditions, providing faster and more efficient pipelines.
- Docker and Kubernetes Integration:
Seamlessly deploy and test Docker containers and Kubernetes configurations within CircleCI, ideal for microservices architectures and containerized applications.
- Auto-caching and Resource Classes:
CircleCI automatically caches dependencies and provides various VM options to optimize builds, leading to significantly shorter CI/CD times.
Advanced Security Options:
CircleCI allows for encrypted environment variables and secure contexts, ensuring sensitive information like API keys and tokens remain protected.
- Configuration Flexibility with Orbs:
CircleCI’s reusable Orbs offer modular YAML components, making it easy to standardize complex workflows across multiple projects.
- Automated Deployment and Rollbacks:
Enables zero-downtime deployments and conditional rollbacks with various cloud providers, including AWS, GCP, and Heroku.
- Wide Language and Platform Support:
CircleCI supports multiple programming languages and platforms, making it highly adaptable to different tech stacks.
Why Not CircleCI?
Despite its advantages, CircleCI has some drawbacks to consider:
- Complexity for Simple Workflows:
CircleCI’s extensive feature set can be overwhelming for small teams needing simple pipelines, with other tools potentially offering faster configurations.
- Limited Free Tier Resources:
CircleCI’s free tier provides limited usage, which may be insufficient for larger open-source projects or teams with frequent builds.
- Docker Limitations for Free Plans:
Free-tier Docker builds on CircleCI might face resource constraints, particularly in multi-container workflows.
- Learning Curve:
Although CircleCI is flexible, its advanced configuration options and YAML syntax can pose a steep learning curve for new users.
- Pricing for Premium Features:
Some features, such as private Docker registries or dedicated resource classes, are only available in paid plans, which may not suit every budget.
Installation Process
- Sign Up and Link to a Git Repository:
Go to CircleCI and sign up with a GitHub or Bitbucket account. Authorize CircleCI to access your repositories.
- Create the .circleci/config.yml File:
Place a .circleci/config.yml file in the root of your repository. This file defines your pipeline's jobs, workflows, and build environment.
Example Configuration:
version: 2.1
jobs:
test:
docker:
- image: circleci/node:14
steps:
- checkout
- run: npm install
- run: npm test
- Commit and Push Configuration File:
After configuring .circleci/config.yml, push it to the repository to trigger the initial build.
- View Pipeline Progress:
Access the CircleCI dashboard to monitor pipeline progress. Adjust configurations as needed.
- Deployment:
CircleCI can be configured to automatically deploy on success using a deploy job. For example, to deploy to AWS, you might add the following:
deploy:
docker:
- image: circleci/aws-cli
steps:
- checkout
- run: aws s3 sync . s3://my-bucket
What is GitLab?
GitLab is an open-source DevOps platform providing an integrated solution for Continuous Integration and Continuous Delivery (CI/CD), version control, and project management. It allows development teams to collaborate on code, track project progress, automate testing and deployment, and manage infrastructure as code in a single platform. GitLab’s flexibility makes it a powerful choice for teams of all sizes, from small startups to large enterprises.
Why GitLab?
Comprehensive DevOps Lifecycle Management
GitLab provides an end-to-end DevOps solution, integrating source code management, CI/CD, and monitoring, which minimizes the need to use multiple tools. This unified approach allows teams to manage the entire lifecycle, from planning and development to monitoring and security, on one platform.
Example:
stages:
- build
- test
- deploy
build:
stage: build
script:
- echo "Building project"
test:
stage: test
script:
- echo "Running tests"
deploy:
stage: deploy
script:
- echo "Deploying application"
CI/CD Pipelines with .gitlab-ci.yml
GitLab simplifies pipeline configuration with a single .gitlab-ci.yml file that defines jobs, stages, and rules, making pipelines easy to read, maintain, and customize for different project needs.
Container Registry
GitLab includes a built-in container registry, enabling teams to manage, store, and secure Docker images alongside the codebase. This feature is particularly valuable for containerized and microservices-based applications.
Kubernetes Integration
GitLab integrates with Kubernetes clusters, allowing teams to manage, deploy, and scale applications directly from GitLab, which is highly beneficial for applications running on container orchestration platforms.
Auto DevOps
GitLab’s Auto DevOps feature offers automatic pipelines that build, test, and deploy code based on best practices. This is ideal for teams looking to automate workflows quickly without extensive custom configuration.
Built-in Security Scanning
GitLab performs static and dynamic security scanning within the pipeline, offering vulnerability management without requiring additional third-party tools. Security testing results are displayed directly in the merge request, helping teams identify and address issues early.
Flexible CI/CD with Custom Runners
GitLab allows for custom runners, providing teams with the flexibility to define runner specifications, environments, and resource limits based on project requirements.
Why Not GitLab?
Despite its advantages, there are some limitations to consider:
Complexity for Simple Projects
While GitLab’s extensive features are ideal for large projects, smaller teams might find the platform's setup complex for basic version control and CI/CD needs, especially compared to simpler CI/CD tools.
Performance on Self-Hosted Servers
Self-hosted GitLab instances may require considerable server resources, especially for larger teams. This can lead to additional costs and complexity in managing server infrastructure.
Cost for Premium Features
While GitLab offers a free tier, some advanced features, such as enhanced security scanning and priority support, are available only in premium plans, which may not be feasible for every team.
Learning Curve for Advanced Features
GitLab’s extensive functionality may require a learning curve, especially for teams new to DevOps practices or those without dedicated DevOps engineers.
Installation Process
Sign Up and Configure Repository
Visit GitLab and sign up using a preferred account (e.g., Google, GitHub) or by creating a new one. Create a new project or link an existing repository to GitLab.
Create a .gitlab-ci.yml File
Add a .gitlab-ci.yml file in the project’s root directory, defining the stages, jobs, and conditions for the pipeline. This file governs the CI/CD flow within GitLab.
Example Configuration:
stages:
- test
test:
script:
- echo "Running tests"
Commit and Push Configuration File
After defining .gitlab-ci.yml, commit and push it to trigger the pipeline. GitLab CI/CD will automatically initiate based on the configuration.
Monitor Pipeline
Access the GitLab CI/CD dashboard to monitor job progress, view logs, and adjust settings as required.
Deployment Options
GitLab allows for both automated and manual deployments. For example, a deploy job can be set up to deploy code to a cloud provider like AWS:
deploy:
stage: deploy
script:
- aws s3 sync . s3://my-bucket
Github Actions
What is GitHub Actions?
GitHub Actions is a continuous integration and continuous delivery (CI/CD) platform built into GitHub. It lets you automate tasks within your software development workflow. Instead of manually running tests, deployments, or other actions, you can define these processes in a configuration file. GitHub Actions then automatically executes these tasks based on events like pushing code, creating a pull request, or on a schedule.
Why GitHub Actions?
- Automation: Automate repetitive tasks like building, testing, and deploying code. This saves you time and reduces errors.
- Integration: Seamlessly integrated with GitHub, your code and your automation live in the same place.
- Customization: Highly customizable. You can create simple or complex workflows to match your exact needs.
- Community: A vast marketplace of pre-built actions created by the community, making it easy to get started.
- Cost-effective: Free for public repositories and offers generous free usage for private repositories.
Why not GitHub Actions?
- Learning curve: While generally user-friendly, there's still a learning curve, especially for complex workflows.
- Vendor lock-in: Your CI/CD processes become tied to GitHub. Switching to another platform later might require adjustments.
- Debugging: Troubleshooting complex workflows can sometimes be challenging.
- Security concerns: It's crucial to secure your workflows and secrets to prevent unauthorized access.
Installation Process for a Django Project
Here's a basic example of how to set up GitHub Actions for a Django project. This workflow will run your tests whenever you push code to your repository.
-
Create a Workflow File:
- In your Django project's root directory, create a folder named
.github/workflows
. - Inside that folder, create a YAML file (e.g.,
django-ci.yml
).
- In your Django project's root directory, create a folder named
-
Define the Workflow:
name: Django CI on: push: branches: [ main ] # Run workflow on pushes to the main branch pull_request: branches: [ main ] # Also run on pull requests to the main branch jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 # Checks out your code - name: Set up Python uses: actions/setup-python@v4 with: python-version: '3.10' # Choose your Python version - name: Install dependencies run: | python -m pip install --upgrade pip pip install -r requirements.txt - name: Run tests run: python manage.py test
-
Commit and Push:
- Commit the
.github/workflows/django-ci.yml
file to your repository. - Push the changes to GitHub.
- Commit the
Now, every time you push code to your main
branch or create a pull request, GitHub Actions will automatically run this workflow to execute your Django tests.
Key Improvements for Django:
- Specify Python version: Make sure your workflow uses the correct Python version for your Django project.
- Install dependencies: Include a step to install your project's dependencies from your
requirements.txt
file. - Run tests: Use the
python manage.py test
command to execute your Django tests.
Remember to adjust the workflow file to match your specific Django project setup and testing needs. You can add more steps for linting, code coverage, or even deployment to different environments.