-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall-gitlab.sh
More file actions
executable file
·225 lines (190 loc) · 6.36 KB
/
install-gitlab.sh
File metadata and controls
executable file
·225 lines (190 loc) · 6.36 KB
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
#!/bin/bash -
#===============================================================================
#
# FILE: install-gitlab.sh
#
# USAGE: install-gitlab.sh -h hostname [-v]
# install-gitlab.sh --host hostname [--verbose]
#
# DESCRIPTION: This script will install Gitlab into /opt, and be made
# accessible via the hostname provided. The Mattermost chat
# server will also be installed if you provide a hostname for
# it.
# OPTIONS:
# -h | --host
# The fully qualified domain name of the virtual host you wish
# to use to access GitLab.
# -v | --verbose
# If passed, will show all commands executed.
# REQUIREMENTS: Nginx, Passenger, Yum
# BUGS: ---
# NOTES: ---
# AUTHOR: Jason White (Jason@iDoAWS.com),
# ORGANIZATION: @iDoAWS
# CREATED: 05/17/2016 22:33
# REVISION: 001
#===============================================================================
# Strict mode
set -euo pipefail
IFS=$'\n\t'
# Check for arguments or provide help
if [ $# -eq 0 ] ; then
echo "Usage:"
echo " `basename $0` -h hostname [-v]"
echo " `basename $0` --host hostname [--verbose]"
echo "This should be run on your staging or production server."
exit 0
fi
# Parse command line arguments into variables
while :
do
case ${1:-} in
-h | --host)
HOST="$2"
shift 2
;;
-v | --verbose)
VERBOSE=true
shift 1
;;
-*)
echo "Error: Unknown option: $1" >&2
exit 1
;;
*) # No more options
break
;;
esac
done
# Validate arguments
if [ ! -v HOST ] ; then
echo 'Host name is required.'
exit 1
else
URL="http://$HOST"
fi
if [ -f /etc/nginx/sites-available/$HOST\.conf ] ; then
echo 'Virtual host configuration already exists.'
exit 1
fi
if [ -L /etc/nginx/sites-enabled/$HOST\.conf ] ; then
echo 'Virtual host configuration is already enabled.'
exit 1
fi
# Check verbosity
if [ -v VERBOSE ] ; then
set -v
fi
# Remove pre-existing config if it exists
if [ -f /etc/gitlab/gitlab.rb ] ; then
sudo rm -rf /etc/gitlab/gitlab.rb
fi
# Check for Gitlab Repo
curl -sS https://packages.gitlab.com/install/repositories/gitlab/gitlab-ce/script.rpm.sh | sudo bash
# Run Yum installer
sudo yum install gitlab-ce -y
sudo gitlab-ctl reconfigure
# Configure Gitlab to use our pre-existing services
# http://docs.gitlab.com/omnibus/settings/nginx.html#using-an-existing-passengernginx-installation
echo "
## Disable internal servers
nginx['enable'] = false
unicorn['enable'] = false
## Set URL
gitlab_rails['internal_api_url'] = '$URL'
" | sudo tee -a /etc/gitlab/gitlab.rb
# Recompile Gitlab
sudo gitlab-ctl reconfigure
# Create & enable virtual host
echo "upstream gitlab-workhorse {
server unix://var/opt/gitlab/gitlab-workhorse/socket fail_timeout=0;
}
server {
listen *:80;
server_name $HOST;
server_tokens off;
root /opt/gitlab/embedded/service/gitlab-rails/public;
client_max_body_size 250m;
access_log /opt/nginx/logs/$HOST-access.log;
error_log /opt/nginx/logs/$HOST-error.log;
# Ensure Passenger uses the bundled Ruby version
passenger_ruby /opt/gitlab/embedded/bin/ruby;
# Correct the PATH variable to included packaged executables
passenger_env_var PATH "/opt/gitlab/bin:/opt/gitlab/embedded/bin:/usr/local/bin:/usr/bin:/bin";
# Make sure Passenger runs as the correct user and group to
# prevent permission issues
passenger_user git;
passenger_group git;
# Enable Passenger & keep at least one instance running at all times
passenger_enabled on;
passenger_min_instances 1;
location ~ ^/[\w\.-]+/[\w\.-]+/(info/refs|git-upload-pack|git-receive-pack)$ {
# 'Error' 418 is a hack to re-use the @gitlab-workhorse block
error_page 418 = @gitlab-workhorse;
return 418;
}
location ~ ^/[\w\.-]+/[\w\.-]+/repository/archive {
# 'Error' 418 is a hack to re-use the @gitlab-workhorse block
error_page 418 = @gitlab-workhorse;
return 418;
}
location ~ ^/api/v3/projects/.*/repository/archive {
# 'Error' 418 is a hack to re-use the @gitlab-workhorse block
error_page 418 = @gitlab-workhorse;
return 418;
}
# Build artifacts should be submitted to this location
location ~ ^/[\w\.-]+/[\w\.-]+/builds/download {
client_max_body_size 0;
# 'Error' 418 is a hack to re-use the @gitlab-workhorse block
error_page 418 = @gitlab-workhorse;
return 418;
}
# Build artifacts should be submitted to this location
location ~ /ci/api/v1/builds/[0-9]+/artifacts {
client_max_body_size 0;
# 'Error' 418 is a hack to re-use the @gitlab-workhorse block
error_page 418 = @gitlab-workhorse;
return 418;
}
location @gitlab-workhorse {
## https://github.com/gitlabhq/gitlabhq/issues/694
## Some requests take more than 30 seconds.
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
# Do not buffer Git HTTP responses
proxy_buffering off;
proxy_set_header Host \$http_host;
proxy_set_header X-Real-IP \$remote_addr;
proxy_set_header X-Forwarded-For \$proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto \$scheme;
proxy_pass http://gitlab-workhorse;
## The following settings only work with NGINX 1.7.11 or newer
#
## Pass chunked request bodies to gitlab-workhorse as-is
# proxy_request_buffering off;
# proxy_http_version 1.1;
}
## Enable gzip compression as per rails guide:
## http://guides.rubyonrails.org/asset_pipeline.html#gzip-compression
## WARNING: If you are using relative urls remove the block below
## See config/application.rb under "Relative url support" for the list of
## other files that need to be changed for relative url support
location ~ ^/(assets)/ {
root /opt/gitlab/embedded/service/gitlab-rails/public;
gzip_static on; # to serve pre-gzipped version
expires max;
add_header Cache-Control public;
}
error_page 502 /502.html;
}" | sudo tee /etc/nginx/sites-available/$HOST.conf
sudo ln -s /etc/nginx/sites-available/$HOST.conf /etc/nginx/sites-enabled/$HOST.conf
# Add Nginx user to gitlab-www
sudo usermod -aG gitlab-www nginx
# Restart Nginx
sudo service nginx restart
echo
echo "Gitlab has been successfully installed, visit the URL below to get started!"
echo "$URL"
echo