Commit 671f6074 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch 'jv-rake-workhorse-vendored' into 'master'

Let `rake gitlab:workhorse:install` use vendored workhorse

See merge request gitlab-org/gitlab!49250
parents 3d606eb2 34d186be
---
title: Let `rake gitlab:workhorse:install` use vendored workhorse
merge_request: 49250
author:
type: changed
...@@ -210,17 +210,12 @@ sudo -u git -H make build ...@@ -210,17 +210,12 @@ sudo -u git -H make build
### 10. Update GitLab Workhorse ### 10. Update GitLab Workhorse
Install and compile GitLab Workhorse. GitLab Workhorse uses Install and compile GitLab Workhorse.
[GNU Make](https://www.gnu.org/software/make/).
If you are not using Linux you may have to run `gmake` instead of
`make` below.
```shell ```shell
cd /home/git/gitlab-workhorse cd /home/git/gitlab
sudo -u git -H git fetch --all --tags --prune sudo -u git -H bundle exec rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]" RAILS_ENV=production
sudo -u git -H git checkout v$(</home/git/gitlab/GITLAB_WORKHORSE_VERSION)
sudo -u git -H make
``` ```
### 11. Update Gitaly ### 11. Update Gitaly
......
...@@ -8,18 +8,32 @@ namespace :gitlab do ...@@ -8,18 +8,32 @@ namespace :gitlab do
abort %(Please specify the directory where you want to install gitlab-workhorse:\n rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]") abort %(Please specify the directory where you want to install gitlab-workhorse:\n rake "gitlab:workhorse:install[/home/git/gitlab-workhorse]")
end end
# It used to be the case that the binaries in the target directory match
# the source code. An administrator could run `make` to rebuild the
# binaries for instance. Or they could read the source code, or run `git
# log` to see what changed. Or they could patch workhorse for some
# reason and recompile it. None of those things make sense anymore once
# the transition in https://gitlab.com/groups/gitlab-org/-/epics/4826 is
# done: there would be an outdated copy of the workhorse source code for
# the administrator to poke at.
#
# To prevent this possible confusion and make clear what is going on, we
# have created a special branch `workhorse-move-notice` in the old
# gitlab-workhorse repository which contains no Go files anymore, just a
# README explaining what is going on. See:
# https://gitlab.com/gitlab-org/gitlab-workhorse/tree/workhorse-move-notice
#
args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitlab-workhorse.git') args.with_defaults(repo: 'https://gitlab.com/gitlab-org/gitlab-workhorse.git')
checkout_or_clone_version(version: 'workhorse-move-notice', repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1])
version = Gitlab::Workhorse.version _, which_status = Gitlab::Popen.popen(%w[which gmake])
make = which_status == 0 ? 'gmake' : 'make'
command = %W[#{make} -C #{Rails.root.join('workhorse')} install PREFIX=#{File.absolute_path(args.dir)}]
checkout_or_clone_version(version: version, repo: args.repo, target_dir: args.dir, clone_opts: %w[--depth 1]) run_command!(command)
_, status = Gitlab::Popen.popen(%w[which gmake]) # 'make install' puts the binaries in #{args.dir}/bin but the init script expects them in args.dir
command = status == 0 ? 'gmake' : 'make' FileUtils.mv(Dir["#{args.dir}/bin/*"], args.dir)
Dir.chdir(args.dir) do
run_command!([command])
end
end end
end end
end end
#!/bin/sh #!/bin/sh
set -e set -e
WORKHORSE_DIR=workhorse/ WORKHORSE_DIR=workhorse/
WORKHORSE_REF="v$(cat GITLAB_WORKHORSE_VERSION)" WORKHORSE_REF="$(cat GITLAB_WORKHORSE_VERSION)"
WORKHORSE_URL=${GITLAB_WORKHORSE_URL:-https://gitlab.com/gitlab-org/gitlab-workhorse.git} WORKHORSE_URL=${GITLAB_WORKHORSE_URL:-https://gitlab.com/gitlab-org/gitlab-workhorse.git}
if [ $# -gt 1 ] || ([ $# = 1 ] && [ x$1 != xcheck ]); then if [ $# -gt 1 ] || ([ $# = 1 ] && [ x$1 != xcheck ]); then
...@@ -9,6 +9,11 @@ if [ $# -gt 1 ] || ([ $# = 1 ] && [ x$1 != xcheck ]); then ...@@ -9,6 +9,11 @@ if [ $# -gt 1 ] || ([ $# = 1 ] && [ x$1 != xcheck ]); then
exit 1 exit 1
fi fi
if echo "$WORKHORSE_REF" | grep -q '^[0-9]\+\.[0-9]\+\.[0-9]\+' ; then
# Assume this is a tagged release
WORKHORSE_REF="v${WORKHORSE_REF}"
fi
clean="$(git status --porcelain)" clean="$(git status --porcelain)"
if [ -n "$clean" ] ; then if [ -n "$clean" ] ; then
echo 'error: working directory is not clean:' echo 'error: working directory is not clean:'
......
...@@ -10,7 +10,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do ...@@ -10,7 +10,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
describe 'install' do describe 'install' do
let(:repo) { 'https://gitlab.com/gitlab-org/gitlab-workhorse.git' } let(:repo) { 'https://gitlab.com/gitlab-org/gitlab-workhorse.git' }
let(:clone_path) { Rails.root.join('tmp/tests/gitlab-workhorse').to_s } let(:clone_path) { Rails.root.join('tmp/tests/gitlab-workhorse').to_s }
let(:version) { File.read(Rails.root.join(Gitlab::Workhorse::VERSION_FILE)).chomp } let(:workhorse_source) { Rails.root.join('workhorse').to_s }
context 'no dir given' do context 'no dir given' do
it 'aborts and display a help message' do it 'aborts and display a help message' do
...@@ -30,13 +30,9 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do ...@@ -30,13 +30,9 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
end end
describe 'checkout or clone' do describe 'checkout or clone' do
before do
expect(Dir).to receive(:chdir).with(clone_path)
end
it 'calls checkout_or_clone_version with the right arguments' do it 'calls checkout_or_clone_version with the right arguments' do
expect(main_object) expect(main_object)
.to receive(:checkout_or_clone_version).with(version: version, repo: repo, target_dir: clone_path, clone_opts: %w[--depth 1]) .to receive(:checkout_or_clone_version).with(version: 'workhorse-move-notice', repo: repo, target_dir: clone_path, clone_opts: %w[--depth 1])
run_rake_task('gitlab:workhorse:install', clone_path) run_rake_task('gitlab:workhorse:install', clone_path)
end end
...@@ -45,7 +41,6 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do ...@@ -45,7 +41,6 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
describe 'gmake/make' do describe 'gmake/make' do
before do before do
FileUtils.mkdir_p(clone_path) FileUtils.mkdir_p(clone_path)
expect(Dir).to receive(:chdir).with(clone_path).and_call_original
end end
context 'gmake is available' do context 'gmake is available' do
...@@ -56,7 +51,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do ...@@ -56,7 +51,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
it 'calls gmake in the gitlab-workhorse directory' do it 'calls gmake in the gitlab-workhorse directory' do
expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0]) expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['/usr/bin/gmake', 0])
expect(main_object).to receive(:run_command!).with(['gmake']).and_return(true) expect(main_object).to receive(:run_command!).with(["gmake", "-C", workhorse_source, "install", "PREFIX=#{clone_path}"]).and_return(true)
run_rake_task('gitlab:workhorse:install', clone_path) run_rake_task('gitlab:workhorse:install', clone_path)
end end
...@@ -70,7 +65,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do ...@@ -70,7 +65,7 @@ RSpec.describe 'gitlab:workhorse namespace rake task' do
it 'calls make in the gitlab-workhorse directory' do it 'calls make in the gitlab-workhorse directory' do
expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['', 42]) expect(Gitlab::Popen).to receive(:popen).with(%w[which gmake]).and_return(['', 42])
expect(main_object).to receive(:run_command!).with(['make']).and_return(true) expect(main_object).to receive(:run_command!).with(["make", "-C", workhorse_source, "install", "PREFIX=#{clone_path}"]).and_return(true)
run_rake_task('gitlab:workhorse:install', clone_path) run_rake_task('gitlab:workhorse:install', clone_path)
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