This commit is contained in:
cronekorkn 2024-02-08 16:15:57 +01:00
parent cb8253e868
commit 6602f2569a
Signed by: cronekorkn
SSH key fingerprint: SHA256:v0410ZKfuO1QHdgKBsdQNF64xmTxOF8osF1LIqwTcVw
4 changed files with 83 additions and 15 deletions

View file

@ -1,4 +1,7 @@
# https://github.com/freescout-helpdesk/freescout/wiki/Installation-Guide
run_as = repo.libs.tools.run_as
php_version = node.metadata.get('php/version')
directories = {
'/opt/freescout': {
@ -8,13 +11,45 @@ directories = {
},
}
git_deploy = {
'/opt/freescout': {
'repo': 'https://github.com/freescout-helpdesk/freescout.git',
'rev': 'master',
actions = {
'clone_freescout': {
'command': run_as('www-data', 'git clone https://github.com/freescout-helpdesk/freescout.git /opt/freescout'),
'unless': 'test -e /opt/freescout/.git',
'needs': [
'pkg_apt:git',
'directory:/opt/freescout',
],
},
'pull_freescout': {
'command': run_as('www-data', 'git -C /opt/freescout pull'),
'unless': run_as('www-data', 'git -C /opt/freescout fetch origin && git -C /opt/freescout status -uno | grep -q "Your branch is up to date"'),
'needs': [
'action:clone_freescout',
],
'triggers': [
'action:freescout_artisan_update',
f'svc_systemd:php{php_version}-fpm.service:restart',
],
},
'freescout_artisan_update': {
'command': run_as('www-data', 'php /opt/freescout/artisan freescout:after-app-update'),
'triggered': True,
'needs': [
f'svc_systemd:php{php_version}-fpm.service:restart',
'action:pull_freescout',
],
},
}
files = {
'/opt/freescout/.env': {
'content': '\n'.join(
f'{k}={v}' for k, v in
sorted(node.metadata.get('freescout/env').items())
),
'needs': [
'directory:/opt/freescout',
'action:clone_freescout',
],
},
}

View file

@ -3,8 +3,9 @@ database_password = repo.vault.password_for(f'{node.name} postgresql freescout')
defaults = {
'apt': {
'packages': {
'git': {},
'php': {},
'php-mysql': {},
'php-pgsql': {},
'php-fpm': {},
'php-mbstring': {},
'php-xml': {},
@ -15,6 +16,18 @@ defaults = {
'php-intl': {},
},
},
'freescout': {
'env': {
'APP_TIMEZONE': 'Europe/Berlin',
'DB_CONNECTION': 'pgsql',
'DB_HOST': '127.0.0.1',
'DB_PORT': '5432',
'DB_DATABASE': 'freescout',
'DB_USERNAME': 'freescout',
'DB_PASSWORD': database_password,
'APP_KEY': 'base64:' + repo.vault.random_bytes_as_base64_for(f'{node.name} freescout APP_KEY', length=32).value
},
},
'php': {
'php.ini': {
'cgi': {
@ -34,9 +47,29 @@ defaults = {
},
},
},
'zfs': {
'datasets': {
'tank/freescout': {
'mountpoint': '/opt/freescout',
},
},
},
}
@metadata_reactor.provides(
'freescout/env/APP_URL',
)
def freescout(metadata):
return {
'freescout': {
'env': {
'APP_URL': 'https://' + metadata.get('freescout/domain') + '/',
},
},
}
@metadata_reactor.provides(
'nginx/vhosts',
)

View file

@ -1,9 +1,3 @@
from os.path import join
import json
from bundlewrap.utils.dicts import merge_dict
version = node.metadata.get('php/version')
files = {
@ -21,7 +15,7 @@ files = {
f'pkg_apt:php{version}-fpm',
},
'triggers': {
f'svc_systemd:php{version}-fpm:restart',
f'svc_systemd:php{version}-fpm.service:restart',
},
},
f'/etc/php/{version}/fpm/pool.d/www.conf': {
@ -33,13 +27,13 @@ files = {
f'pkg_apt:php{version}-fpm',
},
'triggers': {
f'svc_systemd:php{version}-fpm:restart',
f'svc_systemd:php{version}-fpm.service:restart',
},
},
}
svc_systemd = {
f'php{version}-fpm': {
f'php{version}-fpm.service': {
'needs': {
'pkg_apt:',
f'file:/etc/php/{version}/fpm/php.ini',

View file

@ -86,3 +86,9 @@ def require_bundle(node, bundle, hint=''):
# way of defining bundle requirements in other bundles.
if not node.has_bundle(bundle):
raise BundleError(f'{node.name} requires bundle {bundle}, but wasn\'t found! {hint}')
from shlex import quote
def run_as(user, command):
return f'sudo su - {user} -c {quote(command)} -s /bin/bash'