English

GitLab Components and Workflows

GitFlow and GitLab Flow:

What is GitFlow? GitFlow is a set of guidelines that helps effectively use Git for consistent and productive work. It provides instructions on how to structure branches and manage workflows during software development.

Branching Strategy: It is a development workflow in VCS, Describes how a team collaborates on and merges branches of source code. GitLab Flow: A specific branching strategy within GitLab. Basic Branching Strategy: Introduction of a feature branch for concurrent development. Considerations for Choosing a Strategy: Depends on factors like team requirements, source code management system, deployment environments, and codebase structure.

Basic Git Workflow with GitLab

GitLab integrates seamlessly with Git, creating a centralized repository for teams. Developers use Git locally to create and update code, share changes, and collaborate with the team through git commands like push, fetch, and merge.

In GitLab, a central repository is utilized alongside local Git commands for coding, collaboration, and tracking team changes. GitLab builds upon the fundamental Git workflow, enhancing collaboration across developers, security, and operations teams.

GitLab Workflow

Organizations commonly employ version control systems to streamline workflows, with Git emerging as a preferred choice. GitFlow, a guide for effective Git utilization, is widely embraced for consistent and productive work.

GitLab further enhances Git usage through GitLab Flow, a seamless integration of Git workflows and issue tracking. This approach simplifies software development by channeling all features and fixes to the main branch, alongside supporting production and stable branches. GitLab Flow incorporates best practices, ensuring collaborative feature shipping through a well-defined process. This shift from other source control tools, such as SVN, is attributed to Git's simplified branching and merging capabilities.

Git FlowGitHub FlowGitLab Flow
Feature branch-based workflowFeature-specific branches merged into masterFurther refinement of Git Flow and GitHub Flow
Organizes branches with a structured approachSimplifies merge workflow with lightweight branchesIntegrates Git workflow with an issue tracking system
Feature branches created off MasterAddresses multiple environments, releases, integrationsCreates additional ephemeral branches for features
Work completed in feature branches, merged back to MasterInvolves Master branch in commits, simplifies merge workflowIntegrates with issue tracking and creates dedicated branches
Principles around Continuous DeliverySolves challenges by creating branches for environments/releases
Integration, testing, and destruction of lightweight branches

GitLab Flow simplifies the development process, fostering collaboration among developers, security, and ops teams. It enhances Git's capabilities, providing a consistent and efficient workflow for productive software development.

What is GitLab Flow?

GitLab Flow is a streamlined approach to software development that simplifies the Git workflow by integrating it with an issue tracking system. It's designed to prevent the overhead of releasing, tagging, and merging, making the development process more efficient.

Key Points:

1. Version Control with Git:

  • Git is the preferred version control system, simplifying branching and merging.
  • GitLab Flow enhances Git's capabilities.

2. GitLab Flow Benefits:

  • Provides a seamless software development approach.
  • GitLab Flow is a simpler alternative to GitFlow, combining feature-driven development and feature branches with issue tracking.

3. Main Branch Usage:

  • All features and fixes go directly to the main branch.
  • Production and stable branches coexist alongside the main branch.

4. Production and Stable Branches:

  • GitLab Flow includes production and stable branches alongside the main branch.
  • Production branches facilitate controlled releases.

5. Best Practices and Guidelines:

  • GitLab Flow incorporates a set of best practices and guidelines.
  • Ensures a smooth collaborative process for shipping features.

How GitLab Flow Works:

1. Main Branch as Default: Unlike GitFlow, GitLab Flow works with the 'main' branch right away.

2. Pre-Production Branch:

  • Bug fixes are made in a pre-production branch before merging changes back to the main branch.
  • Multiple pre-production branches can be added, like from main to test, test to acceptance, and acceptance to production.

3. Feature Branching:

  • Teams practice feature branching, maintaining a separate production branch.
  • When 'main' is ready for deployment, it's merged into the production branch and released.

4. Version Maintenance:

  • GitLab Flow is flexible for maintaining different software versions.
  • Teams can create and maintain separate branches (e.g., v1 and v2) to address specific needs or bug fixes.

