Unified Backups: Add gitlab-backup-cli to Omnibus

- Adds wrapper around `gitlab-backup-cli` command
- Adds recipe and template for `gitlab-backup-cli` yaml configuration

Closes https://gitlab.com/gitlab-org/omnibus-gitlab/-/issues/8273

Changelog: added
This commit is contained in:
Javiera Tapia 2024-04-03 02:49:59 +00:00 committed by Robert Marshall
parent 05b9bc0a08
commit e19a65e32e
8 changed files with 141 additions and 0 deletions

View File

@ -149,6 +149,7 @@ dependency 'gitlab-cookbooks'
dependency 'chef-acme'
dependency 'gitlab-ctl'
dependency 'gitlab-psql'
dependency 'gitlab-backup-cli'
dependency 'gitlab-redis-cli'
dependency 'gitlab-healthcheck'

View File

@ -0,0 +1,30 @@
#
# Copyright:: Copyright (c) 2024 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-backup-cli'
license 'Apache-2.0'
license_file File.expand_path('LICENSE', Omnibus::Config.project_root)
skip_transitive_dependency_licensing true
build do
# Create a wrapper for the gitlab-backup-cli tool
erb dest: "#{install_dir}/bin/gitlab-backup-cli",
source: 'gitlab_backup_cli_wrapper.erb',
mode: 0755,
vars: { install_dir: install_dir }
end

View File

@ -0,0 +1,26 @@
#!/usr/bin/env bash
set -euo pipefail
# Export the environment variables
PATH="/opt/gitlab/embedded/bin${PATH+:}${PATH}"
export PATH
export GITLAB_BACKUP_CLI_CONFIG_FILE="<%= install_dir %>/etc/gitlab-backup-cli-config.yml"
gitlab_backup_cli="<%= install_dir %>/embedded/service/gitlab-rails/bin/gitlab-backup-cli"
error_echo()
{
echo "$1" >&2
}
if [[ ! -f ${gitlab_backup_cli} ]] ; then
error_echo "$0 error: could not load ${gitlab_backup_cli}"
error_echo "Either you are not allowed to execute the binary, or it does not exist yet."
error_echo "You can generate it with: sudo gitlab-ctl reconfigure"
exit 1
fi
# Executes the gitlab-backup-cli tool with embedded ruby
"${gitlab_backup_cli}" "${@}"

View File

@ -83,6 +83,9 @@ include_recipe "gitlab::web-server"
# `account` custom resource will not create them.
include_recipe "gitlab::users"
# Recipe for gitlab-backup-cli tool
include_recipe "gitlab::gitlab-backup-cli"
include_recipe "gitlab::gitlab-rails" if node['gitlab']['gitlab_rails']['enable']
include_recipe "gitlab::selinux"

View File

@ -0,0 +1,26 @@
#
# Copyright:: Copyright (c) 2024 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.
install_dir = node['package']['install-dir']
gitlab_backup_cli_config_file = "#{install_dir}/etc/gitlab-backup-cli-config.yml"
template gitlab_backup_cli_config_file do
owner 'root'
group 'root'
mode '0644'
source 'gitlab-backup-cli-config.yml.erb'
sensitive true
end

View File

@ -0,0 +1,9 @@
<% gitlab_rails_dir = node['gitlab']['gitlab_rails']['dir'] %>
<% gitlab_rails_etc_dir = File.join(gitlab_rails_dir, 'etc') %>
version: 1
installation_type: "omnibus"
gitlab:
config_path: <%= File.join(gitlab_rails_etc_dir, 'gitlab.yml') %>
database:
config_path: <%= File.join(gitlab_rails_etc_dir, 'database.yml') %>

View File

@ -12,6 +12,7 @@ usr_bin_symlinks=(
"${DEST_DIR}/bin/gitlab-geo-psql"
"${DEST_DIR}/bin/gitlab-backup"
"${DEST_DIR}/bin/gitlab-redis-cli"
"${DEST_DIR}/bin/gitlab-backup-cli"
)
error_exit()

View File

@ -0,0 +1,45 @@
#
# Copyright:: Copyright (c) 2024 GitLab Inc.
#
# 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.
#
require 'chef_helper'
RSpec.describe 'gitlab::gitlab-backup-cli' do
let(:chef_runner) do
ChefSpec::SoloRunner.new do |node|
node.normal['package']['install-dir'] = '/opt/gitlab'
end
end
let(:chef_run) do
chef_runner.converge('gitlab::default')
end
let(:template_path) { '/opt/gitlab/etc/gitlab-backup-cli-config.yml' }
before do
allow(Gitlab).to receive(:[]).and_call_original
end
it 'creates gitlab-backup-cli-config.yml template' do
expect(chef_run).to create_template(template_path).with(
owner: 'root',
group: 'root',
mode: '0644',
source: 'gitlab-backup-cli-config.yml.erb',
sensitive: true
)
end
end