DEV Community

Mandala
Mandala

Posted on

Lesson 3: "Configuring Git and a Basic CI/CD Pipeline on Your Own Server"

In today's tech landscape, automation is crucial for both the speed and quality of application development, especially for startups and small companies. This article will walk you through the basics of setting up Git and configuring a CI/CD pipeline on your own server—ideal if you want full control over your environment and want to avoid external service costs.

1. Installing and Configuring Git on the Server

To get started, install Git on your server:

sudo apt update
sudo apt install git
Enter fullscreen mode Exit fullscreen mode

Next, configure Git:

git config --global user.name "Your Name"
git config --global user.email "youremail@example.com"
Enter fullscreen mode Exit fullscreen mode

2. Creating a Repository

Create a project folder on the server and initialize Git:

mkdir myproject
cd myproject
git init --bare
Enter fullscreen mode Exit fullscreen mode

You now have a repository ready to serve as a central point for your code.

3. Choosing a CI/CD Tool

For CI/CD on your server, you can deploy various tools, such as Jenkins, GitLab CI, or a simple bash script. For beginners, GitLab Runner or Jenkins are solid choices as they are well-documented and easy to configure.

4. Installing GitLab Runner (Example)

If you decide on GitLab Runner:

# Download the installation script
curl -L --output /usr/local/bin/gitlab-runner https://gitlab-runner-downloads.s3.amazonaws.com/latest/binaries/gitlab-runner-linux-amd64
# Grant permissions
chmod +x /usr/local/bin/gitlab-runner
# Add GitLab Runner as a system service
sudo gitlab-runner install --user=gitlab-runner --working-directory=/home/gitlab-runner
# Start the runner
sudo gitlab-runner start
Enter fullscreen mode Exit fullscreen mode

5. Configuring the Pipeline

In a .gitlab-ci.yml file, you can define the steps to run tests and deploy your application:

stages:
  - build
  - test
  - deploy

build-job:
  stage: build
  script:
    - echo "Building the application"
    - ./build.sh

test-job:
  stage: test
  script:
    - echo "Running tests"
    - ./test.sh

deploy-job:
  stage: deploy
  script:
    - echo "Deploying the application"
    - ./deploy.sh
Enter fullscreen mode Exit fullscreen mode

6. Testing and Monitoring the Pipeline

After configuring your pipeline, make sure that each step is running correctly. Regularly check logs and troubleshoot any errors. Monitoring your CI/CD processes will help quickly detect issues and reduce potential risks.

Summary

Setting up Git and a basic CI/CD pipeline on your own server is a great way to gain independence from external providers and have full control over your project. Today, we learned how to set up a repository, select a CI/CD tool, and create a basic pipeline.

If you have any questions or need help, feel free to ask in the comments or our others platforms:
Medium: https://medium.com/@hello_65165
Linkedin https://www.linkedin.com/company/81651982/admin/dashboard/
Instagram: https://www.instagram.com/mandala_software_house/

Image description

Top comments (0)