Benefits of GitLab Flow:

  • Offers a simple, transparent, and effective way to work with Git.
  • Enables collaboration and maintenance of multiple software versions in different environments.
  • Decreases the overhead of releasing, tagging, and merging.
  • Provides an easier way to deploy code.
  • Commits flow downstream, ensuring thorough testing in all environments.
  • Suitable for teams of any size and adaptable to various needs and challenges.

Environment Branches in GitLab:

Branches in GitLab represent different versions of a project's working tree. When you create a new project, GitLab automatically generates a default branch that cannot be deleted. The default branch settings can be configured at various levels—project, subgroup, group, or instance (GitLab components to be explained later).

As your project expands, your team creates additional branches. Each branch signifies a set of changes, allowing parallel development without affecting other branches.

GitLab Flow Example with Environment Branches

Consider a GitLab flow with environment branches like production, pre-production, or release branches, depending on the project's needs. This approach supports versioned releases and continuous delivery.

Workflow Overview:

1. Master Branch:

  • Deploy the master branch to a staging environment initially.

2. Pre-Production Branch:

  • Create a merge request from the master branch to the pre-production branch for deployment.

3. Production Branch:

  • Go live by merging the pre-production branch into the production branch.

Workflow Details:

  • Testing in Environments:

    • The master branch is initially deployed to staging for additional testing, resembling the production environment.
  • Downstream Commit Flow:

    • Commits only flow downstream, ensuring thorough testing in all environments.
  • Hotfix Handling:

    • If a hotfix is needed, develop it on a feature branch and merge it into the master using a merge request.
    • Keep the feature branch until the master passes automatic testing.
    • If manual testing is required, send merge requests from the feature branch to downstream branches.

This workflow ensures that all changes are thoroughly tested in different environments before reaching production. It provides a structured approach for managing versioned releases and handling hotfixes.

Release Branches in GitLab

1. Stable Branches

  • Create stable branches based on the master branch, branching as late as possible.
  • This minimizes the time during which bug fixes need to be applied to multiple branches.

2. Release Branch

  • After announcing a release branch, only add serious bug fixes into that branch.

3. Master Branch

  • Ideally, merge these bug fixes into the master branch first.
  • Cherry-pick these fixes into the release branch afterward.

Upstream First Policy

  • Starting with the master branch ensures that bug fixes are not forgotten when cherry-picking into subsequent releases.
  • Merging into master and then cherry-picking is known as the "upstream first" policy.

Versioning and Tagging

  • Patch Version Increase:
    • Every time a bug fix is added to a release branch, increase the patch version and set a new tag.

Additional Consideration

  • Stable Branch vs. Production Branch:
    • Some projects have a stable branch pointing to the latest released branch's commit.
    • In this flow, having a separate production branch is not common.

This GitLab flow with release branches ensures a systematic approach to handling bug fixes and versioning for external releases. It follows a structured process to minimize the risk of introducing bugs and inconsistencies in subsequent releases.

The GitLab flow introduces the concept of differently-named environment branches, which automatically sync with the master branch. Understanding branches is crucial as they form the foundation of project development.

Branching Tips & Tricks:

  • Default Branch:

    • The default branch (usually named Master) is essential and cannot be deleted.
    • Initially protected against forced pushes to avoid accidental data loss.
  • Branch Management:

    • You can manage branches using:
      • GitLab user interface
      • Command line
      • Branches API

GitLab Branching Benefits:

  • Maintaining Environments:
    • GitLab flow allows the maintenance of multiple environments, keeping staging separate from production.
    • Provides isolation for developers to work on different software versions in various environments.

Deployment Considerations:

  • Variability in Deployment:
    • Unlike some Git flows that assume deploying to production after every feature branch merge, GitLab acknowledges situations where this may not be feasible.
    • Examples include applications with controlled release timings (e.g., iOS apps passing App Store validation) or specific deployment windows.

Production Branch Usage:

  • Creating a Production Branch:

    • In cases where deploying to production isn't immediate after merging a feature branch, you can create a production branch reflecting the deployed code.
  • Deploying New Versions:

    • Deploy a new version by merging the master branch into the production branch.
  • Code in Production:

    • To check the code currently in production, you can inspect the production branch.

This simplified GitLab flow accommodates different deployment scenarios, allowing flexibility in managing multiple environments and addressing challenges associated with controlled release timings or specific deployment windows.

GitLab Workflow Components

