Add cookbook for static asset hosting

Configures assets.kosmos.org, only for webfont hosting for now.
This commit is contained in:
Basti 2021-02-25 12:12:41 +01:00
parent 09f0faadda
commit 1c47f9ab27
Signed by untrusted user: basti
GPG Key ID: 9F88009D31D99C72
4 changed files with 76 additions and 0 deletions

View File

@ -0,0 +1,3 @@
node.default["kosmos_assets"]["domain"] = "assets.kosmos.org"
node.default["kosmos_assets"]["repo"] = "https://gitea.kosmos.org/kosmos/assets.kosmos.org.git"
node.default["kosmos_assets"]["revision"] = "master"

View File

@ -0,0 +1,10 @@
name 'kosmos_assets'
maintainer 'Kosmos'
maintainer_email 'ops@kosmos.org'
license 'MIT'
description 'Configures static asset Web hosting'
long_description 'Configures static asset Web hosting'
version '1.0.0'
chef_version '>= 15.10' if respond_to?(:chef_version)
depends "kosmos-nginx"

View File

@ -0,0 +1,38 @@
#
# Cookbook:: kosmos_assets
# Recipe:: nginx_site
#
include_recipe "kosmos-nginx"
domain = node["kosmos_assets"]["domain"]
nginx_certbot_site domain
directory "/var/www/#{domain}/site" do
user node["nginx"]["user"]
group node["nginx"]["group"]
mode "0755"
end
git "/var/www/#{domain}/site" do
user node["nginx"]["user"]
group node["nginx"]["group"]
repository node["kosmos_assets"]["repo"]
revision node["kosmos_assets"]["revision"]
action :sync
end
template "#{node["nginx"]["dir"]}/sites-available/#{domain}" do
source "nginx_conf_assets.erb"
owner node["nginx"]["user"]
mode 0640
variables domain: domain,
ssl_cert: "/etc/letsencrypt/live/#{domain}/fullchain.pem",
ssl_key: "/etc/letsencrypt/live/#{domain}/privkey.pem"
notifies :reload, "service[nginx]", :delayed
end
nginx_site domain do
action :enable
end

View File

@ -0,0 +1,25 @@
<% if File.exist?(@ssl_cert) && File.exist?(@ssl_key) -%>
# Generated by Chef
server {
listen 443 ssl http2;
server_name <%= @domain %>;
root /var/www/<%= @domain %>/site;
access_log off;
gzip_static on;
gzip_comp_level 5;
location ~* .(css)$ {
expires 1d;
}
location ~* .(woff|woff2)$ {
expires max;
}
ssl_certificate <%= @ssl_cert %>;
ssl_certificate_key <%= @ssl_key %>;
}
<% end -%>