From 0a21f6a638988d30bf212b8df5e3b46a0b3a88de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Le=20Ninivin?= <cedric.leninivin@tiolive.com> Date: Thu, 10 Dec 2020 18:01:55 +0100 Subject: [PATCH] html5as-base: Add basic html5as sr as base for tutorial --- software/html5as-base/README.md | 23 +++ software/html5as-base/instance.cfg.in | 27 ++++ software/html5as-base/instance_html5as.cfg.in | 131 ++++++++++++++++++ software/html5as-base/software.cfg | 70 ++++++++++ software/html5as-base/templates/launcher.in | 6 + software/html5as-base/templates/mime_types.in | 78 +++++++++++ software/html5as-base/templates/nginx_conf.in | 34 +++++ 7 files changed, 369 insertions(+) create mode 100644 software/html5as-base/README.md create mode 100644 software/html5as-base/instance.cfg.in create mode 100644 software/html5as-base/instance_html5as.cfg.in create mode 100644 software/html5as-base/software.cfg create mode 100644 software/html5as-base/templates/launcher.in create mode 100644 software/html5as-base/templates/mime_types.in create mode 100644 software/html5as-base/templates/nginx_conf.in diff --git a/software/html5as-base/README.md b/software/html5as-base/README.md new file mode 100644 index 000000000..eb1891bd3 --- /dev/null +++ b/software/html5as-base/README.md @@ -0,0 +1,23 @@ +# Html5 Application Server # + +## Presentation ## + +* Fast hosting software for static website (html5) + +* Use Nginx server + +## Parameter ## + +download_url (string) :required + +Details : + +* Only tarball (tar) is supported + +* Compressed format is gunzip (optional) + +* Tarball must contain an index.html at its root + +## How it works ## + +Each time you (re)start your instance or update parameters, html5as will remove previous website then download tarball and extract it in docroot directory. diff --git a/software/html5as-base/instance.cfg.in b/software/html5as-base/instance.cfg.in new file mode 100644 index 000000000..c21b979e2 --- /dev/null +++ b/software/html5as-base/instance.cfg.in @@ -0,0 +1,27 @@ +[buildout] +parts = + switch-softwaretype + +eggs-directory = {{ buildout['eggs-directory'] }} +develop-eggs-directory = {{ buildout['develop-eggs-directory'] }} +offline = true + +[profile-common] +nginx_location = {{ nginx_location }} +dash_location = {{ dash_location }} +template_nginx_conf = {{ template_nginx_conf_target }} +template_mime_types = {{ template_mime_types_target }} +template_launcher = {{ template_launcher_target }} + +[instance-html5as] +recipe = slapos.recipe.template:jinja2 +template = {{ template_instance_html5as_target }} +rendered = ${buildout:directory}/${:filename} +filename = instance-html5as.cfg +context = + section buildout buildout + section parameter_list profile-common + +[switch-softwaretype] +recipe = slapos.cookbook:softwaretype +default = ${instance-html5as:rendered} diff --git a/software/html5as-base/instance_html5as.cfg.in b/software/html5as-base/instance_html5as.cfg.in new file mode 100644 index 000000000..c230720fb --- /dev/null +++ b/software/html5as-base/instance_html5as.cfg.in @@ -0,0 +1,131 @@ +############################# +# +# Deploy html5as instance +# +############################# +[buildout] +parts = + nginx_conf + downloader + mime_types + launcher + publish-connection-information + +# Define egg directories to be the one from Software Release +# (/opt/slapgrid/...) +# Always the same. +eggs-directory = {{ buildout['eggs-directory'] }} +develop-eggs-directory = {{ buildout['develop-eggs-directory'] }} +offline = true + +# partition tree +# / +# |- etc/ +# | |- nginx.conf +# | |- run/ +# | |- html5as (binary) +# |- var/ +# | |- run/ +# | | |- nginx.pid +# | |- log/ +# | | |- nginx.log +# | | |- nginx.access.log +# |- srv/ +# | |- html5as/ (doc root) +# | | |- index.html +# | |- backup/ + +# Create all needed directories, depending on your needs +[directory] +recipe = slapos.cookbook:mkdirectory +home = ${buildout:directory} +etc = ${:home}/etc +var = ${:home}/var +srv = ${:home}/srv + +[basedirectory] +recipe = slapos.cookbook:mkdirectory +# Executables put here will be started but not monitored (for startup scripts) +script = ${directory:etc}/run +# Executables put here will be started and monitored (for daemons) +service = ${directory:etc}/service +log = ${directory:var}/log +run = ${directory:var}/run +backup = ${directory:srv}/backup +data = ${directory:srv}/html5as + +[tempdirectory] +recipe = slapos.cookbook:mkdirectory +tmp = ${directory:home}/tmp +client_body_temp_path = ${:tmp}/client_body_temp_path +proxy_temp_path = ${:tmp}/proxy_temp_path +fastcgi_temp_path = ${:tmp}/fastcgi_temp_path +uwsgi_temp_path = ${:tmp}/uwsgi_temp_path +scgi_temp_path = ${:tmp}/scgi_temp_path + +# List of options for html5as configuration +# It will run a simple nginx serving the content of srv/html5as +[html5as] +# Options +nb_workers = 2 + +# Network +ip = ${slap-network-information:global-ipv6} +port = 8081 +access_url = http://[${:ip}]:${:port} + +# Paths +# Log +path_pid = ${basedirectory:run}/nginx.pid +path_log = ${basedirectory:log}/nginx.log +path_access_log = ${basedirectory:log}/nginx.access.log +path_error_log = ${basedirectory:log}/nginx.error.log +path_tmp = ${tempdirectory:tmp} +# Docroot +docroot = ${basedirectory:data} +default_index = ${basedirectory:data}/index.html +# Config files +path_nginx_conf = ${directory:etc}/nginx.conf +path_mime_types = ${directory:etc}/mime_types +# Binaries +path_shell = {{ parameter_list['dash_location'] }}/bin/dash + +# Executables +bin_launcher = ${basedirectory:script}/launcher + +# Utils +path_nginx = {{ parameter_list['nginx_location'] }}/sbin/nginx + +# Render nginx conf +[nginx_conf] +recipe = slapos.recipe.template:jinja2 +template = {{ parameter_list['template_nginx_conf'] }} +rendered = ${html5as:path_nginx_conf} +context = + section param_html5as html5as + section param_tempdir tempdirectory + +# Render necessary mime types file for nginx +[mime_types] +recipe = slapos.recipe.template:jinja2 +template = {{ parameter_list['template_mime_types'] }} +rendered = ${html5as:path_mime_types} + +# Render the script launching nginx +[launcher] +recipe = slapos.recipe.template:jinja2 +template = {{ parameter_list['template_launcher'] }} +rendered = ${html5as:bin_launcher} +mode = 700 +context = + section param_html5as html5as + +# Simple command to put content in the docroot +[downloader] +recipe = plone.recipe.command +command = rm -r ${html5as:docroot}/*; echo "Hello World!" > ${html5as:docroot}/index.html + +# Publish nginx address +[publish-connection-information] +recipe = slapos.cookbook:publish +server_url = ${html5as:access_url} diff --git a/software/html5as-base/software.cfg b/software/html5as-base/software.cfg new file mode 100644 index 000000000..d234d8c09 --- /dev/null +++ b/software/html5as-base/software.cfg @@ -0,0 +1,70 @@ +[buildout] +extends = +# "slapos" stack describes basic things needed for 99.9% of SlapOS Software +# Releases + ../../stack/slapos.cfg +# Extend here component profiles, like openssl, apache, mariadb, curl... +# Or/and extend a stack (lamp, tomcat) that does most of the work for you +# In this example we extend needed components for html5as. + ../../component/nginx/buildout.cfg + ../../component/dash/buildout.cfg + +parts = +# Call installation of slapos.cookbook egg defined in stack/slapos.cfg (needed +# in 99,9% of Slapos Software Releases) + slapos-cookbook +# Call creation of instance.cfg file that will be called for deployment of +# instance + template-cfg + +# Download instance.cfg.in (buildout profile used to deployment of instance), +# replace all {{ foo_bar }} parameters by real values +# The recipe, template and mode are fetched from jijna-template +[template-cfg] +recipe = slapos.recipe.template:jinja2 +rendered = ${buildout:directory}/template.cfg +template = ${:_profile_base_location_}/${:filename} +filename = instance.cfg.in +md5sum = 5a6ebc126bcad3cdff1b51fb51f82a35 +mode = 0644 +context = + section buildout buildout + key nginx_location nginx:location + key dash_location dash:location + key template_nginx_conf_target template_nginx_conf:target + key template_mime_types_target template_mime_types:target + key template_launcher_target template_launcher:target + key template_instance_html5as_target instance_html5as:target + +# Download instance_html5as.cfg.in +[instance_html5as] +recipe = slapos.recipe.build:download +url = ${:_profile_base_location_}/${:_update_hash_filename_} +_update_hash_filename_ = instance_html5as.cfg.in +md5sum = 4a8c98cc5ca141f78f14fb9cec203cb8 +mode = 0644 + +[template_nginx_conf] +recipe = slapos.recipe.build:download +url = ${:_profile_base_location_}/${:_update_hash_filename_} +_update_hash_filename_ = templates/nginx_conf.in +md5sum = 61dc4c82bf48563228ce4dea6c5c6319 +mode = 0644 + +[template_launcher] +recipe = slapos.recipe.build:download +url = ${:_profile_base_location_}/${:_update_hash_filename_} +_update_hash_filename_ = templates/launcher.in +md5sum = 8d4d3152f5125f73d0c3f3ea1c3699dd +mode = 0644 + +[template_mime_types] +recipe = slapos.recipe.build:download +url = ${:_profile_base_location_}/${:_update_hash_filename_} +_update_hash_filename_ = templates/mime_types.in +md5sum = 4ef94a7b458d885cd79ba0b930a5727e +mode = 0644 + +# Pin versions of eggs used that are not already pinned by stack/slapos.cfg +[versions] +slapos.recipe.template = 4.4 diff --git a/software/html5as-base/templates/launcher.in b/software/html5as-base/templates/launcher.in new file mode 100644 index 000000000..86706c89e --- /dev/null +++ b/software/html5as-base/templates/launcher.in @@ -0,0 +1,6 @@ +#! {{ param_html5as['path_shell'] }} +# BEWARE: This file is operated by slapos node +# BEWARE: It will be overwritten automatically + +# Run nginx +exec {{ param_html5as['path_nginx'] }} -c {{ param_html5as['path_nginx_conf'] }} diff --git a/software/html5as-base/templates/mime_types.in b/software/html5as-base/templates/mime_types.in new file mode 100644 index 000000000..f07db332b --- /dev/null +++ b/software/html5as-base/templates/mime_types.in @@ -0,0 +1,78 @@ +types { + text/html html htm shtml; + text/css css; + text/xml xml rss; + image/gif gif; + image/jpeg jpeg jpg; + application/x-javascript js; + application/atom+xml atom; + + text/mathml mml; + text/plain txt; + text/vnd.sun.j2me.app-descriptor jad; + text/vnd.wap.wml wml; + text/x-component htc; + + image/png png; + image/tiff tif tiff; + image/vnd.wap.wbmp wbmp; + image/x-icon ico; + image/x-jng jng; + image/x-ms-bmp bmp; + image/svg+xml svg svgz; + + application/java-archive jar war ear; + application/mac-binhex40 hqx; + application/msword doc; + application/pdf pdf; + application/postscript ps eps ai; + application/rtf rtf; + application/vnd.ms-excel xls; + application/vnd.ms-powerpoint ppt; + application/vnd.wap.wmlc wmlc; + application/vnd.google-earth.kml+xml kml; + application/vnd.google-earth.kmz kmz; + application/x-7z-compressed 7z; + application/x-cocoa cco; + application/x-java-archive-diff jardiff; + application/x-java-jnlp-file jnlp; + application/x-makeself run; + application/x-perl pl pm; + application/x-pilot prc pdb; + application/x-rar-compressed rar; + application/x-redhat-package-manager rpm; + application/x-sea sea; + application/x-shockwave-flash swf; + application/x-stuffit sit; + application/x-tcl tcl tk; + application/x-x509-ca-cert der pem crt; + application/x-xpinstall xpi; + application/xhtml+xml xhtml; + application/zip zip; + + application/octet-stream bin exe dll; + application/octet-stream deb; + application/octet-stream dmg; + application/octet-stream eot; + application/octet-stream iso img; + application/octet-stream msi msp msm; + application/ogg ogx; + + audio/midi mid midi kar; + audio/mpeg mpga mpega mp2 mp3 m4a; + audio/ogg oga ogg spx; + audio/x-realaudio ra; + audio/webm weba; + + video/3gpp 3gpp 3gp; + video/mp4 mp4; + video/mpeg mpeg mpg mpe; + video/ogg ogv; + video/quicktime mov; + video/webm webm; + video/x-flv flv; + video/x-mng mng; + video/x-ms-asf asx asf; + video/x-ms-wmv wmv; + video/x-msvideo avi; +} diff --git a/software/html5as-base/templates/nginx_conf.in b/software/html5as-base/templates/nginx_conf.in new file mode 100644 index 000000000..503690356 --- /dev/null +++ b/software/html5as-base/templates/nginx_conf.in @@ -0,0 +1,34 @@ +worker_processes {{ param_html5as['nb_workers'] }}; + +pid {{ param_html5as['path_pid'] }}; +error_log {{ param_html5as['path_error_log'] }}; + +daemon off; + +events { + worker_connections 1024; + accept_mutex off; +} + +http { + include {{ param_html5as['path_mime_types'] }}; + default_type application/octet-stream; + types_hash_bucket_size 64; + access_log {{ param_html5as['path_access_log'] }} combined; + index index.html; + + server { + listen [{{ param_html5as['ip'] }}]:{{ param_html5as['port'] }}; + server_name _; + + keepalive_timeout 5; + client_body_temp_path {{ param_tempdir['client_body_temp_path'] }}; + proxy_temp_path {{ param_tempdir['proxy_temp_path'] }}; + fastcgi_temp_path {{ param_tempdir['fastcgi_temp_path'] }}; + uwsgi_temp_path {{ param_tempdir['uwsgi_temp_path'] }}; + scgi_temp_path {{ param_tempdir['scgi_temp_path'] }}; + + # path for static files + root {{ param_html5as['docroot'] }}; + } +} -- 2.30.9