Let's now delve into the key components of the GitLab workflow that you'll be utilizing. GitLab employs unique terminology for its components; here is a table showing each of the main GitLab components and what their functionality is known as in other systems you may have previously used:

GitLab ComponentFunctionAlso Known As
ProjectThe core building block for organizing, managing, tracking, and delivering work. It uses issues for collaborative planning.Repository
GroupA collection of projects and/or other groups, functioning like folders to organize and manage related projects.Project
IssueA fundamental planning object within a project. It documents use cases, discusses approaches, estimates effort, tracks time, assigns work, and monitors progress.Story, Narrative, Ticket
EpicA collection of related issues across different groups and projects, aiding in organizing work by theme.Initiatives, Themes
Merge RequestConnects issues to code changes, capturing design, implementation details, discussions (reviews), approvals, testing (CI Pipeline), and security scans.Pull Request
LabelTags used to track and associate work with different initiatives, helping in organizing and categorizing issues.Tag
BoardA visual listing of projects and issues, useful for teams to manage their backlog, prioritize items, and move issues through stages in the project.Kanban
MilestoneRepresents a sprint or deliverable, aiding in organizing code, issues, and merge requests into a cohesive group.Release
RoadmapA visual representation of various epics for the group, providing an overview of planned themes and initiatives.
-

Understanding these components will enhance your experience with the GitLab workflow, ensuring efficient collaboration and project progression.

The GitLab Flow: A Deeper Look

Let's dive into the GitLab Flow, breaking down its stages and understanding how it guides your development journey. The GitLab Flow involves several steps to transform an idea into a deployed solution, covering everything from bugs to features and security vulnerabilities.

GitLab Flow Stages:

Step 1 - Create an Issue

  • Starting Point:
    • Every change in GitLab begins with an Issue.
  • Purpose:
    • Issues serve as a platform for sharing and discussing proposals before and during implementation.
    • Used for tracking tasks, work status, accepting feature proposals, and more.

Step 2 - Create a Merge Request

  • Transition:
    • After creating an Issue and making changes, the next step is to create a Merge Request (MR).
  • Purpose:
    • Merge requests visualize and collaborate on proposed code changes existing as commits on a Git branch.
    • Also known as a pull request.

Step 3 - Commit Your Changes

  • Initiating CI/CD:
    • Submitting a Merge Request triggers the Commit process, initiating the CI pipeline.
  • Repetition:
    • This step repeats as reviews and changes are needed.

Step 4 - CI Pipeline Runs

  • Automation:
    • The CI pipeline runs, performing code builds, running tests, and deploying to the staging environment.
  • Error Handling:
    • If errors or conflicts occur, the pipeline fails, providing error messages for resolution.

Step 5 - Review Apps

  • Live Preview:
    • Review apps offer live previews of changes in a feature branch by creating dynamic environments for merge requests.
  • Accessibility:
    • Allows designers and stakeholders to view changes without checking out branches or running changes locally.

Step 6 - Peer Review and Discussion

  • Collaboration:
    • Peers and stakeholders review changes in the review app, ensuring no conflicts or necessary edits before finalization.

Step 7 - Approve Changes

  • Validation:
    • Changes are approved by a person with merge rights/permissions, signaling readiness for the next step.

Step 8 - Merge; Issue Closed; CD Pipeline Runs

  • Integration:
    • The approved changes are merged into the master, closing the associated issue.
    • The Continuous Delivery (CD) pipeline deploys changes to the production environment.

Step 9 - Monitor

  • Evaluation:
    • Continuous monitoring ensures that changes have the intended effect.
  • Flexibility:
    • GitLab's ease of rollback allows adjustments in case of issues or emerging production needs.

Following this recommended GitLab Flow within a concurrent development lifecycle ensures a streamlined and efficient DevOps process. Each step will be explored in detail as you gain hands-on experience in the system.

Code Review Workflow

Ensuring the highest code quality for production is crucial, and GitLab follows a rigorous review process for every change. Here's a simplified walkthrough of the typical code review workflow:

1. New Merge Request

  • Initiation:
    • The developer (author) creates a merge request (MR) for a change on their branch.

2. Assign and Review

  • Assignment:
    • The developer assigns the MR to a reviewer.
  • Feedback Loop:
    • The reviewer makes comments, addressing aspects that need attention.
    • The reviewer then assigns the MR back to the author.

3. Author's Response

  • Adjustments:
    • The author addresses the reviewer's comments and makes necessary adjustments.
    • The MR is assigned back to the reviewer.

4. Final Review

  • Approval Process:
    • A final reviewer conducts a thorough review, making additional comments if needed.
    • The author, once again, addresses any comments and assigns the MR back to the final reviewer.

5. Merge Approval

  • Approval for Merging:
    • The final reviewer approves the MR, signaling that the changes are ready for merging.

6. Merge Completed

  • Merging Process:
    • With approval, the changes are merged into the main branch, completing the code review.

Additional Notes:

  • Assigning Responsibilities:
    • Either the author or the initial reviewer can assign the MR to the final reviewer.
  • Iterative Cycle:
    • The review cycle repeats as needed until the code meets the required quality standards.

This systematic approach ensures collaboration and feedback between authors and reviewers, guaranteeing that code changes are thoroughly examined before being merged into the main codebase.

Additional Tools Used for Code Review & Collaboration

In addition to its core features, GitLab provides extra tools to enhance collaboration and streamline the development process:

GitLab Snippets

GitLab Snippets provide a space to store and share code snippets and text with other users. They offer a convenient way to exchange and collaborate on specific pieces of code.

Wikis

  • Documentation Hub:
    • GitLab Wikis serve as a separate system for documentation and are integrated into each GitLab project.
    • Enabled by default, Wikis offer a convenient way to keep documentation in the same project without cluttering the repository.
    • Creation of Wiki pages is possible through the web interface or locally using Git, as each Wiki is a separate Git repository.

Web IDE

  • User-Friendly Editor:
    • GitLab's Web IDE editor accelerates and simplifies the contribution process by providing an advanced editor with commit staging.
    • Developers can make changes to multiple files directly from the GitLab interface, making contribution accessible to everyone, regardless of their development experience.
    • The Web IDE is designed for efficiency, combining powerful features from VS Code with improved performance and the ability to securely connect to a remote development environment directly from the Web IDE.

Use GitLab to merge code:

A. Create a new project and issue:

1. Navigate to your group:

  • Go to your GitLab group.

2. Create blank project:

  • Choose to create a blank project.
  • Name it "Second Project."
  • Set Visibility Level to Private.
  • Enable the "Initialize repository with a README" checkbox.
  • Create the project and wait to be redirected to the new project’s main page.

3. Create a new issue:

  • In the left-hand navigation pane, select `Issues`.
  • Select `New issue`.
  • Type "New issue" in the title field.
  • Optionally, add a comment in the Description box.
  • Next to Assignees, select the link for "Assign to me."
  • Select `Create issue`.

B. Create a merge request:

1. Customize merge request:

  • To the right of the "Create merge request" button, select the dropdown arrow.
  • For this exercise, use default settings.
  • Select `Create merge request and branch`.

2. Create merge request:

  • On the New merge request page, use default settings.
  • Select `Create merge request`.

C. Edit files on a branch using GitLab’s Web IDE:

1. Open in Web IDE:

  • On the merge request page, select the arrow to the right of "Code" and choose "Open in Web IDE."
  • Confirm you are on the created branch.

2. Edit README.md:

  • In the file list, select `README.md`.
  • On line 3, type "Edit my README.md file."
  • Select `Create commit…`.
  • For Commit Message, type "Updated the README.md file."
  • Select `Commit`.

D. Verify changes in a merge request:

1. Navigate to the merge request:

  • Navigate to the merge request for the branch you just committed to.

2. Assignee and Changes:

  • Ensure the merge request is assigned to yourself.
  • Select the `Changes` tab.
  • Hover over line 3 and select the comment icon.

3. Review and Resolve:

  • Type a comment and select "Start a review."
  • Select "Finish review" and "Submit review."
  • Pretend someone addressed your comment and select "Resolve thread."

E. Merge the branch and close the merge request:

1. Mark as ready and merge:

  • To mark the merge request ready to merge, select the button next to "Code" and choose "Mark as ready."
  • Select the `Overview` tab.
  • Ensure "Delete source branch" is enabled and select `Merge`.

