🦊

GitLab

CI/CD & DevOps

Plataforma DevOps completa con repositorio Git, pipelines CI/CD y gestión de proyectos

Deployment Info

Despliegue: 2-5 min
categoría: CI/CD & DevOps
Apoyo: 24/7

Share this guide

Overview

GitLab is a complete DevOps platform delivered as a single application that covers the entire software development lifecycle from planning to production. Unlike traditional tools that require integrating multiple separate products, GitLab provides source code management, CI/CD pipelines, security scanning, container registry, project management, monitoring, and more - all in one unified interface. This "single application" approach eliminates integration complexity and provides seamless workflows across the entire development process.

At its core, GitLab is a Git repository manager with advanced features like merge requests (similar to GitHub pull requests), code review workflows, protected branches, and approval rules. The built-in code editor and Web IDE allow you to make changes directly in the browser, while features like code intelligence, blame, and history make navigation and understanding code straightforward. GitLab supports unlimited private repositories, wikis, issue tracking, and milestones right out of the box.

GitLab CI/CD is where the platform truly shines. Define pipelines as code using .gitlab-ci.yml files in your repository, and GitLab automatically builds, tests, and deploys your applications. The CI/CD system supports complex workflows with stages, parallel jobs, manual gates, environments, and deployment strategies like canary and blue-green. GitLab Runners execute your jobs and can run anywhere - on your servers, in Docker, Kubernetes, or cloud VMs, giving you complete control over your build environment.

Security is integrated at every step with GitLab's DevSecOps features. Static Application Security Testing (SAST), Dynamic Application Security Testing (DAST), dependency scanning, container scanning, and license compliance checks run automatically in your pipelines, surfacing vulnerabilities before code reaches production. The Security Dashboard provides a single view of all security findings across projects, making it easy to track and remediate issues.

GitLab's Container Registry and Package Registry are built-in, so you can store Docker images, npm packages, Maven artifacts, PyPI packages, and more right alongside your code. Kubernetes integration allows you to deploy to clusters directly from merge requests, with automatic review apps, canary deployments, and rollback capabilities. The Auto DevOps feature can automatically detect your application type and generate CI/CD pipelines without any configuration.

Key Features

Complete DevOps Platform

Source control, CI/CD, security, monitoring, and more in a single application

Built-in CI/CD

Powerful pipelines with unlimited parallel jobs, Docker support, and Kubernetes integration

DevSecOps Integration

Automated security scanning (SAST, DAST, dependency, container) in every pipeline

Container & Package Registry

Built-in Docker registry and multi-format package repository (npm, Maven, PyPI, etc.)

Kubernetes Deployment

Native K8s integration with auto review apps, canary deploys, and monitoring

Self-Hosted or Cloud

Deploy on your infrastructure or use GitLab.com SaaS - same features both ways

Common Use Cases

• **Full CI/CD Pipelines**: Automate building, testing, and deploying applications with GitLab CI/CD
• **Kubernetes Deployments**: Deploy containerized apps to Kubernetes with built-in monitoring and auto-scaling
• **Security Scanning**: Integrate security testing into every merge request with automated SAST/DAST/dependency scanning
• **Enterprise Source Control**: Manage large codebases with advanced branching, code review, and compliance features
• **Package Management**: Host private packages (Docker, npm, Maven, PyPI) alongside your source code
• **Multi-Team Collaboration**: Organize projects into groups, manage permissions, and track work across teams

Installation Guide

**Installation on Ubuntu 20.04/22.04:**

1. **Install Dependencies:**
```bash
sudo apt update
sudo apt install -y curl openssh-server ca-certificates tzdata perl
```

2. **Install Postfix (for email notifications):**
```bash
sudo apt install -y postfix
# Select "Internet Site" and configure your domain
```

3. **Add GitLab Package Repository:**
```bash
curl https://packages.gitlab.com/install/repositories/gitlab/gitlab-ee/script.deb.sh | sudo bash
```

4. **Install GitLab (Community Edition):**
```bash
# Set your domain (or IP)
export EXTERNAL_URL="https://gitlab.yourdomain.com"

# Install GitLab CE
sudo EXTERNAL_URL=$EXTERNAL_URL apt install gitlab-ce

# Check installation status
sudo gitlab-ctl status
```

5. **Get Initial Root Password:**
```bash
# Password is auto-generated and stored here
sudo cat /etc/gitlab/initial_root_password
# Login as: root / <password>
# Change password immediately after first login
```

