summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2015-07-08 14:12:34 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2015-07-08 14:12:34 +0000
commit00b6536f4d155ec41b8a8434d992b6b207f07bb5 (patch)
tree118927afe00dc27abe67420862d0035bced7f2c9
parent52cc9a572484a87cea542448e6d439b7c6032e04 (diff)
parentb34f96ec2a4a0d09d35f562aa18eb91071d95b2f (diff)
downloadgitlab-ci-00b6536f4d155ec41b8a8434d992b6b207f07bb5.tar.gz
Merge branch 'trace_in_file' into 'master'
Build trace in file https://dev.gitlab.org/gitlab/gitlab-ci/issues/272 See merge request !167
-rw-r--r--.gitignore1
-rw-r--r--CHANGELOG1
-rw-r--r--app/models/build.rb33
-rw-r--r--builds/.gitkeep1
-rw-r--r--doc/install/installation.md3
-rw-r--r--doc/raketasks/backup_restore.md4
-rw-r--r--doc/update/7.12-to-7.13.md51
-rw-r--r--lib/backup/builds.rb30
-rw-r--r--lib/backup/manager.rb4
-rw-r--r--lib/tasks/backup.rake9
-rw-r--r--spec/support/setup_builds_storage.rb12
11 files changed, 145 insertions, 4 deletions
diff --git a/.gitignore b/.gitignore
index 794c1ec..6c806ae 100644
--- a/.gitignore
+++ b/.gitignore
@@ -17,3 +17,4 @@ tmp/*
/db/*.sqlite3
/log/*.log
/.idea
+/builds/*
diff --git a/CHANGELOG b/CHANGELOG
index e64281d..76050f1 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -12,6 +12,7 @@ v7.13.0
v7.12.2
- Revert: Runner without tag should pick builds without tag only
+ - Build traces is stored in the file instead of database
v7.12.1
- Runner without tag should pick builds without tag only
diff --git a/app/models/build.rb b/app/models/build.rb
index 725da75..51c2bf6 100644
--- a/app/models/build.rb
+++ b/app/models/build.rb
@@ -210,4 +210,37 @@ class Build < ActiveRecord::Base
# so we just silentrly ignore error for now
end
end
+
+ def trace
+ if File.exist?(path_to_trace)
+ File.read(path_to_trace)
+ else
+ # backward compatibility
+ read_attribute :trace
+ end
+ end
+
+ def trace=(trace)
+ unless Dir.exists? dir_to_trace
+ FileUtils.mkdir_p dir_to_trace
+ end
+
+ File.write(path_to_trace, trace)
+ end
+
+ def dir_to_trace
+ Rails.root.join(
+ root_dir_to_trace,
+ created_at.utc.strftime("%Y_%m"),
+ project.id.to_s
+ )
+ end
+
+ def root_dir_to_trace
+ "builds"
+ end
+
+ def path_to_trace
+ "#{dir_to_trace}/#{id}.log"
+ end
end
diff --git a/builds/.gitkeep b/builds/.gitkeep
new file mode 100644
index 0000000..45adbb2
--- /dev/null
+++ b/builds/.gitkeep
@@ -0,0 +1 @@
+.gitkeep \ No newline at end of file
diff --git a/doc/install/installation.md b/doc/install/installation.md
index 4d85fb4..ba9c9ba 100644
--- a/doc/install/installation.md
+++ b/doc/install/installation.md
@@ -129,6 +129,9 @@ We recommend PostgreSQL but you can also use MySQL
sudo -u gitlab_ci -H mkdir -p tmp/pids/
sudo chmod -R u+rwX tmp/pids/
+ # Make sure GitLab CI can write to the builds/ directory
+ sudo chmod -R u+rwX builds
+
### Install gems
# For MySQL (note, the option says "without ... postgres")
diff --git a/doc/raketasks/backup_restore.md b/doc/raketasks/backup_restore.md
index 73ca73e..3da3f26 100644
--- a/doc/raketasks/backup_restore.md
+++ b/doc/raketasks/backup_restore.md
@@ -2,7 +2,7 @@
## Create a backup of the GitLab CI
-A backup creates an archive file that contains the database.
+A backup creates an archive file that contains the database and builds files.
This archive will be saved in backup_path (see `config/application.yml`).
The filename will be `[TIMESTAMP]_gitlab_ci_backup.tar.gz`. This timestamp can be used to restore an specific backup.
You can only restore a backup to exactly the same version of GitLab CI that you created it on, for example 7.10.1.
@@ -24,6 +24,8 @@ Example output:
Dumping database ...
Dumping PostgreSQL database gitlab_ci_development ... [DONE]
done
+Dumping builds ...
+done
Creating backup archive: 1430930060_gitlab_ci_backup.tar.gz ... done
Uploading backup archive to remote storage ... skipped
Deleting tmp directories ... done
diff --git a/doc/update/7.12-to-7.13.md b/doc/update/7.12-to-7.13.md
new file mode 100644
index 0000000..e3600eb
--- /dev/null
+++ b/doc/update/7.12-to-7.13.md
@@ -0,0 +1,51 @@
+# Update from 7.12 to 7.13
+
+## Notice
+
+__GitLab CI 7.13 requires GitLab 7.12 or higher and GitLab Multi Runner 0.4.0 or higher
+
+### 1. Stop CI server
+
+ sudo service gitlab_ci stop
+
+### 2. Switch to your gitlab_ci user
+
+```
+sudo su gitlab_ci
+cd /home/gitlab_ci/gitlab-ci
+```
+
+### 3. Get latest code
+
+```
+git fetch
+git checkout 7-13-stable
+```
+
+### 4. Make sure GitLab CI can write to the builds/ directory
+
+```
+sudo chmod -R u+rwX builds
+```
+
+### 5. Install libs, migrations etc
+
+
+```
+# Install nodejs dependency:
+sudo apt-get install nodejs
+
+# For MySQL users
+bundle install --without postgres development test --deployment
+
+# For Postgres users
+bundle install --without mysql development test --deployment
+
+# Run migrations
+bundle exec rake db:migrate RAILS_ENV=production
+```
+
+
+### 5. Start web application
+
+ sudo service gitlab_ci start
diff --git a/lib/backup/builds.rb b/lib/backup/builds.rb
new file mode 100644
index 0000000..71e9704
--- /dev/null
+++ b/lib/backup/builds.rb
@@ -0,0 +1,30 @@
+module Backup
+ class Builds
+ attr_reader :app_builds_dir, :backup_builds_dir, :backup_dir
+
+ def initialize
+ @app_builds_dir = File.realpath(Rails.root.join('builds'))
+ @backup_dir = GitlabCi.config.backup.path
+ @backup_builds_dir = File.join(GitlabCi.config.backup.path, 'builds')
+ end
+
+ # Copy builds from builds directory to backup/builds
+ def dump
+ FileUtils.mkdir_p(backup_builds_dir)
+ FileUtils.cp_r(app_builds_dir, backup_dir)
+ end
+
+ def restore
+ backup_existing_builds_dir
+
+ FileUtils.cp_r(backup_builds_dir, app_builds_dir)
+ end
+
+ def backup_existing_builds_dir
+ timestamped_builds_path = File.join(app_builds_dir, '..', "builds.#{Time.now.to_i}")
+ if File.exists?(app_builds_dir)
+ FileUtils.mv(app_builds_dir, File.expand_path(timestamped_builds_path))
+ end
+ end
+ end
+end
diff --git a/lib/backup/manager.rb b/lib/backup/manager.rb
index fc847e2..43fb362 100644
--- a/lib/backup/manager.rb
+++ b/lib/backup/manager.rb
@@ -15,7 +15,7 @@ module Backup
file << s.to_yaml.gsub(/^---\n/,'')
end
- FileUtils.chmod(0700, "db")
+ FileUtils.chmod(0700, ["db", "builds"])
# create archive
$progress.print "Creating backup archive: #{tar_file} ... "
@@ -146,7 +146,7 @@ module Backup
private
def backup_contents
- ["db", "backup_information.yml"]
+ ["db", "builds", "backup_information.yml"]
end
def settings
diff --git a/lib/tasks/backup.rake b/lib/tasks/backup.rake
index 3431bd1..df20c40 100644
--- a/lib/tasks/backup.rake
+++ b/lib/tasks/backup.rake
@@ -5,10 +5,13 @@ namespace :backup do
configure_cron_mode
$progress.puts "Dumping database ... ".blue
-
Backup::Database.new.dump
$progress.puts "done".green
+ $progress.puts "Dumping builds ... ".blue
+ Backup::Builds.new.dump
+ $progress.puts "done".green
+
backup = Backup::Manager.new
backup.pack
backup.cleanup
@@ -26,6 +29,10 @@ namespace :backup do
Backup::Database.new.restore
$progress.puts "done".green
+ $progress.puts "Restoring builds ... ".blue
+ Backup::Builds.new.restore
+ $progress.puts "done".green
+
backup.cleanup
end
diff --git a/spec/support/setup_builds_storage.rb b/spec/support/setup_builds_storage.rb
new file mode 100644
index 0000000..ab93471
--- /dev/null
+++ b/spec/support/setup_builds_storage.rb
@@ -0,0 +1,12 @@
+RSpec.configure do |config|
+ config.before(:each) do
+ FileUtils.mkdir_p("tmp/builds_test")
+ Build.any_instance.stub(:root_dir_to_trace).and_return("tmp/builds_test")
+ end
+
+ config.after(:suite) do
+ Dir.chdir(Rails.root.join("tmp/builds_test")) do
+ `ls | grep -v .gitkeep | xargs rm -r`
+ end
+ end
+end