2. Verify merge:

  • Navigate back to your project's repository.
  • Check the branch you’re on.
  • Verify that the merge added "Edit my README.md file" to `README.md`.

Setting Up Your Organization In GitLab

GitLab provides features to help you organize your organization, projects, and users and manage other issues within the organization according to your business needs. Here are key aspects to consider:

Organization Structure

  • Components:
  • Group Structure: Projects are housed within groups, and groups can have subgroups.
  • Permission Inheritance: Permissions cascade down from top-level groups, allowing controlled access at various levels.
  • Labels and Milestones: Shared labels and milestones are created at higher levels for consistency across subgroups and projects.

User Roles and Permissions

  • Granular Control:
    • Users can have specific roles and varying access levels to different projects.
    • Permissions are inherited downward, allowing you to add users with minimal permissions at the top level and grant higher permissions at the Subgroup or Project level.

Best Practices

  • Label and Milestone Management:
    • Labels and Milestones are created at the top-group level, making them available to all Subgroups and Projects.
    • Implement shared labels at the highest level possible for consistency.

Key Reminders:

  • GitLab's organization structure involves Projects within Groups, which can have Subgroups.
  • Manage permissions efficiently by starting with the least permission and increasing as needed at the Subgroup or Project level.
  • Utilize shared labels and milestones at the highest level for consistent tracking across the organization.

This organizational setup allows for effective project management and collaboration within GitLab, ensuring a streamlined workflow for your development teams.

GitLab Project and Group Visibility

Private

  • Access: Only members of the private project or group have access.
  • Clone and View: Members can clone the project, view the public access directory (/public).
  • Guests: Users with the Guest role cannot clone the project.
  • Subgroups: Private groups can have only private subgroups.

Internal

  • Access: Any authenticated user, including Guest role users, can access.
  • Clone and View: Authenticated users can clone the project, view the public access directory (/public).
  • Internal Content: Only internal members can view internal content.
  • External Users: External users cannot clone the project.

Public

  • Access: Users not authenticated, including Guest role users, have access.
  • Clone and View: Unauthenticated users can clone the project, view the public access directory (/public).
  • Subgroups: Public groups can have public, internal, or private subgroups.
  • Internal Subgroups: Internal groups can have internal or private subgroups.

Key Points:

  • Private: Limited to project or group members, Guests excluded.
  • Internal: Authenticated users, including Guests, can access; internal content limited.
  • Public: Open access, even for unauthenticated users; flexible subgroup visibility options.

GitLab Epics

Epics in GitLab help you efficiently manage your portfolio of projects by tracking groups of related issues that share a common theme across projects and milestones.

Key Points

  • Definition: Epics are defined at the Group level.
  • Content: Epics can contain both issues and other epics as children.
  • Filter and Visibility: Epics can be used as filters in issue lists and boards, providing better visibility of related issues.
  • Roadmap and Gantt Chart: Epics provide visibility on child epics, issue statuses, and the timeline in the roadmap. They also help generate Gantt charts for programs or portfolios.
  • Assignee: Epics do not have an Assignee.
  • Creation: Epics cannot be created at the Project level.

Confidential Epics

  • Visibility: Confidential epics are visible only to members of a project with sufficient permissions.
  • Use Cases: Useful for open source projects or companies to keep security vulnerabilities private or protect sensitive information.

Note: Epics enhance collaboration and organization by providing a structured way to manage related issues and milestones across multiple projects.

GitLab Issues

Issues in GitLab are fundamental for planning and collaborating on development work. They serve as the basic building blocks for tracking and managing tasks, discussions, and ideas within a project.

Key Points

  • Issues are defined within the scope of a project, not a group.
  • Issues only exist within projects. Groups may have boards and lists for managing issues, but the issues themselves are stored in projects subordinate to the group.
  • Groups don't have issues but have epics.
  • An issue can only be the child of a single epic.
  • An issue cannot be added to more than one milestone.
  • Issues can have various properties, including Time Tracking, Weight, Participants and Notifications, Mentions, Related Issues, Related Merge Requests, Comments
  • Each project can define Issue Templates to simplify the creation of common issues for different scenarios.

Quick Actions

Quick Actions are commands that efficiently change an issue. For example:

  • /assign @user: Assigns the issue to a specific user.
  • /close: Closes the issue.
  • /duplicate #issue_number: Closes the current issue as a duplicate, linking to the given open issue.

Confidentiality

Similar to epics, issues can be marked as confidential to prevent information leakage.

Note: GitLab Issues offer a comprehensive way to plan, discuss, and track various aspects of development work within a project.

Labels in GitLab

Labels in GitLab provide a flexible way to categorize Epics, Issues, and Merge Requests, offering powerful capabilities for organizing and managing work items.

Key Points

  • Labels are not exclusive, allowing multiple assignments to an Epic, Issue, or Merge Request.
  • Usage:
    • Project Labels: Assigned to Issues and Merge Requests within a specific project.
    • Group Labels: Applied to Epics, Issues, and Merge Requests in any project within the selected Group or its Subgroups.

Best Practices

  • Create Labels at the Lowest Level to avoid clutter.: Project-level labels should be used within the project only, while Group-level labels should focus on tracking at the Group level across multiple projects or subgroups.
  • Scoped Labels: Use Scoped Labels for workflows, status assignment, and "either/or" situations to avoid clutter and confusion.

Quick Actions

Labels in GitLab can be managed efficiently using quick actions:

  • /label: Assign labels.
  • /unlabel: Remove labels.
  • /relabel: Remove all labels and assign new ones.

Note: GitLab Labels enhance search, filtering, and reporting capabilities, providing a versatile tool for organizing and managing work items.

Handson: Working with projects, issues and labels:

A. Access the Top Level Project:

1. Navigate to My Test Group:

  • Click on Menu > Groups > Your Groups.
  • Open "My Test Group - <USERNAME>."

2. Select the Top Level Project:

  • Choose the Top Level Project created in Lab 1.

B. Create an Issue:

1. Access Issues:

  • On the left sidebar, click on "Issues."

2. Create a New Issue:

  • Select "New issue."
  • Enter "My first issue" in the Title text box.
  • Optionally, add a comment in the Description field.
  • Choose "Assign to me" from the Assignees dropdown.
  • Leave other fields at their defaults.
  • Click "Create issue."

C. Create Custom Labels:

1. Go to Project Information > Labels:

  • On the left sidebar, select "Project information > Labels."

2. Create a New Label:

  • Click on "New label."
  • Enter "Opened" in the Title text box.
  • Assign a background color.
  • Click "Create label."
  • Repeat for labels "Completed" and "Needs documentation" with different colors.
  • Note: These labels are specific to this project.

D. Use a Quick Action:

1. Access Issues and Open an Issue:

  • On the left sidebar, click on "Issues."
  • Open "My first issue."

2. Use a Quick Action:

  • In the comment text box, type "/spend 1 hour."
  • View available quick actions by selecting the link below the text box.
  • Click "Comment."
  • Check the time tracking widget in the right sidebar.

E. Assign Labels to an Issue:

1. Edit Labels:

  • On the right sidebar of "My first issue," select "Edit" in the Labels section.

2. Assign Labels:

  • Choose "Opened" and "Needs documentation" labels.
  • Click away from the Labels section.
  • Ensure that both labels are now applied to the issue.

Warning: This step might not be obvious, but it's crucial to complete the label assignment process.

GitLab CI/CD

GitLab CI/CD is a tool that facilitates software development using continuous methodologies, combining Continuous Integration (CI) and Continuous Delivery (CD) practices.

Continuous Integration (CI) Developers integrate code changes frequently into a shared repository.

  • Developer Workflow: Share code via a Merge Request to a feature branch.
  • Pipeline: Triggers a CI pipeline to build, test, and validate new code.
  • Purpose: Identifies and reduces bugs early.
  • Outcome: Changes are confidently merged into the main code base.

Key Steps:

  1. Developers integrate code changes into a shared repository.
  2. Automated builds and tests validate changes.
  3. Promotes regular code integration and a stable codebase.

Continuous Delivery (CD) CD automates delivering validated code to production environments.

  • Automated Delivery: Automatically pushes the code changes to a staging environment.
  • Continuous Deployment: Optionally, automatically pushes the code changes to production.
  • Purpose: Speeds up application delivery.
  • Outcome: Verified code moves quickly to end users.

