odania-static-pages 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +11 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +44 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/cf-templates/s3-http.yml +50 -0
- data/cf-templates/s3-logging.yml +21 -0
- data/cf-templates/s3-state.yml +21 -0
- data/exe/odania-static-pages +5 -0
- data/lib/odania_static_pages/cli/deploy_cli.rb +17 -0
- data/lib/odania_static_pages/cli/generator_cli.rb +17 -0
- data/lib/odania_static_pages/cli.rb +30 -0
- data/lib/odania_static_pages/config/docker_compose.rb +24 -0
- data/lib/odania_static_pages/config/generator/jekyll.rb +126 -0
- data/lib/odania_static_pages/config/rsync.rb +24 -0
- data/lib/odania_static_pages/config/s3.rb +41 -0
- data/lib/odania_static_pages/config.rb +127 -0
- data/lib/odania_static_pages/deploy/docker_compose.rb +148 -0
- data/lib/odania_static_pages/deploy/rsync.rb +73 -0
- data/lib/odania_static_pages/deploy/s3.rb +165 -0
- data/lib/odania_static_pages/generator/jekyll.rb +112 -0
- data/lib/odania_static_pages/server/nginx.rb +7 -0
- data/lib/odania_static_pages/version.rb +3 -0
- data/lib/odania_static_pages.rb +28 -0
- data/odania-static-pages.gemspec +33 -0
- data/odania-static-pages.iml +15 -0
- data/templates/docker-compose/docker-compose.yml.erb +68 -0
- data/templates/jekyll/Gemfile.erb +44 -0
- data/templates/jekyll/example_config.yml +19 -0
- data/templates/nginx/default-live-vhost.conf +13 -0
- data/templates/nginx/default-vhost.conf +21 -0
- data/templates/nginx/index.html.erb +14 -0
- data/templates/nginx/nginx.conf +41 -0
- data/templates/nginx/vhost-redirects.conf.erb +14 -0
- data/templates/nginx/vhost.conf.erb +22 -0
- metadata +196 -0
@@ -0,0 +1,127 @@
|
|
1
|
+
require_relative 'config/docker_compose'
|
2
|
+
require_relative 'config/generator/jekyll'
|
3
|
+
require_relative 'config/rsync'
|
4
|
+
require_relative 'config/s3'
|
5
|
+
|
6
|
+
module OdaniaStaticPages
|
7
|
+
class Config
|
8
|
+
attr_accessor :environment
|
9
|
+
attr_reader :project_dir, :base_dir, :output_sites_path, :output_nginx_path, :environments,
|
10
|
+
:generator_type, :generator
|
11
|
+
|
12
|
+
def initialize(path=nil)
|
13
|
+
@base_dir = File.absolute_path(File.join(File.dirname(__FILE__), '..', '..'))
|
14
|
+
@project_dir = path.nil? ? Dir.getwd : path
|
15
|
+
@output_sites_path = 'sites'
|
16
|
+
@output_nginx_path = 'nginx'
|
17
|
+
@generator_type = 'Jekyll'
|
18
|
+
@environments = {
|
19
|
+
develop: Environment.new('_develop', 'DockerCompose'),
|
20
|
+
live: Environment.new('_live', 'Rsync')
|
21
|
+
}
|
22
|
+
@generator = Generator::Jekyll.new(@project_dir, {})
|
23
|
+
end
|
24
|
+
|
25
|
+
def load!
|
26
|
+
if File.exist? config_file
|
27
|
+
config = YAML.load_file(config_file).stringify_keys!
|
28
|
+
@output_sites_path = config['output_sites_path'] unless config['output_sites_path'].nil?
|
29
|
+
@output_nginx_path = config['output_nginx_path'] unless config['output_nginx_path'].nil?
|
30
|
+
@generator_type = config['generator_type'] unless config['generator_type'].nil?
|
31
|
+
|
32
|
+
unless config['environments'].nil?
|
33
|
+
@environments = {}
|
34
|
+
config['environments'].each_pair do |name, data|
|
35
|
+
@environments[name] = Environment.from_hash data
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
@deploy = Deploy.from_hash(config['deploy']) unless config['deploy'].nil?
|
40
|
+
|
41
|
+
unless config['generator'].nil?
|
42
|
+
generator_config_module = "OdaniaStaticPages::Config::Generator::#{@generator_type}".constantize
|
43
|
+
@generator = generator_config_module.from_hash @project_dir, config['generator']
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
self
|
48
|
+
end
|
49
|
+
|
50
|
+
def config_file
|
51
|
+
File.join(@project_dir, '_config.yml')
|
52
|
+
end
|
53
|
+
|
54
|
+
def output_site_path
|
55
|
+
File.join @project_dir, current_environment.output_path, @output_sites_path
|
56
|
+
end
|
57
|
+
|
58
|
+
def output_path
|
59
|
+
File.join @project_dir, current_environment.output_path
|
60
|
+
end
|
61
|
+
|
62
|
+
def pages_path
|
63
|
+
File.join @project_dir, 'pages'
|
64
|
+
end
|
65
|
+
|
66
|
+
def current_environment
|
67
|
+
@environments[@environment]
|
68
|
+
end
|
69
|
+
|
70
|
+
def save!
|
71
|
+
puts "Writing config file #{config_file}"
|
72
|
+
File.write config_file, YAML.dump(to_h)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def to_h
|
78
|
+
environment_hash = {}
|
79
|
+
@environments.each_pair do |name, environment|
|
80
|
+
environment_hash[name.to_s] = environment.to_h
|
81
|
+
end
|
82
|
+
|
83
|
+
config = {
|
84
|
+
output_sites_path: @output_sites_path,
|
85
|
+
output_nginx_path: @output_nginx_path,
|
86
|
+
generator_type: @generator_type,
|
87
|
+
generator: @generator.to_h,
|
88
|
+
environments: environment_hash
|
89
|
+
}
|
90
|
+
|
91
|
+
config.stringify_keys!
|
92
|
+
end
|
93
|
+
|
94
|
+
class Environment
|
95
|
+
attr_reader :output_path, :deploy_type, :deploy_module, :notify
|
96
|
+
|
97
|
+
def initialize(output_path, deploy_type, deploy_module_config={}, notify='echo Switched from OLD-COLOR to NEW-COLOR!')
|
98
|
+
@output_path = output_path
|
99
|
+
@deploy_type = deploy_type
|
100
|
+
@notify = notify
|
101
|
+
clazz_name = "OdaniaStaticPages::Config::Deploy::#{deploy_type}"
|
102
|
+
@deploy_module = clazz_name.constantize.new deploy_module_config.symbolize_keys!
|
103
|
+
end
|
104
|
+
|
105
|
+
def to_h
|
106
|
+
{
|
107
|
+
output_path: @output_path,
|
108
|
+
deploy_type: @deploy_type,
|
109
|
+
notify: @notify,
|
110
|
+
deploy_config: @deploy_module.to_h
|
111
|
+
}.stringify_keys!
|
112
|
+
end
|
113
|
+
|
114
|
+
def self.from_hash(data)
|
115
|
+
Environment.new data['output_path'], data['deploy_type'], data['deploy_config'], data['notify']
|
116
|
+
end
|
117
|
+
|
118
|
+
def do_notify(new_color, old_color)
|
119
|
+
unless @notify.nil?
|
120
|
+
replaced_notify = @notify.gsub('NEW-COLOR', new_color).gsub('OLD-COLOR', old_color)
|
121
|
+
puts "Ececuting notify: #{replaced_notify}"
|
122
|
+
puts `#{replaced_notify}`
|
123
|
+
end
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
@@ -0,0 +1,148 @@
|
|
1
|
+
module OdaniaStaticPages
|
2
|
+
module Deploy
|
3
|
+
class DockerCompose
|
4
|
+
def initialize
|
5
|
+
@config = OdaniaStaticPages.config
|
6
|
+
@environment = @config.current_environment
|
7
|
+
@deploy_config = @environment.deploy_module
|
8
|
+
@generator_config = @config.generator
|
9
|
+
@nginx_dir = File.join(@config.output_path, 'nginx')
|
10
|
+
@nginx_conf_dir = File.join(@nginx_dir, 'conf.d')
|
11
|
+
end
|
12
|
+
|
13
|
+
def prepare
|
14
|
+
puts 'Preparing docker-compose state'
|
15
|
+
load_state
|
16
|
+
state_path = File.dirname(@deploy_config.state_file)
|
17
|
+
FileUtils.mkdir_p state_path unless File.exist? state_path
|
18
|
+
save_state
|
19
|
+
end
|
20
|
+
|
21
|
+
def publish(color, do_rebuild)
|
22
|
+
puts 'docker-compose'
|
23
|
+
load_state
|
24
|
+
color = color.nil? ? @state[:color] : color
|
25
|
+
new_color = 'green'.eql?(color) ? 'blue' : 'green'
|
26
|
+
puts " -> Current color: #{color}"
|
27
|
+
@site_path = @config.output_site_path
|
28
|
+
puts " -> Deploying to color: #{new_color} [Path: #{@site_path}]"
|
29
|
+
|
30
|
+
generate_compose_config
|
31
|
+
generate_nginx_config(do_rebuild)
|
32
|
+
prepare_varnish
|
33
|
+
|
34
|
+
@config.current_environment.do_notify new_color, color
|
35
|
+
puts
|
36
|
+
puts "Finished deploying color #{new_color}"
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
def load_state
|
42
|
+
@state = {color: 'blue'}
|
43
|
+
@state = YAML.load_file(@deploy_config.state_file).symbolize_keys! if File.exist? @deploy_config.state_file
|
44
|
+
|
45
|
+
@state
|
46
|
+
end
|
47
|
+
|
48
|
+
def save_state
|
49
|
+
File.write @deploy_config.state_file, YAML.dump(@state)
|
50
|
+
end
|
51
|
+
|
52
|
+
def generate_compose_config
|
53
|
+
puts 'Generating docker-compose.yml'
|
54
|
+
environment = @config.current_environment
|
55
|
+
compose_file = File.join(@config.project_dir, environment.output_path, 'docker-compose.yml')
|
56
|
+
|
57
|
+
puts "Writing docker compose to #{compose_file}"
|
58
|
+
docker_compose_generator = DockerComposeGenerator.new @config, environment
|
59
|
+
docker_compose_generator.write compose_file
|
60
|
+
end
|
61
|
+
|
62
|
+
def generate_nginx_config(do_rebuild)
|
63
|
+
vhost_renderer = ERB.new(File.read(File.join(@config.base_dir, 'templates', 'nginx', 'vhost.conf.erb')))
|
64
|
+
sites = {}
|
65
|
+
grouped_domains.each_pair do |site_name, page_config|
|
66
|
+
full_site_name = "#{site_name}.lvh.me"
|
67
|
+
puts "Writing vhost for: #{full_site_name}"
|
68
|
+
expires = @deploy_config.expires
|
69
|
+
File.write File.join(@nginx_conf_dir, "#{site_name}.conf"), vhost_renderer.result(binding)
|
70
|
+
|
71
|
+
sites[site_name] = "#{site_name}.lvh.me:8080"
|
72
|
+
|
73
|
+
page_config.each do |config|
|
74
|
+
sites["#{site_name}#{config[:baseurl]}"] = "#{site_name}.lvh.me:8080#{config[:baseurl]}"
|
75
|
+
end if page_config.count > 1
|
76
|
+
end
|
77
|
+
|
78
|
+
puts 'Generating index.html'
|
79
|
+
renderer = ERB.new(File.read(File.join(@config.base_dir, 'templates', 'nginx', 'index.html.erb')))
|
80
|
+
File.write File.join(@config.output_site_path, 'index.html'), renderer.result(binding)
|
81
|
+
|
82
|
+
puts 'Copy default vhost'
|
83
|
+
FileUtils.cp File.join(@config.base_dir, 'templates', 'nginx', 'default-vhost.conf'), File.join(@nginx_conf_dir, 'default.conf')
|
84
|
+
end
|
85
|
+
|
86
|
+
def prepare_varnish
|
87
|
+
docker_folder = File.join(@config.project_dir, 'docker')
|
88
|
+
FileUtils.mkdir_p docker_folder
|
89
|
+
puts "Checkout repositories in #{docker_folder}"
|
90
|
+
|
91
|
+
if File.exist? "#{docker_folder}/varnish"
|
92
|
+
cmd = "cd #{docker_folder}/varnish && git pull"
|
93
|
+
else
|
94
|
+
cmd = "git clone -q -b develop https://github.com/Odania-IT/odania-varnish.git #{docker_folder}/varnish"
|
95
|
+
end
|
96
|
+
puts " -> Executing #{cmd}"
|
97
|
+
puts `#{cmd}`
|
98
|
+
exit 1 unless $?.success?
|
99
|
+
|
100
|
+
if File.exist? "#{docker_folder}/varnish-generator"
|
101
|
+
cmd = "cd #{docker_folder}/varnish-generator && git pull"
|
102
|
+
else
|
103
|
+
cmd = "git clone -q https://github.com/Odania-IT/odania-varnish-generator.git #{docker_folder}/varnish-generator"
|
104
|
+
end
|
105
|
+
puts " -> Executing #{cmd}"
|
106
|
+
puts `#{cmd}`
|
107
|
+
exit 1 unless $?.success?
|
108
|
+
|
109
|
+
puts 'Prepare varnish secret'
|
110
|
+
File.write File.join(docker_folder, 'varnish', 'varnish-secret'), @deploy_config.varnish_secret
|
111
|
+
File.write File.join(docker_folder, 'varnish-generator', 'varnish-secret'), @deploy_config.varnish_secret
|
112
|
+
end
|
113
|
+
|
114
|
+
def grouped_domains
|
115
|
+
result = Hash.new { |k, v| k[v] = [] }
|
116
|
+
|
117
|
+
@generator_config.jekyll_config['pages'].each do |page|
|
118
|
+
uri = URI.parse(page['url'])
|
119
|
+
host = uri.host
|
120
|
+
result[host] << {baseurl: page['baseurl'], relative_path: @generator_config.page_path(page)}
|
121
|
+
end
|
122
|
+
|
123
|
+
puts result.inspect
|
124
|
+
result
|
125
|
+
end
|
126
|
+
|
127
|
+
class DockerComposeGenerator
|
128
|
+
attr_reader :nginx_volume_html, :nginx_volume_conf_d, :nginx_volume_nginx_conf, :compose_images
|
129
|
+
|
130
|
+
def initialize(config, environment)
|
131
|
+
@nginx_volume_html = "#{config.output_site_path}:/srv:ro"
|
132
|
+
@nginx_volume_conf_d = "#{@nginx_conf_dir}:/etc/nginx/conf.d:ro"
|
133
|
+
@nginx_volume_nginx_conf = "#{File.join(config.output_path, 'nginx', 'nginx.conf')}:/etc/nginx/nginx.conf"
|
134
|
+
@compose_images = environment.deploy_module.compose_images
|
135
|
+
@erb_template = File.join(config.base_dir, 'templates', 'docker-compose', 'docker-compose.yml.erb')
|
136
|
+
end
|
137
|
+
|
138
|
+
def render
|
139
|
+
ERB.new(File.read(@erb_template)).result(binding)
|
140
|
+
end
|
141
|
+
|
142
|
+
def write(out_dir)
|
143
|
+
File.write out_dir, render
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module OdaniaStaticPages
|
2
|
+
module Deploy
|
3
|
+
class Rsync
|
4
|
+
def initialize
|
5
|
+
@config = OdaniaStaticPages.config
|
6
|
+
@deploy_config = @config.current_environment.deploy_module
|
7
|
+
@local_state = '_local_state.yml'
|
8
|
+
end
|
9
|
+
|
10
|
+
def prepare
|
11
|
+
puts 'Preparing rsync state'
|
12
|
+
load_state
|
13
|
+
save_state
|
14
|
+
end
|
15
|
+
|
16
|
+
def publish(color, do_rebuild)
|
17
|
+
puts 'Rsync website'
|
18
|
+
load_state
|
19
|
+
color = color.nil? ? @state[:color] : color
|
20
|
+
new_color = 'green'.eql?(color) ? 'blue' : 'green'
|
21
|
+
puts " -> Current color: #{color}"
|
22
|
+
@site_path = @config.output_site_path
|
23
|
+
puts " -> Deploying to color: #{new_color} [Path: #{@site_path}]"
|
24
|
+
|
25
|
+
@deploy_config.targets[new_color].each do |target|
|
26
|
+
puts
|
27
|
+
puts
|
28
|
+
puts "Syncing target #{target} " + '-' * 50
|
29
|
+
|
30
|
+
cmd = "cd #{@site_path} && rsync #{@deploy_config.rsync_options} . #{target}"
|
31
|
+
puts "Executing: #{cmd}"
|
32
|
+
puts `#{cmd}`.split("\n").join("\n ")
|
33
|
+
|
34
|
+
unless $?.success?
|
35
|
+
puts 'Error during rsync!!'
|
36
|
+
exit 1
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
@state[:color] = new_color
|
41
|
+
save_state
|
42
|
+
|
43
|
+
@config.current_environment.do_notify new_color, color
|
44
|
+
puts
|
45
|
+
puts "Finished deploying color #{new_color}"
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def load_state
|
51
|
+
@state = {color: 'blue'}
|
52
|
+
cmd = "rsync #{@deploy_config.state_file} #{@local_state}"
|
53
|
+
puts "Syncing state: #{cmd}"
|
54
|
+
puts `#{cmd}`
|
55
|
+
|
56
|
+
@state = YAML.load_file(@local_state).symbolize_keys! if $?.success?
|
57
|
+
@state
|
58
|
+
end
|
59
|
+
|
60
|
+
def save_state
|
61
|
+
File.write @local_state, YAML.dump(@state)
|
62
|
+
cmd = "rsync #{@local_state} #{@deploy_config.state_file}"
|
63
|
+
puts "Syncing state: #{cmd}"
|
64
|
+
puts `#{cmd}`
|
65
|
+
|
66
|
+
unless $?.success?
|
67
|
+
puts 'Error saving state!!'
|
68
|
+
exit 1
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,165 @@
|
|
1
|
+
module OdaniaStaticPages
|
2
|
+
module Deploy
|
3
|
+
class S3
|
4
|
+
def initialize
|
5
|
+
@config = OdaniaStaticPages.config
|
6
|
+
@s3_config = @config.current_environment.deploy_module
|
7
|
+
params = {
|
8
|
+
region: @s3_config.region
|
9
|
+
}
|
10
|
+
params[:profile] = @s3_config.profile unless @s3_config.profile.nil?
|
11
|
+
|
12
|
+
puts "Configuring AWS with params: #{params}"
|
13
|
+
Aws.config.update(params)
|
14
|
+
end
|
15
|
+
|
16
|
+
def prepare
|
17
|
+
tags = @s3_config.tags
|
18
|
+
logging_stack_name = 'odania-logging'
|
19
|
+
params = {
|
20
|
+
BucketName: @s3_config.logging_bucket
|
21
|
+
}
|
22
|
+
Stacker.create_or_update_stack(logging_stack_name, File.join(@config.base_dir, 'cf-templates', 's3-logging.yml'), params, nil, nil, tags)
|
23
|
+
|
24
|
+
params = {
|
25
|
+
BucketName: @s3_config.state_bucket
|
26
|
+
}
|
27
|
+
Stacker.create_or_update_stack('odania-state', File.join(@config.base_dir, 'cf-templates', 's3-state.yml'), params, nil, nil, tags)
|
28
|
+
|
29
|
+
params = {
|
30
|
+
BucketNameGreen: @s3_config.bucket_name_green,
|
31
|
+
BucketNameBlue: @s3_config.bucket_name_blue,
|
32
|
+
LoggingStackName: logging_stack_name
|
33
|
+
}
|
34
|
+
Stacker.create_or_update_stack('odania-static-http', File.join(@config.base_dir, 'cf-templates', 's3-http.yml'), params, logging_stack_name, nil, tags)
|
35
|
+
end
|
36
|
+
|
37
|
+
def publish(color)
|
38
|
+
puts 'Publishing website to s3'
|
39
|
+
load_state
|
40
|
+
color = color.nil? ? @state[:color] : color
|
41
|
+
new_color = 'green'.eql?(color) ? 'blue' : 'green'
|
42
|
+
puts " -> Current color: #{color}"
|
43
|
+
@site_path = @config.output_site_path
|
44
|
+
puts " -> Deploying to color: #{new_color} [Path: #{@site_path}]"
|
45
|
+
|
46
|
+
@uploaded_files = []
|
47
|
+
bucket_name = 'green'.eql?(new_color) ? @s3_config.bucket_name_green : @s3_config.bucket_name_blue
|
48
|
+
recursive_file_upload bucket_name, @site_path
|
49
|
+
delete_not_uploaded_files bucket_name
|
50
|
+
|
51
|
+
@state[:color] = new_color
|
52
|
+
save_state
|
53
|
+
|
54
|
+
url = bucket_url bucket_name
|
55
|
+
|
56
|
+
@config.current_environment.do_notify new_color, color
|
57
|
+
puts
|
58
|
+
puts "Finished deploying color #{new_color} to bucket #{bucket_name}"
|
59
|
+
puts "Public url: #{url}"
|
60
|
+
end
|
61
|
+
|
62
|
+
private
|
63
|
+
|
64
|
+
def client
|
65
|
+
@s3_client = Aws::S3::Client.new if @s3_client.nil?
|
66
|
+
@s3_client
|
67
|
+
end
|
68
|
+
|
69
|
+
def bucket_url(bucket_name)
|
70
|
+
bucket = Aws::S3::Bucket.new bucket_name
|
71
|
+
bucket.url
|
72
|
+
end
|
73
|
+
|
74
|
+
def s3_exists?(bucket, key)
|
75
|
+
result = client.list_objects({bucket: bucket, prefix: key})
|
76
|
+
|
77
|
+
result.contents.each do |content|
|
78
|
+
return true if key.eql? content.key
|
79
|
+
end
|
80
|
+
|
81
|
+
false
|
82
|
+
end
|
83
|
+
|
84
|
+
def s3_files_in_bucket(bucket)
|
85
|
+
is_truncated = true
|
86
|
+
next_marker = nil
|
87
|
+
result = []
|
88
|
+
|
89
|
+
while is_truncated
|
90
|
+
params = {bucket: bucket}
|
91
|
+
params[:next_marker] = next_marker unless next_marker.nil?
|
92
|
+
response = client.list_objects(params)
|
93
|
+
|
94
|
+
response.contents.each do |content|
|
95
|
+
result << content.key
|
96
|
+
end
|
97
|
+
|
98
|
+
next_marker = response.next_marker
|
99
|
+
is_truncated = response.is_truncated
|
100
|
+
end
|
101
|
+
|
102
|
+
result
|
103
|
+
end
|
104
|
+
|
105
|
+
def recursive_file_upload(bucket, path)
|
106
|
+
Dir.glob(File.join(path, '**')).each do |file|
|
107
|
+
if File.directory? file
|
108
|
+
recursive_file_upload bucket, file
|
109
|
+
else
|
110
|
+
target_file = file.gsub("#{@site_path}/", '')
|
111
|
+
content_type = MimeMagic.by_extension File.extname file
|
112
|
+
@uploaded_files << target_file
|
113
|
+
puts " *> #{file} => #{target_file} [Content-Type: #{content_type}]"
|
114
|
+
|
115
|
+
File.open(file, 'rb') do |opened_file|
|
116
|
+
client.put_object({
|
117
|
+
acl: 'public-read',
|
118
|
+
bucket: bucket,
|
119
|
+
key: target_file,
|
120
|
+
body: opened_file,
|
121
|
+
content_type: content_type.to_s,
|
122
|
+
server_side_encryption: 'AES256'
|
123
|
+
})
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
127
|
+
end
|
128
|
+
|
129
|
+
def delete_not_uploaded_files(bucket)
|
130
|
+
s3_files = s3_files_in_bucket bucket
|
131
|
+
|
132
|
+
new_files = @uploaded_files - s3_files
|
133
|
+
files_to_delete = s3_files - @uploaded_files
|
134
|
+
|
135
|
+
puts '*'*100
|
136
|
+
puts @uploaded_files
|
137
|
+
puts '*'*100
|
138
|
+
puts s3_files
|
139
|
+
puts '*'*100
|
140
|
+
puts "New Files: #{new_files}"
|
141
|
+
puts '*'*100
|
142
|
+
puts "Files to delete: #{files_to_delete}"
|
143
|
+
end
|
144
|
+
|
145
|
+
def load_state
|
146
|
+
@state = {color: 'blue'}
|
147
|
+
if s3_exists?(@s3_config.state_bucket, 'state.yml')
|
148
|
+
response = client.get_object({bucket: @s3_config.state_bucket, key: 'state.yml'})
|
149
|
+
@state = YAML.load response.body.read
|
150
|
+
end
|
151
|
+
|
152
|
+
@state
|
153
|
+
end
|
154
|
+
|
155
|
+
def save_state
|
156
|
+
client.put_object({
|
157
|
+
bucket: @s3_config.state_bucket,
|
158
|
+
key: 'state.yml',
|
159
|
+
body: YAML.dump(@state),
|
160
|
+
server_side_encryption: 'AES256'
|
161
|
+
})
|
162
|
+
end
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module OdaniaStaticPages
|
2
|
+
module Generator
|
3
|
+
class Jekyll
|
4
|
+
def init
|
5
|
+
puts 'Initliazing jekyll pages'
|
6
|
+
puts
|
7
|
+
setup_generator
|
8
|
+
|
9
|
+
FileUtils.mkdir_p @pages_path unless File.exist? @pages_path
|
10
|
+
|
11
|
+
unless File.exist? @jekyll_config_file
|
12
|
+
FileUtils.cp File.join(@config.base_dir, 'templates', 'jekyll', 'example_config.yml'), @jekyll_config_file
|
13
|
+
setup_generator
|
14
|
+
end
|
15
|
+
|
16
|
+
FileUtils.mkdir_p @generator_config.full_common_folder unless File.exist? @generator_config.full_common_folder
|
17
|
+
|
18
|
+
puts 'Initialize Gemfile'
|
19
|
+
gemfile_template = File.join(@config.base_dir, 'templates', 'jekyll', 'Gemfile.erb')
|
20
|
+
gem_extra = @generator_config.gem_extra
|
21
|
+
File.write File.join(@generator_config.full_common_folder, 'Gemfile'), ERB.new(File.read(gemfile_template)).result(binding)
|
22
|
+
|
23
|
+
puts 'Install gems'
|
24
|
+
puts `cd #{@generator_config.full_common_folder} && bundle check`
|
25
|
+
puts `cd #{@generator_config.full_common_folder} && bundle install --path ~/.gems` unless $?.success?
|
26
|
+
|
27
|
+
@jekyll_config['pages'].each do |page|
|
28
|
+
relative_page_path = @generator_config.page_path page
|
29
|
+
relative_page_path += page['baseurl'] unless page['baseurl'].empty?
|
30
|
+
page_path = File.join @pages_path, relative_page_path
|
31
|
+
|
32
|
+
puts '*' * 100
|
33
|
+
puts "Processing #{relative_page_path} => #{page_path}"
|
34
|
+
|
35
|
+
unless File.directory? page_path
|
36
|
+
puts "Creating page #{page['name']}"
|
37
|
+
`cd #{@pages_path} && octopress new #{relative_page_path}`
|
38
|
+
end
|
39
|
+
|
40
|
+
page_config = @generator_config.prepare_config page
|
41
|
+
current_config_file = File.join page_path, '_config.yml'
|
42
|
+
current_config = YAML.load_file current_config_file
|
43
|
+
|
44
|
+
unless current_config.eql? page_config
|
45
|
+
puts ' -> Updating config'
|
46
|
+
File.write current_config_file, YAML.dump(page_config)
|
47
|
+
end
|
48
|
+
|
49
|
+
@generator_config.link @config.base_dir, page_path, page
|
50
|
+
|
51
|
+
puts
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
|
56
|
+
def build(env)
|
57
|
+
puts 'Building all jekyll websites'
|
58
|
+
setup_generator
|
59
|
+
|
60
|
+
grouped_domains.each_pair do |site_name, page_config|
|
61
|
+
build_for_configs(page_config, site_name, @config.output_site_path, env)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
private
|
66
|
+
|
67
|
+
def setup_generator
|
68
|
+
@config = OdaniaStaticPages.config
|
69
|
+
@current_environment = @config.current_environment
|
70
|
+
@generator_config = @config.generator
|
71
|
+
@pages_path = @config.pages_path
|
72
|
+
@jekyll_config_file = @generator_config.jekyll_config_file
|
73
|
+
@jekyll_config = @generator_config.jekyll_config
|
74
|
+
end
|
75
|
+
|
76
|
+
def grouped_domains
|
77
|
+
result = Hash.new { |k, v| k[v] = [] }
|
78
|
+
|
79
|
+
@generator_config.jekyll_config['pages'].each do |page|
|
80
|
+
uri = URI.parse(page['url'])
|
81
|
+
host = uri.host
|
82
|
+
result[host] << {baseurl: page['baseurl'], relative_path: @generator_config.page_path(page)}
|
83
|
+
end
|
84
|
+
|
85
|
+
puts result.inspect
|
86
|
+
result
|
87
|
+
end
|
88
|
+
|
89
|
+
def build_site(site_path, options, jekyll_env='development')
|
90
|
+
puts 'Install gems'
|
91
|
+
puts `cd #{File.join(@generator_config.pages_dir, site_path)} && bundle check`
|
92
|
+
puts `cd #{File.join(@generator_config.pages_dir, site_path)} && bundle install --path ~/.gems` unless $?.success?
|
93
|
+
|
94
|
+
cmd = "cd #{ File.join(@generator_config.pages_dir, site_path) } && JEKYLL_ENV=#{jekyll_env} bundle exec jekyll build #{options}"
|
95
|
+
puts " -> Building site [cmd: #{cmd}]"
|
96
|
+
unless system(cmd)
|
97
|
+
puts "Error building site: #{site_path}"
|
98
|
+
exit 1
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def build_for_configs(page_config, site_name, target_site_path, jekyll_env='development')
|
103
|
+
page_config.each do |config|
|
104
|
+
site_path = site_name
|
105
|
+
site_path = File.join(site_path, config[:baseurl]) unless config[:baseurl].nil?
|
106
|
+
options = "-d #{File.join(target_site_path, site_path)}"
|
107
|
+
build_site site_path, options, jekyll_env
|
108
|
+
end
|
109
|
+
end
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'active_support/all'
|
2
|
+
require 'autostacker24'
|
3
|
+
require 'aws-sdk'
|
4
|
+
require 'erb'
|
5
|
+
require 'mimemagic'
|
6
|
+
require 'thor'
|
7
|
+
require 'uri'
|
8
|
+
require 'yaml'
|
9
|
+
|
10
|
+
require_relative 'odania_static_pages/cli'
|
11
|
+
require_relative 'odania_static_pages/config'
|
12
|
+
require_relative 'odania_static_pages/deploy/docker_compose'
|
13
|
+
require_relative 'odania_static_pages/deploy/rsync'
|
14
|
+
require_relative 'odania_static_pages/deploy/s3'
|
15
|
+
require_relative 'odania_static_pages/generator/jekyll'
|
16
|
+
require_relative 'odania_static_pages/server/nginx'
|
17
|
+
require_relative 'odania_static_pages/version'
|
18
|
+
|
19
|
+
module OdaniaStaticPages
|
20
|
+
def self.config(path=nil)
|
21
|
+
if @config.nil? or !path.nil?
|
22
|
+
@config = OdaniaStaticPages::Config.new(path)
|
23
|
+
@config.load!
|
24
|
+
end
|
25
|
+
|
26
|
+
@config
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require_relative 'lib/odania_static_pages/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'odania-static-pages'
|
8
|
+
spec.version = OdaniaStaticPages::VERSION
|
9
|
+
spec.authors = ['Mike Petersen']
|
10
|
+
spec.email = ['mike@odania-it.de']
|
11
|
+
|
12
|
+
spec.summary = %q{Helper For creating static pages}
|
13
|
+
spec.description = %q{Helper for creating static pages}
|
14
|
+
spec.homepage = 'http://www.odania.com'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
19
|
+
end
|
20
|
+
spec.bindir = 'exe'
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) {|f| File.basename(f)}
|
22
|
+
spec.require_paths = ['lib']
|
23
|
+
|
24
|
+
spec.add_runtime_dependency 'activesupport'
|
25
|
+
spec.add_runtime_dependency 'autostacker24', '>= 2.8.0'
|
26
|
+
spec.add_runtime_dependency 'aws-sdk', '>= 3'
|
27
|
+
spec.add_runtime_dependency 'mimemagic'
|
28
|
+
spec.add_runtime_dependency 'thor'
|
29
|
+
|
30
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
31
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
32
|
+
spec.add_development_dependency 'minitest', '~> 5.0'
|
33
|
+
end
|