2023-05-07 13:15:45 +02:00
|
|
|
---
|
2020-03-04 00:10:16 +01:00
|
|
|
{% macro gvaapp_base(gvaappname, servicename) -%}
|
|
|
|
{% set app_home = salt['grains.get']('gnuviechadmin:home', '/home/{}'.format(gvaappname)) %}
|
|
|
|
{% set app_user = salt['grains.get']('gnuviechadmin:user', gvaappname) %}
|
|
|
|
{% set app_group = salt['grains.get']('gnuviechadmin:group', gvaappname) %}
|
|
|
|
|
2020-03-04 14:03:35 +01:00
|
|
|
{% set appfullname = 'GNUViech Admin {} User'.format(salt['pillar.get']('gnuviechadmin:{}:fullname'.format(gvaappname))) -%}
|
2020-03-04 00:10:16 +01:00
|
|
|
{% set update_git = salt['grains.get']('gnuviechadmin:update_git', True) %}
|
|
|
|
{% set gitrepo = salt['pillar.get']('gnuviechadmin:{}:git_url'.format(gvaappname), 'git:gnuviech/{}.git'.format(gvaappname)) -%}
|
|
|
|
{% set checkout = salt['grains.get']('gnuviechadmin:checkout', '/srv/{}'.format(gvaappname)) -%}
|
|
|
|
{% set deployment_key = '{}/.ssh/id_deployment'.format(app_home) -%}
|
|
|
|
|
2020-03-07 18:26:52 +01:00
|
|
|
{% for host in salt['pillar.get']('gnuviechadmin:machines', {}) %}
|
|
|
|
{% if host != salt['grains.get']('host') %}
|
|
|
|
{{ host }}:
|
|
|
|
host.present:
|
|
|
|
- ip: {{ salt['pillar.get']('gnuviechadmin:machines:{}:ip'.format(host)) }}
|
|
|
|
{% if salt['pillar.get']('gnuviechadmin:machines:{}:names'.format(host)) %}
|
|
|
|
- names:
|
|
|
|
{% for machine in salt['pillar.get']('gnuviechadmin:machines:{}:names'.format(host)) %}
|
|
|
|
- {{ machine }}
|
|
|
|
{% endfor %}
|
|
|
|
{% endif %}
|
|
|
|
{% endif %}
|
|
|
|
{% endfor %}
|
|
|
|
|
2020-03-04 00:10:16 +01:00
|
|
|
{{ gvaappname }}-group:
|
|
|
|
group.present:
|
|
|
|
- name: {{ app_group }}
|
|
|
|
|
|
|
|
{{ gvaappname }}-user:
|
|
|
|
user.present:
|
|
|
|
- name: {{ app_user }}
|
|
|
|
- home: {{ app_home }}
|
|
|
|
- shell: /bin/bash
|
|
|
|
- fullname: {{ appfullname }}
|
|
|
|
- groups:
|
|
|
|
- {{ app_group }}
|
2020-03-07 18:26:52 +01:00
|
|
|
- require:
|
|
|
|
- group: {{ gvaappname }}-group
|
2020-03-04 00:10:16 +01:00
|
|
|
alias.present:
|
|
|
|
- target: root
|
|
|
|
|
|
|
|
gvabase-dependencies:
|
|
|
|
pkg.installed:
|
|
|
|
- name: build-essential
|
|
|
|
|
2023-05-06 14:42:50 +02:00
|
|
|
/var/log/gnuviechadmin:
|
2020-03-04 00:10:16 +01:00
|
|
|
file.directory:
|
|
|
|
- user: {{ app_user }}
|
|
|
|
- group: {{ app_group }}
|
2023-05-06 14:42:50 +02:00
|
|
|
- mode: 0750
|
2020-03-04 00:10:16 +01:00
|
|
|
- require:
|
|
|
|
- user: {{ gvaappname }}-user
|
2023-05-06 14:42:50 +02:00
|
|
|
- group: {{ gvaappname }}-group
|
2020-03-04 00:10:16 +01:00
|
|
|
|
|
|
|
{{ checkout }}:
|
|
|
|
file.directory:
|
|
|
|
- user: {{ app_user }}
|
|
|
|
- group: {{ app_group }}
|
|
|
|
- mode: 0755
|
|
|
|
- require:
|
|
|
|
- user: {{ gvaappname }}-user
|
|
|
|
|
|
|
|
{% if update_git %}
|
|
|
|
{{ gitrepo }}:
|
|
|
|
git.latest:
|
|
|
|
- user: {{ app_user }}
|
|
|
|
- target: {{ checkout }}
|
|
|
|
- rev: {{ salt['pillar.get']('gnuviechadmin:{}:git_branch'.format(gvaappname), 'production') }}
|
2023-05-06 14:42:50 +02:00
|
|
|
- force_clone: true
|
2020-03-04 00:10:16 +01:00
|
|
|
- require:
|
|
|
|
- file: {{ checkout }}
|
|
|
|
- watch_in:
|
|
|
|
- cmd: {{ gvaappname }}-requirements
|
|
|
|
- service: {{ servicename }}
|
|
|
|
{% endif %}
|
|
|
|
|
|
|
|
{{ gvaappname }}-requirements:
|
2023-05-07 13:15:45 +02:00
|
|
|
cmd.run:
|
2023-05-06 14:42:50 +02:00
|
|
|
- name: /usr/local/poetry/bin/poetry install
|
2020-03-04 00:10:16 +01:00
|
|
|
- runas: {{ app_user }}
|
|
|
|
- cwd: {{ checkout }}
|
|
|
|
- env:
|
2023-05-06 14:42:50 +02:00
|
|
|
- POETRY_VIRTUALENVS_IN_PROJECT: "true"
|
2020-03-04 00:10:16 +01:00
|
|
|
- LC_ALL: C.UTF-8
|
|
|
|
- LANG: C.UTF-8
|
|
|
|
- require:
|
2023-05-06 14:42:50 +02:00
|
|
|
- cmd: install_poetry
|
2020-03-04 00:10:16 +01:00
|
|
|
{%- if update_git %}
|
|
|
|
- git: {{ gitrepo }}
|
|
|
|
{%- else %}
|
|
|
|
- file: {{ checkout }}
|
|
|
|
{%- endif %}
|
|
|
|
- pkg: gvabase-dependencies
|
2023-05-07 13:15:45 +02:00
|
|
|
- unless: test $(find {{ checkout }}/.venv -type f -cnewer poetry.lock \! -name '*.pyc'|wc -l) -gt 0
|
2020-03-04 00:10:16 +01:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ servicename }}
|
|
|
|
{% endmacro %}
|
|
|
|
|
|
|
|
{% macro create_celery_worker(gvaappname, purpose) %}
|
|
|
|
{% set app_home = salt['grains.get']('gnuviechadmin:home', '/home/{}'.format(gvaappname)) %}
|
|
|
|
{% set app_user = salt['grains.get']('gnuviechadmin:user', gvaappname) %}
|
|
|
|
{% set app_group = salt['grains.get']('gnuviechadmin:group', gvaappname) %}
|
|
|
|
|
|
|
|
{% set checkout = salt['grains.get']('gnuviechadmin:checkout', '/srv/{}'.format(gvaappname)) -%}
|
|
|
|
{% set gitrepo = salt['pillar.get']('gnuviechadmin:{}:git_url'.format(gvaappname), 'git:gnuviech/{}.git'.format(gvaappname)) -%}
|
|
|
|
{% set update_git = salt['grains.get']('gnuviechadmin:update_git', True) %}
|
|
|
|
|
2020-03-04 14:03:35 +01:00
|
|
|
{% set servicename = "{}-celery-worker".format(gvaappname) %}
|
2020-03-04 15:02:58 +01:00
|
|
|
{% set amqp_user = salt['pillar.get']('gnuviechadmin:{}:amqp_user'.format(gvaappname)) -%}
|
2020-03-07 18:26:52 +01:00
|
|
|
{{ gvaapp_base(gvaappname, servicename) }}
|
2020-03-04 00:10:16 +01:00
|
|
|
/etc/default/{{ gvaappname }}:
|
|
|
|
file.managed:
|
|
|
|
- user: root
|
|
|
|
- group: root
|
|
|
|
- mode: 0640
|
|
|
|
- source: salt://gnuviechadmin/{{ gvaappname }}/celery-worker.env
|
|
|
|
- template: jinja
|
|
|
|
- context:
|
|
|
|
checkout: {{ checkout }}
|
2020-03-04 15:02:58 +01:00
|
|
|
broker_url: amqp://{{ amqp_user }}:{{ salt['pillar.get']('gnuviechadmin:queues:users:{}:password'.format(amqp_user)) }}@{{ salt['pillar.get']('gnuviechadmin:amqp_host', 'mq') }}/{{ salt['pillar.get']('gnuviechadmin:queues:vhost') }}
|
2020-03-04 14:03:35 +01:00
|
|
|
result_url: redis://:{{ salt['pillar.get']('gnuviechadmin:redis_password') }}@{{ salt['pillar.get']('gnuviechadmin:redis_host') }}/0
|
2020-03-04 00:10:16 +01:00
|
|
|
- watch_in:
|
|
|
|
- service: {{ servicename }}
|
|
|
|
|
|
|
|
/etc/systemd/system/{{ servicename }}.service:
|
|
|
|
file.managed:
|
|
|
|
- user: root
|
2020-03-04 14:03:35 +01:00
|
|
|
- group: {{ app_group }}
|
2020-03-04 00:10:16 +01:00
|
|
|
- mode: 0640
|
|
|
|
- source: salt://gnuviechadmin/celery-worker.service
|
|
|
|
- template: jinja
|
|
|
|
- context:
|
|
|
|
checkout: {{ checkout }}
|
|
|
|
app_user: {{ app_user }}
|
|
|
|
appname: {{ gvaappname }}
|
|
|
|
celery_module: {{ salt['pillar.get']('gnuviechadmin:{}:celery_module'.format(gvaappname), gvaappname) }}
|
|
|
|
amqpname: {{ amqp_user }}
|
|
|
|
description: Gnuviechadmin celery worker {{ purpose|default(gvaappname) }}
|
|
|
|
- watch_in:
|
|
|
|
- service: {{ servicename }}
|
|
|
|
|
|
|
|
{{ servicename }}:
|
|
|
|
service.running:
|
|
|
|
- enable: True
|
|
|
|
- require:
|
|
|
|
{%- if update_git %}
|
|
|
|
- git: {{ gitrepo }}
|
|
|
|
{%- else %}
|
|
|
|
- file: {{ checkout }}
|
|
|
|
{%- endif %}
|
|
|
|
- file: /etc/systemd/system/{{ servicename }}.service
|
|
|
|
- watch:
|
|
|
|
- cmd: {{ gvaappname }}-requirements
|
|
|
|
{%- if update_git %}
|
|
|
|
- git: {{ gitrepo }}
|
|
|
|
{%- endif %}
|
|
|
|
{% endmacro %}
|