6. **Configure GitLab:**
```bash
sudo nano /etc/gitlab/gitlab.rb

# Essential settings:
external_url 'https://gitlab.yourdomain.com'
gitlab_rails['gitlab_shell_ssh_port'] = 22
gitlab_rails['time_zone'] = 'UTC'

# Email settings
gitlab_rails['smtp_enable'] = true
gitlab_rails['smtp_address'] = "smtp.gmail.com"
gitlab_rails['smtp_port'] = 587
gitlab_rails['smtp_user_name'] = "your-email@gmail.com"
gitlab_rails['smtp_password'] = "your-app-password"
gitlab_rails['smtp_domain'] = "gmail.com"
gitlab_rails['smtp_authentication'] = "login"
gitlab_rails['smtp_enable_starttls_auto'] = true
gitlab_rails['gitlab_email_from'] = 'gitlab@yourdomain.com'

# Reconfigure after changes
sudo gitlab-ctl reconfigure
```

7. **Install GitLab Runner:**
```bash
# Add GitLab Runner repository
curl -L "https://packages.gitlab.com/install/repositories/runner/gitlab-runner/script.deb.sh" | sudo bash

# Install
sudo apt install gitlab-runner

# Check status
sudo gitlab-runner status
```

8. **Register GitLab Runner:**
```bash
# Get registration token from:
# GitLab UI → Admin → CI/CD → Runners

sudo gitlab-runner register \
--url https://gitlab.yourdomain.com \
--registration-token YOUR_TOKEN \
--executor docker \
--docker-image docker:20.10 \
--docker-privileged \
--docker-volumes /var/run/docker.sock:/var/run/docker.sock
```

9. **Enable Let's Encrypt SSL:**
```bash
sudo nano /etc/gitlab/gitlab.rb

# Add:
letsencrypt['enable'] = true
letsencrypt['contact_emails'] = ['admin@yourdomain.com']
external_url 'https://gitlab.yourdomain.com'

# Apply
sudo gitlab-ctl reconfigure
```

10. **Access GitLab:**
- Navigate to https://gitlab.yourdomain.com
- Login with root and initial password
- Create your first project and add .gitlab-ci.yml!

Configuration Tips

**Essential Configuration:**

1. **Basic CI/CD Pipeline (.gitlab-ci.yml):**
```yaml
stages:
- build
- test
- deploy

variables:
DOCKER_IMAGE: myapp:$CI_COMMIT_SHORT_SHA

build:
stage: build
image: docker:20.10
services:
- docker:20.10-dind
script:
- docker build -t $DOCKER_IMAGE .
- docker push $DOCKER_IMAGE
only:
- main

test:
stage: test
image: node:18
script:
- npm install
- npm test
coverage: '/Coverage: \d+\.\d+%/'

deploy_production:
stage: deploy
image: bitnami/kubectl:latest
script:
- kubectl set image deployment/myapp myapp=$DOCKER_IMAGE
environment:
name: production
url: https://app.yourdomain.com
only:
- main
when: manual
```

2. **Docker-in-Docker Configuration:**
```yaml
services:
- docker:20.10-dind

variables:
DOCKER_TLS_CERTDIR: "/certs"
DOCKER_HOST: tcp://docker:2376
DOCKER_TLS_VERIFY: 1
DOCKER_CERT_PATH: "$DOCKER_TLS_CERTDIR/client"
```

3. **Kubernetes Deployment:**
```yaml
deploy:
image: bitnami/kubectl:latest
script:
- kubectl config set-cluster k8s --server="$KUBE_URL" --insecure-skip-tls-verify=true
- kubectl config set-credentials admin --token="$KUBE_TOKEN"
- kubectl config set-context default --cluster=k8s --user=admin
- kubectl config use-context default
- kubectl apply -f k8s/deployment.yml
- kubectl rollout status deployment/myapp
```

4. **Security Scanning:**
```yaml
include:
- template: Security/SAST.gitlab-ci.yml
- template: Security/Dependency-Scanning.gitlab-ci.yml
- template: Security/Container-Scanning.gitlab-ci.yml
```

**Best Practices:**
- Use protected branches for main/production
- Enable merge request approvals
- Configure branch protection rules
- Use CI/CD variables for secrets
- Enable Auto DevOps for quick starts
- Set up monitoring and alerting
- Regular backups with gitlab-backup
- Use object storage for artifacts in production

Califica este artículo

-
Loading...

¿Listo para implementar su aplicación? ?

Get started in minutes with our simple VPS deployment process

No se requiere tarjeta de crédito para registrarse • Implementación en 2 a 5 minutos