Key Aspects:

  1. Aims to automate code delivery to production.
  2. Ensures software is always in a releasable state.
  3. Facilitates quick responses to feedback and feature delivery.
  4. Promotes a reliable and frequent release cycle.

Together, CI and CD in GitLab accelerate the development process, allowing teams to deliver fast and high-quality results to end users.

  • CI helps catch and reduce bugs early in the development cycle.
  • CD moves verified code changes to applications faster, ensuring efficient and reliable software delivery.

Continuous Integration (CI):

Continuous Integration (CI) at GitLab involves developers pushing code changes multiple times a day, receiving immediate feedback on the quality and potential risks of their changes. This practice ensures that each submitted change, even to development branches, undergoes automated and continuous building and testing. These tests verify that the changes meet established guidelines, tests, and code compliance standards.

GitLab itself exemplifies Continuous Integration by subjecting every project push to a set of checks. This approach brings several benefits:

  1. Problems are found right away, making them easier and faster to fix. It's like catching a typo before you finish writing the sentence.
  2. Programmers know their code is constantly checked, boosting their trust in what they're building.
  3. CI reduces the common problem of "it works on my machine" by ensuring that the application is not only functional in the developer's environment but also deployable and capable of running smoothly in a production environment.

Continuous Delivery at GitLab

Continuous Delivery (CD) at GitLab extends the principles of Continuous Integration by not only building and testing code changes automatically but also deploying the application continuously. However, in contrast to Continuous Deployment, CD triggers deployments to production manually, ensuring human oversight and strategic control.

Key Concepts:

1. Automated Deployments to Non-Production Environments:

  • CD automates deploying code changes to non-production environments, such as staging, without requiring human intervention.

2. Manual Deployment to Production:

  • Deploying changes to the production environment involves human oversight and, at times, manual approval for a strategic approach.

Continuous Deployment vs. Continuous Delivery:

  • Continuous Deployment:

    • Automatically deploys the application to production without human intervention.
    • No manual triggering is required.
  • Continuous Delivery:

    • Checks code automatically.
    • Requires manual and strategic intervention to trigger deployments to production.

Benefits of CD:

1. Comprehensive Testing, Including Deployment:

  • Ensures thorough testing, including deployment, before considering a task done.

2. Early Error Detection and Rollback:

  • Releasing smaller changes more frequently catches errors earlier in the development process.
  • Easier rollback of smaller changes when needed.

3. Reliable Deployments and More Releases:

  • Reliable deployments result in more frequent releases of new features.
  • Frequent releases allow for fast and valuable customer feedback, aligning delivered features with customer needs.

4. Fast and Frequent Customer Feedback:

  • The customer feedback loop is integral, providing timely insights and ensuring alignment with customer expectations.

In summary, GitLab CI/CD combines Continuous Integration and Continuous Delivery practices, fostering reliable and customer-focused software releases.

How GitLab CI/CD Works

To leverage GitLab CI/CD, you only need your application code in a Git repository and a configuration file, .gitlab-ci.yml, at the repository's root. This YAML file contains the pipeline definition, specifying build, test, and deployment instructions.

GitLab CI/CD Workflow

1. Discuss Code Implementation in an Issue

Developers initiate discussions and plan code implementation in a GitLab issue, detailing proposed changes and project objectives.

2. Work Locally on Proposed Changes

Clone the Git repository locally and implement proposed changes on a feature branch. Developers commit and test changes locally.

3. Push Commits to Feature Branch

After local testing, push commits to a feature branch in the remote GitLab repository.

4. CI/CD Pipeline Triggered

Pushing changes to the feature branch triggers the GitLab CI/CD pipeline.

5. Automated Scripts Run

The CI/CD pipeline runs automated scripts sequentially or in parallel to:

  • Build and test the application.
  • Create a Review App for previewing changes in an environment similar to localhost.

6. Code Review and Approval

After a successful CI/CD pipeline run, create a Merge Request (MR) to merge the feature branch into the default branch.

7. Get Code Reviewed and Approved

Team members review the MR, provide feedback, and approve changes to ensure code quality and adherence to project standards.

8. Merge Feature Branch into Default Branch

Once the MR is approved, merge the feature branch into the default branch (e.g., main or master).

9. GitLab CI/CD Deploys Changes to Production

GitLab CI/CD automatically deploys changes to a production environment.

10. Rollback in Case of Issues

