Merge branch 'docker-healthcheck' into 'master'

Add Shell and Healthcheck to Docker

Closes #1810

See merge request !1182
This commit is contained in:
Marin Jankovski 2017-01-31 11:23:00 +00:00
commit 845b52b242
8 changed files with 146 additions and 0 deletions

View File

@ -6,6 +6,7 @@ omnibus-gitlab repository.
8.17.0
- Remove deprecated Elasticsearch configuration options
- Add HealthCheck support to our Docker image
8.16.3

View File

@ -89,6 +89,7 @@ dependency "gitlab-shell"
dependency "gitlab-workhorse"
dependency "gitlab-ctl"
dependency "gitlab-psql"
dependency "gitlab-healthcheck"
dependency "gitlab-cookbooks"
dependency "gitlab-selinux"
dependency "gitlab-scripts"

View File

@ -0,0 +1,58 @@
#
# Copyright:: Copyright (c) 2016 GitLab Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
name "gitlab-healthcheck"
license "Apache-2.0"
license_file File.expand_path("LICENSE", Omnibus::Config.project_root)
# This 'software' is self-contained in this file. Use the file contents
# to generate a version string.
default_version Digest::MD5.file(__FILE__).hexdigest
build do
block do
open("#{install_dir}/bin/gitlab-healthcheck", "w") do |file|
file.print <<-EOH
#!/bin/sh
error_echo()
{
echo "$1" 2>& 1
}
gitlab_healthcheck_rc='/opt/gitlab/etc/gitlab-healthcheck-rc'
if ! [ -f ${gitlab_healthcheck_rc} ] ; then
exit 1
fi
. ${gitlab_healthcheck_rc}
if [ "$(id -n -u)" = "${psql_user}" ] ; then
privilege_drop=''
else
privilege_drop="-u ${psql_user}"
fi
exec /opt/gitlab/embedded/bin/curl $@ ${host}:${port}${path}
EOH
end
end
command "chmod 755 #{install_dir}/bin/gitlab-healthcheck"
end

View File

@ -1,6 +1,8 @@
FROM ubuntu:16.04
MAINTAINER Kamil Trzciński <kamil@gitlab.com>
SHELL ["/bin/sh", "-c"],
# Install required packages
RUN apt-get update -q \
&& DEBIAN_FRONTEND=noninteractive apt-get install -yq --no-install-recommends \
@ -36,3 +38,6 @@ VOLUME ["/etc/gitlab", "/var/opt/gitlab", "/var/log/gitlab"]
# Wrapper to handle signal, trigger runit and reconfigure GitLab
CMD ["/assets/wrapper"]
HEALTHCHECK --interval=60s --timeout=30s --retries=5 \
CMD /opt/gitlab/bin/healthcheck --fail

View File

@ -133,6 +133,9 @@ include_recipe "gitlab::logrotate_folders_and_configs"
end
end
# Configure healthcheck if we have the external_url set
include_recipe "gitlab::gitlab-healthcheck" if Gitlab['external_url']
# Recipe which handles all prometheus related services
include_recipe "gitlab::gitlab-prometheus"

View File

@ -0,0 +1,31 @@
#
# Copyright:: Copyright (c) 2016 GitLab Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
server_host = node['gitlab']['nginx']['enable'] ? 'localhost' : Gitlab['gitlab_rails']['gitlab_host']
server_schema = node['gitlab']['gitlab-rails']['gitlab_https'] ? 'https' : 'http'
template "/opt/gitlab/etc/gitlab-healthcheck-rc" do
owner 'root'
group 'root'
variables (
{
host: "#{server_schema}://#{server_host}",
port: node['gitlab']['nginx']['listen_port'],
path: "#{Gitlab['gitlab_rails']['gitlab_relative_url']}/help"
}
)
end

View File

@ -0,0 +1,3 @@
host='<%= @host %>'
port='<%= @port %>'
path='<%= @path %>'

View File

@ -0,0 +1,44 @@
require 'chef_helper'
describe 'gitlab::gitlab-healthcheck' do
let(:chef_run) { ChefSpec::SoloRunner.converge('gitlab::default') }
before do
allow(Gitlab).to receive(:[]).and_call_original
end
it 'correctly renders out the healthcheck-rc file using localhost when nginx is enabled' do
stub_gitlab_rb(external_url: 'http://gitlabe.example.com')
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{host='http://localhost'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{port='80'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{path='/help'})
end
it 'correctly renders out the healthcheck-rc file when using hostname when nginx is disabled' do
stub_gitlab_rb(external_url: 'http://gitlabe.example.com', nginx: { enable: false })
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{host='http://gitlabe.example.com'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{port='80'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{path='/help'})
end
it 'correctly renders out the healthcheck-rc file when using https' do
stub_gitlab_rb(external_url: 'https://gitlabe.example.com')
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{host='https://localhost'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{port='443'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{path='/help'})
end
it 'correctly renders out the healthcheck-rc file when using custom port' do
stub_gitlab_rb(external_url: 'http://gitlabe.example.com:8080')
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{host='http://localhost'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{port='8080'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{path='/help'})
end
it 'correctly renders out the healthcheck-rc file when using a relative url' do
stub_gitlab_rb(external_url: 'http://gitlabe.example.com/custom')
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{host='http://localhost'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{port='80'})
expect(chef_run).to render_file("/opt/gitlab/etc/gitlab-healthcheck-rc").with_content(%r{path='/custom/help'})
end
end