Merge branch 'nginx' of ssh://git.karchnu.fr:2202/WeirdOS/service into nginx
commit
221206ec84
|
@ -1,5 +1,6 @@
|
||||||
command: gitea -C . -w . -c ./custom/conf/app.ini
|
command: gitea -C . -w . -c ./custom/conf/app.ini
|
||||||
consumes: postgresql
|
consumes: postgresql
|
||||||
|
requires-domain: true
|
||||||
|
|
||||||
%directory ${SERVICE_ROOT}/custom/conf
|
%directory ${SERVICE_ROOT}/custom/conf
|
||||||
name: working directory
|
name: working directory
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
command: echo "coucou"
|
command: echo "coucou"
|
||||||
consumes: www
|
consumes: www
|
||||||
|
requires-domain: true
|
||||||
|
|
||||||
%directory ${SERVICE_ROOT}/
|
%directory ${SERVICE_ROOT}/
|
||||||
name: data directory
|
name: data directory
|
||||||
|
|
|
@ -7,6 +7,18 @@ def sanitize_path(path)
|
||||||
path.gsub /\/\/+/, "/"
|
path.gsub /\/\/+/, "/"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class Service
|
||||||
|
def to_genconfig
|
||||||
|
Hash(String, String?).new.tap do |entry|
|
||||||
|
entry["name"] = name
|
||||||
|
entry["id"] = full_id
|
||||||
|
entry["environment"] = environment.name
|
||||||
|
entry["root"] = root
|
||||||
|
entry["domain"] = domain
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
module GenConfig
|
module GenConfig
|
||||||
# FIXME: The fuck has this become.
|
# FIXME: The fuck has this become.
|
||||||
alias Variables =
|
alias Variables =
|
||||||
|
@ -14,6 +26,7 @@ module GenConfig
|
||||||
Array(String) | Array(Variables) |
|
Array(String) | Array(Variables) |
|
||||||
Hash(String, String) | Hash(String, Variables) |
|
Hash(String, String) | Hash(String, Variables) |
|
||||||
Array(Hash(String, String?)) |
|
Array(Hash(String, String?)) |
|
||||||
|
Hash(String, Array(Hash(String, String?))) |
|
||||||
Hash(String, String?) |
|
Hash(String, String?) |
|
||||||
Crinja::Callable::Instance
|
Crinja::Callable::Instance
|
||||||
|
|
||||||
|
@ -78,57 +91,26 @@ class GenConfig::Context
|
||||||
raise Exception.new "Could not find template to generate file ('#{target}')."
|
raise Exception.new "Could not find template to generate file ('#{target}')."
|
||||||
end
|
end
|
||||||
|
|
||||||
pp ENV["SERVICE_ID"]?
|
|
||||||
if service_id = ENV["SERVICE_ID"]?
|
if service_id = ENV["SERVICE_ID"]?
|
||||||
if service = Service.get_by_id service_id
|
if service = Service.get_by_id service_id
|
||||||
environment = service.environment
|
environment = service.environment
|
||||||
|
|
||||||
options["id"] = service.full_id
|
options["service"] = service.to_genconfig
|
||||||
options["name"] = service.name
|
|
||||||
options["service_root"] = service.root
|
|
||||||
|
|
||||||
options["environment"] = environment.name
|
options["providers"] = service.providers.compact_map do |token, provider|
|
||||||
options["environment_root"] = environment.root
|
|
||||||
|
|
||||||
providers = Hash(String, Variables).new
|
|
||||||
service.providers.each do |token, provider|
|
|
||||||
provider = Service.get_by_id provider
|
provider = Service.get_by_id provider
|
||||||
|
|
||||||
next unless provider
|
next unless provider
|
||||||
|
|
||||||
# FIXME: deduplicate
|
provider.to_genconfig
|
||||||
providers[token] = Hash(String, String?).new.tap do |entry|
|
|
||||||
entry["name"] = provider.name
|
|
||||||
entry["id"] = provider.full_id
|
|
||||||
entry["environment"] = provider.environment.name
|
|
||||||
entry["root"] = provider.root
|
|
||||||
entry["domain"] = provider.domain
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
options["providers"] = providers
|
|
||||||
|
|
||||||
consumers = Hash(String, Variables).new
|
options["consumers"] = service.provides
|
||||||
service.provides.each do |provider_data|
|
.map(&.token)
|
||||||
token = provider_data.token
|
.map{ |token|
|
||||||
|
{token, service.get_consumers(token).map &.to_genconfig}
|
||||||
# FIXME: definitely unreadable
|
}
|
||||||
consumers[token] = Service.all
|
.to_h
|
||||||
.select(
|
|
||||||
&.providers.select do |t, provider|
|
|
||||||
t == token && service.is_id?(provider)
|
|
||||||
end
|
|
||||||
.size.>(0))
|
|
||||||
.map do |consumer|
|
|
||||||
Hash(String, String?).new.tap do |entry|
|
|
||||||
entry["name"] = consumer.name
|
|
||||||
entry["id"] = consumer.id
|
|
||||||
entry["environment"] = consumer.environment.name
|
|
||||||
entry["root"] = consumer.root
|
|
||||||
entry["domain"] = consumer.domain
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
options["consumers"] = consumers
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ commands = CommandsList.new
|
||||||
|
|
||||||
commands.push "add", "Adds a service to an environment." do |args|
|
commands.push "add", "Adds a service to an environment." do |args|
|
||||||
providers = Hash(String, String).new
|
providers = Hash(String, String).new
|
||||||
|
domain = nil
|
||||||
|
|
||||||
environment, service = Service.parse_id args[0]
|
environment, service = Service.parse_id args[0]
|
||||||
|
|
||||||
|
@ -52,15 +53,25 @@ commands.push "add", "Adds a service to an environment." do |args|
|
||||||
|
|
||||||
match = arg.match /(.*)=(.*)/
|
match = arg.match /(.*)=(.*)/
|
||||||
|
|
||||||
if match.nil?
|
if match.nil? || match.size < 2
|
||||||
raise ::Service::Exception.new "usage: service add <service> <token=provider>"
|
raise ::Service::Exception.new "usage: service add <service> <token=provider>"
|
||||||
next
|
next
|
||||||
end
|
end
|
||||||
|
|
||||||
providers[match[1]] = match[2]
|
_, key, value = match
|
||||||
|
|
||||||
|
if key == "domain"
|
||||||
|
domain = value
|
||||||
|
else
|
||||||
|
providers[key] = value
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Service.new(service, environment).tap do |service|
|
Service.new(service, environment).tap do |service|
|
||||||
|
if domain
|
||||||
|
service.domain = domain
|
||||||
|
end
|
||||||
|
|
||||||
service.consumes.each do |token|
|
service.consumes.each do |token|
|
||||||
provider = providers[token.token]?
|
provider = providers[token.token]?
|
||||||
|
|
||||||
|
@ -76,7 +87,10 @@ commands.push "add", "Adds a service to an environment." do |args|
|
||||||
|
|
||||||
service.providers[token.token] = provider
|
service.providers[token.token] = provider
|
||||||
end
|
end
|
||||||
pp! service.providers
|
|
||||||
|
if service.requires_domain && !service.domain
|
||||||
|
raise Service::Exception.new "'#{service.name}' requires a domain= parameter to be provided!"
|
||||||
|
end
|
||||||
end.write RC_DIRECTORY
|
end.write RC_DIRECTORY
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Service
|
||||||
getter environment : Environment
|
getter environment : Environment
|
||||||
getter providers = ProvidersList.new
|
getter providers = ProvidersList.new
|
||||||
|
|
||||||
getter domain : String?
|
property domain : String?
|
||||||
|
|
||||||
# The place we’ll store configuration and data.
|
# The place we’ll store configuration and data.
|
||||||
@root : String?
|
@root : String?
|
||||||
|
@ -81,6 +81,10 @@ class Service
|
||||||
file << "root: #{@root}"
|
file << "root: #{@root}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
if @domain
|
||||||
|
file << "domain: #{@domain}"
|
||||||
|
end
|
||||||
|
|
||||||
@providers.each do |token, provider|
|
@providers.each do |token, provider|
|
||||||
file << "%consumes #{token}"
|
file << "%consumes #{token}"
|
||||||
file << " from: #{provider}"
|
file << " from: #{provider}"
|
||||||
|
@ -120,6 +124,9 @@ class Service
|
||||||
def consumes
|
def consumes
|
||||||
@reference.consumes
|
@reference.consumes
|
||||||
end
|
end
|
||||||
|
def requires_domain
|
||||||
|
@reference.requires_domain
|
||||||
|
end
|
||||||
|
|
||||||
def root
|
def root
|
||||||
@root || "#{@environment.root}/#{name}"
|
@root || "#{@environment.root}/#{name}"
|
||||||
|
@ -441,6 +448,16 @@ class Service
|
||||||
def get_default_provider(token) : String?
|
def get_default_provider(token) : String?
|
||||||
@environment.get_provider(token) || Environment.root.get_provider(token)
|
@environment.get_provider(token) || Environment.root.get_provider(token)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def consumes?(token, origin)
|
||||||
|
providers.select do |_token, provider|
|
||||||
|
token == _token && origin.is_id?(provider)
|
||||||
|
end.size > 0
|
||||||
|
end
|
||||||
|
|
||||||
|
def get_consumers(token)
|
||||||
|
Service.all.select(&.consumes?(token, self))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,8 @@ class ServiceDefinition
|
||||||
getter pre_start_hooks : Array(Hook)
|
getter pre_start_hooks : Array(Hook)
|
||||||
getter provides : Array(Provides)
|
getter provides : Array(Provides)
|
||||||
|
|
||||||
|
getter requires_domain = false
|
||||||
|
|
||||||
def initialize(@name, specs : SpecParser)
|
def initialize(@name, specs : SpecParser)
|
||||||
sections = specs.sections
|
sections = specs.sections
|
||||||
specs = specs.assignments
|
specs = specs.assignments
|
||||||
|
@ -60,6 +62,18 @@ class ServiceDefinition
|
||||||
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
|
@consumes = specs["consumes"]?.try &.as_a_or_s.map { |x| Consumes.new x } || Array(Consumes).new
|
||||||
@environment_variables = specs["environment-variables"]?.try &.as_a_or_s || Array(String).new
|
@environment_variables = specs["environment-variables"]?.try &.as_a_or_s || Array(String).new
|
||||||
|
|
||||||
|
# FIXME: as_b?
|
||||||
|
requires_domain = specs["requires-domain"]?.try &.as_s
|
||||||
|
case requires_domain
|
||||||
|
when nil
|
||||||
|
when "true", "yes"
|
||||||
|
@requires_domain = true
|
||||||
|
when "false", "no"
|
||||||
|
@requires_domain = false
|
||||||
|
else
|
||||||
|
STDERR.puts "warning: definition '#{@name}' has a 'requires-domain' entry with an invalid value"
|
||||||
|
end
|
||||||
|
|
||||||
@pre_start_hooks = Array(Hook).new
|
@pre_start_hooks = Array(Hook).new
|
||||||
|
|
||||||
sections.each do |section|
|
sections.each do |section|
|
||||||
|
|
|
@ -16,25 +16,25 @@ SECRET_KEY = vPFgSqRMIe7Dzk4frRM4UA3CETedL8agK7x6IQFQt9YfRPiQGhQbYAGfyan71iU
|
||||||
[database]
|
[database]
|
||||||
DB_TYPE = postgres
|
DB_TYPE = postgres
|
||||||
HOST = 127.0.0.1:{{ port(providers.postgresql) }}
|
HOST = 127.0.0.1:{{ port(providers.postgresql) }}
|
||||||
NAME = {{ id | replace("/", "_") }}_db
|
NAME = {{ service.id | replace("/", "_") }}_db
|
||||||
USER = {{ id | replace("/", "_") }}
|
USER = {{ service.id | replace("/", "_") }}
|
||||||
PASSWD = {{ random_password( id ) }}
|
PASSWD = {{ random_password( service.id ) }}
|
||||||
SSL_MODE = disable
|
SSL_MODE = disable
|
||||||
CHARSET = utf8
|
CHARSET = utf8
|
||||||
PATH = /srv/{{ environment }}/gitea/data/gitea.db
|
PATH = {{ service.root }}/data/gitea.db
|
||||||
|
|
||||||
[repository]
|
[repository]
|
||||||
ROOT = /srv/{{ environment }}/gitea/repositories
|
ROOT = {{ service.root }}/repositories
|
||||||
|
|
||||||
[server]
|
[server]
|
||||||
SSH_DOMAIN = localhost
|
SSH_DOMAIN = {{ service.domain }}
|
||||||
DOMAIN = localhost
|
DOMAIN = {{ service.domain }}
|
||||||
HTTP_PORT = {{ port(id) }}
|
HTTP_PORT = {{ port(service.id) }}
|
||||||
ROOT_URL = http://localhost:{{ port(id) }}/
|
ROOT_URL = http://{{ service.domain }}:{{ port(service.id) }}/
|
||||||
DISABLE_SSH = false
|
DISABLE_SSH = false
|
||||||
SSH_PORT = 22
|
SSH_PORT = 22
|
||||||
LFS_START_SERVER = true
|
LFS_START_SERVER = true
|
||||||
LFS_CONTENT_PATH = /srv/{{ environment }}/gitea/data/lfs
|
LFS_CONTENT_PATH = {{ service.root }}/data/lfs
|
||||||
LFS_JWT_SECRET = nUIANTsStEelCeOo7SFTcJllpJ6I8DXNr7duUgGMXfI
|
LFS_JWT_SECRET = nUIANTsStEelCeOo7SFTcJllpJ6I8DXNr7duUgGMXfI
|
||||||
OFFLINE_MODE = false
|
OFFLINE_MODE = false
|
||||||
|
|
||||||
|
@ -67,6 +67,6 @@ PROVIDER = file
|
||||||
[log]
|
[log]
|
||||||
MODE = file
|
MODE = file
|
||||||
LEVEL = info
|
LEVEL = info
|
||||||
ROOT_PATH = /srv/{{ environment }}/gitea/log
|
ROOT_PATH = {{ service.root }}/log
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -8,8 +8,8 @@ events {
|
||||||
}
|
}
|
||||||
|
|
||||||
http {
|
http {
|
||||||
error_log /var/log/{{ id | replace("/", "_") }}_error.log warn;
|
error_log /var/log/{{ service.id | replace("/", "_") }}_error.log warn;
|
||||||
access_log /var/log/{{ id | replace("/", "_") }}_access.log;
|
access_log /var/log/{{ service.id | replace("/", "_") }}_access.log;
|
||||||
|
|
||||||
include /etc/nginx/mime.types;
|
include /etc/nginx/mime.types;
|
||||||
default_type application/octet-stream;
|
default_type application/octet-stream;
|
||||||
|
|
|
@ -60,7 +60,7 @@
|
||||||
# comma-separated list of addresses;
|
# comma-separated list of addresses;
|
||||||
# defaults to 'localhost'; use '*' for all
|
# defaults to 'localhost'; use '*' for all
|
||||||
# (change requires restart)
|
# (change requires restart)
|
||||||
port = {{port(id)}}
|
port = {{port(service.id)}}
|
||||||
max_connections = 100 # (change requires restart)
|
max_connections = 100 # (change requires restart)
|
||||||
#superuser_reserved_connections = 3 # (change requires restart)
|
#superuser_reserved_connections = 3 # (change requires restart)
|
||||||
#unix_socket_directories = '/run/postgresql' # comma-separated list of directories
|
#unix_socket_directories = '/run/postgresql' # comma-separated list of directories
|
||||||
|
@ -687,4 +687,4 @@ default_text_search_config = 'pg_catalog.english'
|
||||||
# CUSTOMIZED OPTIONS
|
# CUSTOMIZED OPTIONS
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# Add settings for extensions here
|
# Add settings for extensions here
|
||||||
|
|
Loading…
Reference in New Issue