If issues arise post-deployment, GitLab CI/CD enables the rollback of changes to a previous, stable state.

This GitLab CI/CD workflow ensures a systematic and automated approach to software development, testing, and deployment.

GitLab CI/CD: Key Ingredients

.gitlab-ci.yml

To utilize GitLab CI/CD, you start by defining a pipeline in a YAML file named .gitlab-ci.yml at your project's root. This file, following YAML format, serves as the configuration for your CI/CD pipeline.

Key Elements in .gitlab-ci.yml:

1. Tasks: Define tasks such as testing and deploying your application. 2. Configuration Files and Templates: Include other configuration files and templates. 3. Dependencies and Caches: Specify dependencies and caching. 4. Sequential and Parallel Commands: Outline commands to run sequentially and in parallel. 5. Deployment Location: Specify the deployment location for your application. 6. Automatic or Manual Execution: Decide whether to run scripts automatically or trigger them manually.

Get Started:

  1. Create your first .gitlab-ci.yml file.
  2. Explore possible keywords for the .gitlab-ci.yml file configuration.
  3. Use the pipeline editor to visualize and edit your CI/CD configuration.

The .gitlab-ci.yml file acts as the pipeline definition—a set of instructions specifying stages, jobs, and actions for your CI pipeline. It serves as the "brains," while the GitLab Runner functions as the "body.

GitLab Runner

The GitLab Runner, written in Go, executes jobs specified in the YAML file. It communicates with GitLab through an API, enabling seamless integration. Runners can be configured by your GitLab administrator or set up individually.

Key Points:

1. GitLab Runner Functionality: A lightweight, scalable agent that accesses CI jobs via GitLab CI/CD's coordinator API, performs the job, and reports results to GitLab.

2. Configuration Options: GitLab administrators can set up shared runners across multiple projects. Alternatively, you can configure project-specific runners.

3. Runner Types: Agents (runners) can operate on physical machines or virtual instances. In the .gitlab-ci.yml file, you can specify a container image for job execution.

4. Image and Job Execution: The runner loads the specified image, clones your project, and executes the job locally or within the container.

5. Availability on GitLab.com: For GitLab.com users, SaaS runners for Linux, Windows, and macOS are readily available. Additionally, you can register your custom runners on GitLab.com.

6. Self-Managed Instances: If not using GitLab.com, you can register runners for your self-managed instance or create a runner on your local machine.

Get Started:

1. Create a Runner: Set up a runner on your local machine. 2. Learn More: Explore additional details about GitLab runners.

These points cover the core aspects of GitLab Runners and guide you on setting up and using them effectively.

Runner Architecture

GitLab Runner SaaS For simplicity, GitLab provides SaaS runners on GitLab.com, requiring no additional configuration. These runners, hosted by GitLab, are integrated with GitLab.com, allowing you to build, test, and deploy applications effortlessly. Self-Managed Runners If preferred, you can install and manage your own runners independently.

Key Points:

  1. Integrated SaaS runners on GitLab.com perform CI/CD tasks without manual setup for all projects.

  2. You can install runners in various environments, such as the cloud or self-managed instances.

  3. A runner, separate from the GitLab server, executes instructions defined in your ci-yml file, allowing customization. This is where you author your CI in GitLab.

  4. Runners can operate as single processes or be scaled to form a fleet, facilitating parallel job execution.

  5. Install the GitLab runner binary wherever you can host it, for example, in a Dockerized Runner or a Kubernetes Executor.

Example .gitlab-ci.yml file:

A high-level view of a .gitlab-ci.yaml file is presented below. YAML, a human-readable data format, is commonly used for configuration files in various programming languages. This YAML file resides at the project's root and is version controlled along with your code.

Key Elements:

  • Image Specification: The file begins with an image, sourced from GitLab, a URL, or Docker Hub.

  • Stages Definition: The stages section outlines pipeline stages; in this example, "build" and "deploy" are specified.

  • Build Job: The build section represents the "build" job, indicating the stage as "build" and providing the job script.

  • Deploy Job: The deploy section represents the "deploy" job, specifying the stage as "deploy." Additionally, environment, variables, and an only statement are included for job configuration.

YAML files are stored at the project's root, facilitating version control alongside the codebase.

0
0
0
0