Skip to content

Commit

Permalink
sotm: Switch to using containers for jekyll sites
Browse files Browse the repository at this point in the history
  • Loading branch information
Firefishy committed Feb 12, 2023
1 parent e77985f commit a55ea01
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 67 deletions.
2 changes: 1 addition & 1 deletion cookbooks/stateofthemap/metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@
supports "ubuntu"
depends "apache"
depends "git"
depends "ruby"
depends "podman"
depends "wordpress"
65 changes: 9 additions & 56 deletions cookbooks/stateofthemap/recipes/jekyll.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,64 +17,18 @@
# limitations under the License.
#

include_recipe "stateofthemap"
include_recipe "ruby"
include_recipe "apache"
include_recipe "podman"

package %w[
gcc
g++
make
libssl-dev
zlib1g-dev
pkg-config
]

apache_module "expires"
apache_module "rewrite"
apache_module "proxy_http"

%w[2016 2017 2018 2019 2020 2021 2022].each do |year|
git "/srv/#{year}.stateofthemap.org" do
action :sync
repository "https://github.com/openstreetmap/stateofthemap-#{year}.git"
depth 1
user "root"
group "root"
notifies :run, "bundle_install[/srv/#{year}.stateofthemap.org]"
end

directory "/srv/#{year}.stateofthemap.org/_site" do
mode "755"
owner "nobody"
group "nogroup"
end

directory "/srv/#{year}.stateofthemap.org/vendor" do
mode "755"
owner "nobody"
group "nogroup"
end

bundle_install "/srv/#{year}.stateofthemap.org" do
action :nothing
user "nobody"
group "nogroup"
environment "BUNDLE_FROZEN" => "true",
"BUNDLE_WITHOUT" => "development:test",
"BUNDLE_PATH" => "vendor/bundle",
"BUNDLE_DEPLOYMENT" => "1",
"BUNDLE_JOBS" => node.cpu_cores.to_s
notifies :run, "bundle_exec[/srv/#{year}.stateofthemap.org]"
only_if { ::File.exist?("/srv/#{year}.stateofthemap.org/Gemfile") }
end
docker_external_port = 6080 + year.to_i # 8096+

bundle_exec "/srv/#{year}.stateofthemap.org" do
action :nothing
command "jekyll build --trace --disable-disk-cache --baseurl=https://#{year}.stateofthemap.org"
user "nobody"
group "nogroup"
environment "LANG" => "C.UTF-8",
"BUNDLE_PATH" => "vendor/bundle",
"BUNDLE_DEPLOYMENT" => "1"
podman_service "#{year}.stateofthemap.org" do
description "Container service for #{year}.stateofthemap.org"
image "ghcr.io/openstreetmap/stateofthemap-#{year}:latest"
ports docker_external_port => "8080"
end

ssl_certificate "#{year}.stateofthemap.org" do
Expand All @@ -84,7 +38,6 @@

apache_site "#{year}.stateofthemap.org" do
template "apache.jekyll.erb"
directory "/srv/#{year}.stateofthemap.org/_site"
variables :year => year
variables :year => year, :docker_external_port => docker_external_port, :aliases => ["#{year}.sotm.org"]
end
end
17 changes: 7 additions & 10 deletions cookbooks/stateofthemap/templates/default/apache.jekyll.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@

<VirtualHost *:443>
ServerName <%= @year %>.stateofthemap.com
ServerAlias <%= @year %>.sotm.org
<% @aliases.each do |alias_name| -%>
ServerAlias <%= alias_name %>
<% end -%>
ServerAdmin [email protected]

CustomLog /var/log/apache2/<%= @year %>.stateofthemap.org-access.log combined
Expand All @@ -38,14 +40,9 @@
SSLCertificateFile /etc/ssl/certs/<%= @year %>.stateofthemap.org.pem
SSLCertificateKeyFile /etc/ssl/private/<%= @year %>.stateofthemap.org.key

DocumentRoot /srv/<%= @year %>.stateofthemap.org/_site
RequestHeader set X-Forwarded-Proto “https”
RequestHeader set X-Forwarded-Port “443”

ErrorDocument 404 /404.html

ExpiresActive On
ExpiresDefault "access plus 10 minutes"
ProxyPass / http://localhost:<%= @docker_external_port %>/
ProxyPreserveHost on
</VirtualHost>

<Directory /srv/<%= @year %>.stateofthemap.org/_site>
Require all granted
</Directory>

0 comments on commit a55ea01

Please sign in to comment.