Skip to content
Snippets Groups Projects
Commit c3588e40 authored by jurgenhaas's avatar jurgenhaas
Browse files

Finalize role based on docker images and behind an apache reverse proxy

parent 4bf37535
No related branches found
No related tags found
No related merge requests found
Showing
with 205 additions and 188 deletions
---
alerta_ui_version: 7.0.1
--- ---
- name: Restart uwsgi - name: Re-create Docker Network and Containers
service: docker_compose:
name: uwsgi project_src: /opt/alerta
state: restarted build: yes
- name: Re-create the alerta ui container
docker_container:
name: alerta-beta
image: alerta/alerta-beta
state: started
recreate: yes
restart_policy: always
published_ports:
- 8999:80
volumes:
- /var/www/alerta/config.json:/usr/share/nginx/html/config.json
...@@ -12,5 +12,6 @@ galaxy_info: ...@@ -12,5 +12,6 @@ galaxy_info:
- 16 - 16
- 18 - 18
dependencies: dependencies:
- { role: mongodb } - role: apache
- { role: nginx } - role: docker
- role: letsencrypt
--- ---
# file: roles/alerta/tasks/alerta.yml # file: roles/alerta/tasks/alerta.yml
- name: Ensure packages - name: Ensure directory
apt:
pkg: '{{ packages }}'
state: present
vars:
packages:
- python-pip
- python-dev
- python3-dev
- libpq-dev
- name: Ensure PIP packages
pip:
name: '{{ packages }}'
state: present
vars:
packages:
- alerta-server
- alerta
- uwsgi
- python-gitlab
- name: Remove directories for web UI
file:
path: '{{ item }}'
state: absent
with_items:
- /var/www/alerta
- /tmp/angular-alerta-webui-master
- name: Ensure directory for web UI
file: file:
path: '{{ item }}' path: '{{ item }}'
state: absent state: directory
with_items: with_items:
- /var/www/alerta - /opt/alerta/api/plugins
- /opt/alerta/webui
#- name: Download and extract web UI
# unarchive:
# src: 'https://github.com/alerta/angular-alerta-webui/archive/v{{ alerta_ui_version }}.zip'
# dest: /tmp
# remote_src: yes
#- name: Move new web UI
# command: mv /tmp/angular-alerta-webui-{{ alerta_ui_version }}/app /var/www/alerta
# args:
# creates: /var/www/alerta
# removes: /tmp/angular-alerta-webui-{{ alerta_ui_version }}/app
- name: Copy wsgi.py
template:
src: wsgi.py
dest: /var/www/alerta/wsgi.py
- name: Copy uwsgi.ini
template:
src: uwsgi.ini
dest: /etc/uwsgi.ini
- name: Copy uwsgi.service
template:
src: uwsgi.service
dest: /etc/systemd/system/uwsgi.service
- name: Prepare uwsgi for autostart
systemd:
name: uwsgi
state: restarted
enabled: yes
daemon_reload: yes
- name: Copy nginx default config
template:
src: nginx.default
dest: /etc/nginx/sites-available/default
notify:
- Restart nginx
- name: Copy config.js - name: Copy Alerta config files
template: template:
src: '{{ item }}' src: '{{ item }}'
dest: /var/www/alerta/{{ item }} dest: /opt/alerta/{{ item }}
with_items: with_items:
- config.js - docker-compose.yml
- config.json notify:
- Re-create Docker Network and Containers
- name: Copy alertad.conf - name: Copy API config files
template: template:
src: alertad.conf src: api/{{ item }}
dest: /etc/alertad.conf dest: /opt/alerta/api/{{ item }}
with_items:
- alerta.conf
- alertad.conf
- Dockerfile
notify: notify:
- Restart uwsgi - Re-create Docker Network and Containers
- name: Configure root CLI - name: Copy Web UI config files
template: template:
src: alerta.conf src: webui/{{ item }}
dest: /root/.alerta.conf dest: /opt/alerta/webui/{{ item }}
- name: Configure crontabs
cron:
name: '{{ item.name }}'
minute: '{{ item.minute }}'
job: '{{ item.job }} >/dev/null 2>&1'
disabled: '{{ crons_disabled|default(false) }}'
with_items: with_items:
- name: Heartbeats to Alert - .env
minute: '*/3' - config.json
job: /usr/local/bin/alerta heartbeats --alert - nginx.conf
- name: Alerta Housekeeping - Dockerfile
minute: 0 notify:
job: /usr/local/bin/alerta housekeeping - Re-create Docker Network and Containers
tags:
- cron
- name: Copy plugins - name: Copy plugins
template: template:
src: '{{ item }}/plugin.py' src: plugins/{{ item }}/plugin.py
dest: /tmp/alerta_{{ item }}.py dest: /opt/alerta/api/plugins/alerta_{{ item }}.py
with_items: with_items:
- elastalert - elastalert
- gitlab - gitlab
tags: notify:
- plugin - Re-create Docker Network and Containers
- name: Copy plugin setups - name: Copy plugin setups
template: template:
src: '{{ item }}/setup.py' src: plugins/{{ item }}/setup.py
dest: /tmp/setup_alerta_{{ item }}.py dest: /opt/alerta/api/plugins/setup_alerta_{{ item }}.py
with_items:
- elastalert
- gitlab
tags:
- plugin
- name: Install plugins
command: python3 setup_alerta_{{ item }}.py install
args:
chdir: /tmp
with_items: with_items:
- elastalert - elastalert
- gitlab - gitlab
tags: notify:
- plugin - Re-create Docker Network and Containers
- name: Copy favicon.ico
copy:
src: '{{ inventory_dir }}/files/favicon.ico'
dest: /var/www/alerta/favicon.ico
- name: Pull docker image - name: Pull docker image
docker_image: docker_image:
name: alerta/alerta-beta name: "{{ item }}"
source: pull source: pull
force_source: yes force_source: yes
with_items:
- alerta/alerta-web
- node:lts-alpine
- nginx:stable-alpine
- postgres
notify: notify:
- Re-create the alerta ui container - Re-create Docker Network and Containers
tags:
- ui
---
# file: roles/alerta/tasks/apache.yml
- name: Set facts
set_fact:
apacheUser: www-data
- name: Apache Modules
apache2_module:
state: present
name: '{{ item }}'
with_items:
- proxy
- proxy_http
notify:
- Restart Apache
- name: Apache Configuration File
template:
src: vhost.conf
dest: /etc/apache2/sites-available/alerta{{ apache_conf_ext }}
owner: root
group: root
mode: 0664
notify:
- Restart Apache
- name: Apache enable site
command: a2ensite alerta
args:
creates: /etc/apache2/sites-enabled/alerta{{ apache_conf_ext }}
notify:
- Restart Apache
...@@ -12,6 +12,19 @@ ...@@ -12,6 +12,19 @@
- always - always
- block: - block:
- name: Install Certs
include_tasks: ../../letsencrypt/tasks/cert.yml
with_items: '{{ alerta_settings|default([]) }}'
loop_control:
loop_var: domain
when: domain.protocol|default("https") == "https" and domain.letsencrypt|default(true)
when: (not excluded_roles or "letsencrypt" not in excluded_roles) and groups.proxyserver is not defined
- block:
- name: Import apache
import_tasks: apache.yml
- name: Import alerta - name: Import alerta
import_tasks: alerta.yml import_tasks: alerta.yml
......
FROM alerta/alerta-web
USER root
COPY ./plugins/*.py /tmp/plugins/
RUN /venv/bin/pip install python-gitlab && \
/venv/bin/python3 /tmp/plugins/setup_alerta_gitlab.py install && \
/venv/bin/python3 /tmp/plugins/setup_alerta_elastalert.py install && \
echo "Done"
USER 1001
File moved
BASE_URL='https://{{ alerta_domain }}/api' BASE_URL='https://{{ alerta_domain }}/api'
USE_PROXYFIX=True
AUTH_REQUIRED=True AUTH_REQUIRED=True
AUTH_PROVIDER='gitlab' AUTH_PROVIDER='gitlab'
SECRET_KEY='{{ alerta_secret_key }}' SECRET_KEY='{{ alerta_secret_key }}'
...@@ -12,7 +13,7 @@ OAUTH2_CLIENT_SECRET='{{ alerta_gitlab.client_secret }}' ...@@ -12,7 +13,7 @@ OAUTH2_CLIENT_SECRET='{{ alerta_gitlab.client_secret }}'
ALLOWED_GITLAB_GROUPS=['{{ alerta_environments|join("','") }}'] ALLOWED_GITLAB_GROUPS=['{{ alerta_environments|join("','") }}']
# Plugins # Plugins
PLUGINS=['reject','gitlab','elastalert'] PLUGINS=['reject','blackout','normalise','enhance','gitlab','elastalert']
ORIGIN_BLACKLIST=[] ORIGIN_BLACKLIST=[]
ALLOWED_ENVIRONMENTS=['{{ alerta_environments|join("','") }}'] ALLOWED_ENVIRONMENTS=['{{ alerta_environments|join("','") }}']
ACTIONS = ['createIssue'] ACTIONS = ['createIssue']
version: '2.1' version: '3.7'
services: services:
web: webui:
image: alerta/alerta-web build:
context: webui
ports:
- "8092:80"
depends_on:
- api
networks:
net:
aliases:
- web
restart: always
api:
build:
context: api
ports: ports:
- "8091:8080" - "8091:8080"
depends_on: depends_on:
- db - db
volumes: volumes:
- ./config/alerta.conf:/app/alerta.conf - ./api/alerta.conf:/app/alerta.conf
- ./config/alertad.conf:/app/alertad.conf - ./api/alertad.conf:/app/alertad.conf
- ./config/config.json:/web/config.json
- ./plugins/gitlab.py:/venv/lib/python3.7/site-packages/alerta/plugins/gitlab.py
environment: environment:
- DATABASE_URL=postgres://postgres:postgres@db:5432/monitoring - DATABASE_URL=postgres://postgres:postgres@db:5432/monitoring
- BASE_URL=https://alerta.lakedrops.com/api - BASE_URL=https://{{ alerta_domain }}/api
- ALERTA_CONF_FILE=/app/alerta.conf - ALERTA_CONF_FILE=/app/alerta.conf
networks:
net:
aliases:
- api
restart: always restart: always
db: db:
image: postgres image: postgres
...@@ -24,4 +39,11 @@ services: ...@@ -24,4 +39,11 @@ services:
POSTGRES_DB: monitoring POSTGRES_DB: monitoring
POSTGRES_USER: postgres POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres POSTGRES_PASSWORD: postgres
networks:
net:
aliases:
- db
restart: always restart: always
networks:
net: {}
...@@ -9,7 +9,7 @@ setup( ...@@ -9,7 +9,7 @@ setup(
description='LakeDrops Alerta plugin for incoming alerts from Elastalert', description='LakeDrops Alerta plugin for incoming alerts from Elastalert',
url='https://gitlab.lakedrops.com/ansible-roles/alerta', url='https://gitlab.lakedrops.com/ansible-roles/alerta',
license='MIT', license='MIT',
author='Jürgen Haas', author='Juergen Haas',
author_email='juergen.haas@lakedrops.com', author_email='juergen.haas@lakedrops.com',
packages=find_packages(), packages=find_packages(),
py_modules=['alerta_elastalert'], py_modules=['alerta_elastalert'],
......
File moved
...@@ -9,7 +9,7 @@ setup( ...@@ -9,7 +9,7 @@ setup(
description='LakeDrops Alerta plugin for GitLab Issues', description='LakeDrops Alerta plugin for GitLab Issues',
url='https://gitlab.lakedrops.com/ansible-roles/alerta', url='https://gitlab.lakedrops.com/ansible-roles/alerta',
license='MIT', license='MIT',
author='Jürgen Haas', author='Juergen Haas',
author_email='juergen.haas@lakedrops.com', author_email='juergen.haas@lakedrops.com',
packages=find_packages(), packages=find_packages(),
py_modules=['alerta_gitlab'], py_modules=['alerta_gitlab'],
......
...@@ -2,59 +2,48 @@ ...@@ -2,59 +2,48 @@
Include /etc/apache2/conf-available/global-redirect.conf Include /etc/apache2/conf-available/global-redirect.conf
ServerAdmin webmaster@paragon-es.de ServerAdmin webmaster@paragon-es.de
ServerName alerta.lakedrops.com ServerName {{ alerta_domain }}
Include /etc/apache2/conf-available/redirect-ssl.conf Include /etc/apache2/conf-available/redirect-ssl.conf
Include /etc/apache2/conf-available/letsencrypt-redirect.conf Include /etc/apache2/conf-available/letsencrypt-redirect.conf
ErrorLog ${APACHE_LOG_DIR}/alerta.lakedrops.com-error.log ErrorLog ${APACHE_LOG_DIR}/{{ alerta_domain }}-error.log
LogLevel warn LogLevel warn
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog ${APACHE_LOG_DIR}/alerta.lakedrops.com-access.log combined env=!forwarded CustomLog ${APACHE_LOG_DIR}/{{ alerta_domain }}-access.log combined env=!forwarded
CustomLog ${APACHE_LOG_DIR}/alerta.lakedrops.com-access.log proxy env=forwarded CustomLog ${APACHE_LOG_DIR}/{{ alerta_domain }}-access.log proxy env=forwarded
</VirtualHost> </VirtualHost>
<VirtualHost *:443> <VirtualHost *:443>
Include /etc/apache2/conf-available/global-redirect.conf Include /etc/apache2/conf-available/global-redirect.conf
ServerAdmin webmaster@paragon-es.de ServerAdmin webmaster@paragon-es.de
ServerName alerta.lakedrops.com ServerName {{ alerta_domain }}
Header always add Strict-Transport-Security "max-age=15768000; includeSubDomains; preload" Header always add Strict-Transport-Security "max-age=15768000; includeSubDomains; preload"
FileETag None
Header unset ETag
Header set Cache-Control "max-age=0, no-cache, no-store, must-revalidate"
Header set Pragma "no-cache"
Header set Expires "Wed, 11 Jan 1984 05:00:00 GMT"
RequestHeader set Host alerta.lakedrops.com
RequestHeader set X_FORWARDED_PROTO 'https'
RequestHeader set X-Forwarded-Ssl on
RequestHeader set X-Forwarded-For alerta.lakedrops.com
DocumentRoot /var/www/html DocumentRoot /var/www/html
<Proxy *> <Proxy *>
Include /etc/apache2/conf-available/global-deny.conf Include /etc/apache2/conf-available/global-deny.conf
</Proxy> </Proxy>
RewriteEngine on
RewriteCond ${HTTP:Upgrade} websocket [NC]
RewriteCond ${HTTP:Connection} upgrade [NC]
RewriteRule .* "wss:/localhost:8091/$1" [P,L]
ProxyPass / http://localhost:8091/
ProxyPassReverse / http://localhost:8091/
ProxyPreserveHost On ProxyPreserveHost On
ProxyRequests Off
ProxyPass /web http://127.0.0.1:8092/
ProxyPassReverse /web http://127.0.0.1:8092/
ProxyPass /api http://127.0.0.1:8091/api
ProxyPassReverse /api http://127.0.0.1:8091/api
ErrorLog ${APACHE_LOG_DIR}/alerta.lakedrops.com-error.log ErrorLog ${APACHE_LOG_DIR}/{{ alerta_domain }}-error.log
LogLevel warn LogLevel warn
LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy LogFormat "%{X-Forwarded-For}i %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" proxy
SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded SetEnvIf X-Forwarded-For "^.*\..*\..*\..*" forwarded
CustomLog ${APACHE_LOG_DIR}/alerta.lakedrops.com-access.log combined env=!forwarded CustomLog ${APACHE_LOG_DIR}/{{ alerta_domain }}-access.log combined env=!forwarded
CustomLog ${APACHE_LOG_DIR}/alerta.lakedrops.com-access.log proxy env=forwarded CustomLog ${APACHE_LOG_DIR}/{{ alerta_domain }}-access.log proxy env=forwarded
<IfModule mod_expires.c> <IfModule mod_expires.c>
ExpiresActive On ExpiresActive On
...@@ -72,7 +61,7 @@ ...@@ -72,7 +61,7 @@
SSLEngine on SSLEngine on
Include /etc/letsencrypt/options-ssl-apache.conf Include /etc/letsencrypt/options-ssl-apache.conf
SSLCertificateFile /etc/letsencrypt/live/alerta.lakedrops.com/cert.pem SSLCertificateFile /etc/letsencrypt/live/{{ alerta_domain }}/cert.pem
SSLCertificateKeyFile /etc/letsencrypt/live/alerta.lakedrops.com/privkey.pem SSLCertificateKeyFile /etc/letsencrypt/live/{{ alerta_domain }}/privkey.pem
SSLCertificateChainFile /etc/letsencrypt/live/alerta.lakedrops.com/chain.pem SSLCertificateChainFile /etc/letsencrypt/live/{{ alerta_domain }}/chain.pem
</VirtualHost> </VirtualHost>
BASE_URL=/web
# build stage
FROM node:lts-alpine as build-stage
RUN apk add --no-cache git
WORKDIR /app
ADD https://github.com/alerta/alerta-webui/archive/master.tar.gz /tmp/webui.tar.gz
RUN tar zxvf /tmp/webui.tar.gz -C /app --strip-components=1
RUN npm install
COPY .env .
RUN npm run build
# production stage
FROM nginx:stable-alpine as production-stage
COPY --from=build-stage /app/dist /app
COPY config.json /app/config.json
COPY nginx.conf /etc/nginx/nginx.conf
EXPOSE 80
CMD ["nginx", "-g", "daemon off;"]
File moved
user nginx;
worker_processes 1;
error_log /var/log/nginx/error.log warn;
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;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root /app;
index index.html;
try_files $uri $uri/ /index.html;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment