Skip to content
Snippets Groups Projects
Commit b3ff9df2 authored by Dmytro Bogatov's avatar Dmytro Bogatov :two_hearts:
Browse files

add webware

parent b17cc5c8
No related branches found
No related tags found
No related merge requests found
Pipeline #67079 failed
......@@ -20,3 +20,6 @@ infra/spaces-buffer
docker/out
key.json
compose/shevastream.json
compose/dist/*
services:
social_imps:
image: registry.dbogatov.org/wpi/cs-343/project:latest
ports:
- "8080:80"
deploy:
resources:
limits:
memory: 70M
restart: unless-stopped
webware:
image: registry.dbogatov.org/wpi/cs-4241:latest
ports:
- "8081:80"
deploy:
resources:
limits:
memory: 50M
restart: unless-stopped
# Compose with Sablier
```!sh
# when changing config
./generate.py
sudo docker compose -f ./dist/compose.yaml --profile idle --profile all create --remove-orphans
# Run as daemon
sudo docker compose -f ./dist/compose.yaml --profile idle up -d
```
#!/usr/bin/env python3
from jinja2 import Environment, FileSystemLoader
from pathlib import Path
import yaml
import os
import shutil
env = Environment(loader=FileSystemLoader('template'))
with open("services.yaml") as stream:
data = yaml.safe_load(stream)
for path in (Path("dist")).glob("*"):
os.remove(path)
for path in (Path("template")).glob("*.j2"):
template = env.get_template(path.name)
rendered_template = template.render(data)
with open(Path("dist") / path.stem, "w") as f:
f.write(rendered_template)
shutil.copy("nginx.conf", "dist/")
shutil.copy("sablier.js", "dist/")
shutil.copy("shevastream.json", "dist/")
load_module modules/ngx_http_js_module.so;
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
access_log /var/log/nginx/access.log main;
sendfile on;
#tcp_nopush on;
keepalive_timeout 65;
#gzip on;
include /etc/nginx/conf.d/*.conf;
}
const querystring = require('querystring')
function call(r) {
const config = createConfigurationFromVariables(r)
const request = buildRequest(config)
r.subrequest(request.url, request.query,
function(reply) {
if (reply.headersOut["X-Sablier-Session-Status"] == "ready") {
r.internalRedirect(config.internalRedirect);
} else {
r.headersOut["Content-Type"] = reply.headersOut["Content-Type"]
r.headersOut["Content-Length"] = reply.headersOut["Content-Length"]
r.return(200, reply.responseBuffer);
}
}
);
}
/**
* @typedef {Object} SablierConfig
* @property {string} sablierUrl
* @property {string} names
* @property {string} group
* @property {string} sessionDuration
* @property {string} internalRedirect
* @property {string} displayName
* @property {string} showDetails
* @property {string} theme
* @property {string} refreshFrequency
* @property {string} timeout
*
*/
/**
*
* @param {*} headers
* @returns {SablierConfig}
*/
function createConfigurationFromVariables(r) {
return {
sablierUrl: r.variables.sablierUrl,
names: r.variables.sablierNames,
group: r.variables.sablierGroup,
sessionDuration: r.variables.sablierSessionDuration,
internalRedirect: r.variables.sablierNginxInternalRedirect,
displayName: r.variables.sablierDynamicName,
showDetails: r.variables.sablierDynamicShowDetails,
theme: r.variables.sablierDynamicTheme,
refreshFrequency: r.variables.sablierDynamicRefreshFrequency,
timeout: r.variables.sablierBlockingTimeout,
}
}
/**
*
* @param {SablierConfig} c
* @returns
*/
function buildRequest(c) {
if (c.timeout == undefined || c.timeout == "") {
return createDynamicUrl(c)
} else {
return createBlockingUrl(c)
}
}
/**
*
* @param {SablierConfig} config
* @returns
*/
function createDynamicUrl(config) {
const url = `${config.sablierUrl}/api/strategies/dynamic`
const query = {
session_duration: config.sessionDuration,
display_name:config.displayName,
theme: config.theme,
refresh_frequency: config.refreshFrequency,
show_details: config.showDetails
};
if(config.names) {
query.names = config.names.split(",").map(name => name.trim())
} else if(config.group) {
query.group = config.group
} else {
throw new Error('you must specify names or group');
}
return {url, query: querystring.stringify(query)}
}
/**
*
* @param {SablierConfig} config
* @returns
*/
function createBlockingUrl(config) {
const url = `${config.sablierUrl}/api/strategies/blocking`
const query = {
session_duration: config.sessionDuration,
timeout:config.timeout,
};
if(config.names) {
query.names = config.names.split(",").map(name => name.trim())
} else if(config.group) {
query.group = config.group
} else {
throw new Error('you must specify names or group');
}
return {url, query: querystring.stringify(query)}
}
export default { call };
version: 2
services:
- name: social_imps
image: registry.dbogatov.org/wpi/cs-343/project:latest
- name: webware
image: registry.dbogatov.org/wpi/cs-4241:latest
- name: ore
image: registry.dbogatov.org/bu/ore-benchmark/project-code/website:master
- name: shevastream
image: registry.dbogatov.org/dbogatov/shevastream:master
volume:
from: schevastream.conf
to: appsettings.production.json
services:
sablier:
# TODO: https://github.com/sablierapp/sablier/issues/450
image: dbogatov/docker-sources:acouvreur--sablier-1.7.1-beta.1-multi-arch
profiles: ["idle"]
command:
- start
- --provider.name=docker
volumes:
- '/var/run/docker.sock:/var/run/docker.sock'
restart: unless-stopped
proxy:
image: dbogatov/docker-sources:nginx-1.27.3-multi-arch
profiles: ["idle"]
ports:
- "8000:80"
volumes:
- ./nginx.conf:/etc/nginx/nginx.conf:ro
- ./sablier.js:/etc/nginx/conf.d/sablier.js:ro
- ./proxy.conf:/etc/nginx/conf.d/default.conf:ro
restart: unless-stopped
{% for service in services %}
{{ service.name }}_v{{ version }}:
image: {{ service.image }}
labels:
- sablier.enable=true
- sablier.group={{ service.name }}_v{{ version }}
profiles: ["all"]
{% if "volume" in service %}
volumes:
- ./{{ service.volume.from }}:/{{ service.volume.to }}:ro
{% endif %}
{% endfor %}
js_import conf.d/sablier.js;
resolver 127.0.0.11 valid=10s ipv6=off;
server {
listen 80;
subrequest_output_buffer_size 32k;
set $sablierUrl /sablier;
set $sablierSessionDuration 5m;
location /sablier/ {
internal;
proxy_method GET;
proxy_pass http://sablier:10000/;
}
{% for service in services %}
location @{{ service.name }}_v{{ version }} {
set ${{ service.name }}_v{{ version }}_server {{ service.name }}_v{{ version }};
set $proxy_uri $request_uri;
if ($proxy_uri ~* ^/dynamic/{{ service.name }}/(.*)$ ) {
set $proxy_uri $1;
}
proxy_pass http://${{ service.name }}_v{{ version }}_server:80/$proxy_uri;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location /dynamic/{{ service.name }} {
set $sablierDynamicShowDetails true;
set $sablierDynamicRefreshFrequency 5s;
set $sablierNginxInternalRedirect @{{ service.name }}_v{{ version }};
set $sablierGroup {{ service.name }}_v{{ version }};
set $sablierDynamicName "Dynamic {{ service.name }}";
set $sablierDynamicTheme hacker-terminal;
js_content sablier.call;
}
{% endfor %}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment