diff --git a/config/projects/gitlab.rb b/config/projects/gitlab.rb index c998d46e7b5ed84224e4827c711a7900cdd1a3d8_Y29uZmlnL3Byb2plY3RzL2dpdGxhYi5yYg==..d2bf54938bd310c9865663f7f5c6dec0bb984490_Y29uZmlnL3Byb2plY3RzL2dpdGxhYi5yYg== 100644 --- a/config/projects/gitlab.rb +++ b/config/projects/gitlab.rb @@ -149,6 +149,7 @@ dependency 'chef-acme' dependency 'gitlab-ctl' dependency 'gitlab-psql' +dependency 'gitlab-backup-cli' dependency 'gitlab-redis-cli' dependency 'gitlab-healthcheck' diff --git a/config/software/gitlab-backup-cli.rb b/config/software/gitlab-backup-cli.rb new file mode 100644 index 0000000000000000000000000000000000000000..d2bf54938bd310c9865663f7f5c6dec0bb984490_Y29uZmlnL3NvZnR3YXJlL2dpdGxhYi1iYWNrdXAtY2xpLnJi --- /dev/null +++ b/config/software/gitlab-backup-cli.rb @@ -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 diff --git a/config/templates/gitlab-backup-cli/gitlab_backup_cli_wrapper.erb b/config/templates/gitlab-backup-cli/gitlab_backup_cli_wrapper.erb new file mode 100644 index 0000000000000000000000000000000000000000..d2bf54938bd310c9865663f7f5c6dec0bb984490_Y29uZmlnL3RlbXBsYXRlcy9naXRsYWItYmFja3VwLWNsaS9naXRsYWJfYmFja3VwX2NsaV93cmFwcGVyLmVyYg== --- /dev/null +++ b/config/templates/gitlab-backup-cli/gitlab_backup_cli_wrapper.erb @@ -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}" "${@}" diff --git a/files/gitlab-cookbooks/gitlab/recipes/default.rb b/files/gitlab-cookbooks/gitlab/recipes/default.rb index c998d46e7b5ed84224e4827c711a7900cdd1a3d8_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kZWZhdWx0LnJi..d2bf54938bd310c9865663f7f5c6dec0bb984490_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9kZWZhdWx0LnJi 100644 --- a/files/gitlab-cookbooks/gitlab/recipes/default.rb +++ b/files/gitlab-cookbooks/gitlab/recipes/default.rb @@ -83,6 +83,9 @@ # `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" diff --git a/files/gitlab-cookbooks/gitlab/recipes/gitlab-backup-cli.rb b/files/gitlab-cookbooks/gitlab/recipes/gitlab-backup-cli.rb new file mode 100644 index 0000000000000000000000000000000000000000..d2bf54938bd310c9865663f7f5c6dec0bb984490_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItYmFja3VwLWNsaS5yYg== --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/recipes/gitlab-backup-cli.rb @@ -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 diff --git a/files/gitlab-cookbooks/gitlab/templates/default/gitlab-backup-cli-config.yml.erb b/files/gitlab-cookbooks/gitlab/templates/default/gitlab-backup-cli-config.yml.erb new file mode 100644 index 0000000000000000000000000000000000000000..d2bf54938bd310c9865663f7f5c6dec0bb984490_ZmlsZXMvZ2l0bGFiLWNvb2tib29rcy9naXRsYWIvdGVtcGxhdGVzL2RlZmF1bHQvZ2l0bGFiLWJhY2t1cC1jbGktY29uZmlnLnltbC5lcmI= --- /dev/null +++ b/files/gitlab-cookbooks/gitlab/templates/default/gitlab-backup-cli-config.yml.erb @@ -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') %> diff --git a/files/gitlab-scripts/symlink_ctl_cmds b/files/gitlab-scripts/symlink_ctl_cmds index c998d46e7b5ed84224e4827c711a7900cdd1a3d8_ZmlsZXMvZ2l0bGFiLXNjcmlwdHMvc3ltbGlua19jdGxfY21kcw==..d2bf54938bd310c9865663f7f5c6dec0bb984490_ZmlsZXMvZ2l0bGFiLXNjcmlwdHMvc3ltbGlua19jdGxfY21kcw== 100755 --- a/files/gitlab-scripts/symlink_ctl_cmds +++ b/files/gitlab-scripts/symlink_ctl_cmds @@ -12,6 +12,7 @@ "${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() diff --git a/spec/chef/cookbooks/gitlab/recipes/gitlab-backup-cli_spec.rb b/spec/chef/cookbooks/gitlab/recipes/gitlab-backup-cli_spec.rb new file mode 100644 index 0000000000000000000000000000000000000000..d2bf54938bd310c9865663f7f5c6dec0bb984490_c3BlYy9jaGVmL2Nvb2tib29rcy9naXRsYWIvcmVjaXBlcy9naXRsYWItYmFja3VwLWNsaV9zcGVjLnJi --- /dev/null +++ b/spec/chef/cookbooks/gitlab/recipes/gitlab-backup-cli_spec.rb @@ -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