Коммит e0fdbfd3 создал по автору Kamil Trzcinski's avatar Kamil Trzcinski
Просмотр файлов

Serve static pages

владелец 39b7a993
......@@ -104,6 +104,12 @@ def retry(build)
build.update_coverage
end
end
after_transition any => :success do |build, transition|
if build.name == 'pages' && build.artifact_file?
PagesUpdaterWorker.perform_async(build.id)
end
end
end
def ignored?
......
class PagesUpdaterWorker
include Sidekiq::Worker
sidekiq_options queue: :pages
def perform(build_id)
@build_id = build_id
return unless valid?
FileUtils.mkdir_p(tmp_path)
Dir.mktmpdir(nil, tmp_path) do |dir|
cmd = %W(tar -zxf #{build.artifact_file.path} -C #{dir})
return unless system(*cmd)
return unless valid?
public_dir = File.join(dir, 'public')
return unless File.exists?(public_dir)
FileUtils.mkdir_p(pages_path)
if File.exists?(pages_path)
FileUtils.move(pages_path, old_pages_path)
end
FileUtils.move(public_dir, pages_path)
FileUtils.rm_r(old_pages_path)
end
end
private
def valid?
# check if ref is still recent one
build && build.artifact_file? && build.sha == gl_project.commit.sha
end
def build
@build ||= Ci::Build.find(@build_id)
end
def gl_project
@gl_project ||= build.gl_project
end
def tmp_path
@tmp_path ||= File.join(Settings.gitlab_ci.pages_path, 'tmp')
end
def pages_path
@pages_path ||= File.join(Settings.gitlab_ci.pages_path, gl_project.path_with_namespace)
end
def old_pages_path
@old_pages_path ||= File.expand_path("#{pages_path}.#{SecureRandom.hex}")
end
end
......@@ -186,6 +186,7 @@ def base_gitlab_url
Settings.gitlab_ci['url'] ||= Settings.send(:build_gitlab_ci_url)
Settings.gitlab_ci['builds_path'] = File.expand_path(Settings.gitlab_ci['builds_path'] || "builds/", Rails.root)
Settings.gitlab_ci['artifacts_path'] = File.expand_path('shared/artifacts/', Rails.root)
Settings.gitlab_ci['pages_path'] = File.expand_path('shared/pages/', Rails.root)
Settings.gitlab_ci['max_artifact_size'] ||= 100
......
......@@ -20,6 +20,7 @@ def initialize(config, path = nil)
@config = @config.deep_symbolize_keys
initial_parsing
inject_pages
validate!
end
......@@ -38,6 +39,20 @@ def stages
@stages || DEFAULT_STAGES
end
def inject_pages
return unless stages.include?('deploy')
return if @jobs.include?('pages')
@jobs['pages'] = {
stage: 'deploy',
image: 'jekyll/jekyll:builder',
script: 'jekyll build --destination public',
artifacts: [
'public/',
]
}
end
private
def initial_parsing
......
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать