Commit c1015bb0 authored by Robert Marshall's avatar Robert Marshall Committed by Ash McKenzie

Import EE License Automatically During Install

- Represent the path to an Enterprise Edition license file using the
  environment variable `GITLAB_LICENSE_FILE`
- Document how to properly configure `GITLAB_LICENSE_FILE` environment
  variable in source and omnibus installations.
- Detect and automatically install the GitLab license during source
  installation if present in the `config` directory and named
  `Gitlab.gitlab-license`

Resolves: https://gitlab.com/gitlab-org/gitlab-ee/issues/10808Signed-off-by: default avatarRobert Marshall <rmarshall@gitlab.com>
parent 955d013a
---
title: Allow adding GitLab license at installation time
merge_request: 11244
author:
type: added
# frozen_string_literal: true
default_license_file = Settings.source.dirname + 'Gitlab.gitlab-license'
license_file = Pathname.new(ENV.fetch('GITLAB_LICENSE_FILE', default_license_file))
# Do not fail if the license was not specified in configuration or a file
# placed at the expected locations.
if license_file.exist?
if ::License.new(data: license_file.read).save
puts "License Added:\n\nFilePath: #{license_file}".color(:green)
else
puts "License Invalid:\n\nFilePath: #{license_file}".color(:red)
raise "License Invalid"
end
elsif !ENV['GITLAB_LICENSE_FILE'].blank?
puts "License File Missing:\n\nFilePath: #{license_file}".color(:red)
raise "License File Missing"
end
# frozen_string_literal: true
require 'spec_helper'
describe 'Automated License Installation' do
subject { load Rails.root.join('ee', 'db', 'fixtures', 'production', '010_license.rb') }
it 'works when no license to be installed' do
expect { subject }.not_to raise_error
end
context 'when GITLAB_LICENSE_FILE env variable is set' do
let(:license_path) { 'arbitrary_file_name' }
before do
stub_env('GITLAB_LICENSE_FILE', license_path)
end
it 'fails when the file does not exist' do
license_file = double('Pathname', exist?: false)
allow(Pathname).to receive(:new).and_call_original
expect(Pathname).to receive(:new).with(license_path).and_return(license_file)
expect { subject }.to raise_error(RuntimeError, "License File Missing")
end
context 'when the file does exist' do
before do
license_file = double('Pathname', exist?: true, read: license_file_contents)
allow(Pathname).to receive(:new).and_call_original
expect(Pathname).to receive(:new).with(license_path).and_return(license_file)
end
context 'and contains a valid license' do
let(:license_file_contents) { 'valid contents' }
it 'succeeds in adding the license' do
license = double('License', save: true)
expect(License).to receive(:new).with(data: license_file_contents).and_return(license)
expect { subject }.not_to raise_error
end
end
context 'but does not contain a valid license' do
let(:license_file_contents) { 'invalid contents' }
it 'fails to add the license' do
license = double('License', save: false)
expect(License).to receive(:new).with(data: license_file_contents).and_return(license)
expect { subject }.to raise_error(RuntimeError, "License Invalid")
end
end
end
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment