GitLab Community Edition

Sets up GitLab CE for Git repository management and CI/CD

Script Author

Rowan de Haas's avatar
Rowan de Haas
Script Author

Script Details

Created 4 months ago
Size 2 KB

Tags

Script Content

Raw
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#cloud-config
package_update: true
package_upgrade: true

packages:
  - curl
  - openssh-server
  - ca-certificates
  - tzdata
  - perl
  - postfix

write_files:
  - path: /etc/gitlab/gitlab.rb
    content: |
      external_url 'http://gitlab.localhost'
      
      # PostgreSQL settings
      postgresql['shared_preload_libraries'] = 'pg_stat_statements'
      
      # Redis settings
      redis['bind'] = '127.0.0.1'
      redis['port'] = 6379
      
      # Gitaly settings
      gitaly['configuration'] = {
        storage: [
          {
            name: 'default',
            path: '/var/opt/gitlab/git-data/repositories',
          },
        ],
      }
      
      # Disable components we don't need
      prometheus_monitoring['enable'] = false
      alertmanager['enable'] = false
      node_exporter['enable'] = false
      redis_exporter['enable'] = false
      postgres_exporter['enable'] = false
      gitlab_exporter['enable'] = false
      grafana['enable'] = false
      
      # Email settings
      gitlab_rails['smtp_enable'] = false

runcmd:
  # Configure SSH
  - systemctl enable ssh
  - systemctl start ssh
  
  # Configure Postfix
  - debconf-set-selections <<< "postfix postfix/mailname string localhost"
  - debconf-set-selections <<< "postfix postfix/main_mailer_type string 'Internet Site'"
  - systemctl enable postfix
  - systemctl start postfix
  
  # Install GitLab
  - curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.deb.sh | bash
  - EXTERNAL_URL="http://gitlab.localhost" apt-get install -y gitlab-ce
  
  # Configure GitLab
  - gitlab-ctl reconfigure
  
  # Configure firewall
  - ufw allow http
  - ufw allow https
  - ufw allow ssh
  
  # Get initial root password
  - sleep 60
  - echo "GitLab root password:"
  - cat /etc/gitlab/initial_root_password
  - echo "GitLab available at http://gitlab.localhost"

How to Use This Script

Cloud Provider Examples

Amazon EC2

aws ec2 run-instances
  --image-id ami-12345678
  --instance-type t3.micro
  --user-data file://script.yaml

DigitalOcean

doctl compute droplet create
  --image ubuntu-22-04-x64
  --size s-1vcpu-1gb
  --user-data-file script.yaml
  my-droplet

Google Cloud

gcloud compute instances create
  my-instance
  --metadata-from-file
  user-data=script.yaml