Skip to content
Snippets Groups Projects
Commit e0fdbfd3 authored by Kamil Trzcińśki's avatar Kamil Trzcińśki
Browse files

Serve static pages

parent 39b7a993
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -104,6 +104,12 @@ module Ci
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?
Loading
Loading
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
Loading
Loading
@@ -186,6 +186,7 @@ Settings.gitlab_ci['add_pusher'] = false if Settings.gitlab_ci['add_pus
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
 
 
Loading
Loading
Loading
Loading
@@ -20,6 +20,7 @@ module Ci
@config = @config.deep_symbolize_keys
 
initial_parsing
inject_pages
 
validate!
end
Loading
Loading
@@ -38,6 +39,20 @@ module Ci
@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
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment