blob: c8f2e90f01ebf743b95b063798d0f59e5280546e (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
---
- name: Container Setup
vars:
lxc_base: ansible-alpine3.11
lxc_name: healthchecks
import_playbook: ../common/tasks/lxc.yml
- name: Install Health Checks
hosts: healthchecks
vars_files:
- ../variables.yml
tasks:
- name: Ensuring group exists
group:
name: "{{ healthchecks_user }}"
state: present
- name: Creating user and making home directory
user:
system: yes
state: present
name: "{{ healthchecks_user }}"
groups: "{{ healthchecks_user }}"
home: "{{ healthchecks_home }}"
- name: Installing the required dependencies
apk:
state: present
update_cache: yes
name:
- musl-dev
- postgresql-dev
- python3-dev
- gcc
- git
- supervisor
- sudo
- uwsgi
- uwsgi-python
- block:
- name: Cloning repository
git:
repo: "{{ healthchecks_repository }}"
dest: "{{ healthchecks_home }}"
version: "{{ healthchecks_version }}"
- name: Setting up python virtual environment
shell: python3 -m venv .
args:
chdir: "{{ healthchecks_home }}"
creates: bin/activate
- name: Pip installing application
shell: |
. bin/activate
pip install -r requirements.txt
args:
chdir: "{{ healthchecks_home }}"
creates: lib/python3.8/site-packages/django
- name: Migrating database
shell: |
. bin/activate
./manage.py migrate
args:
chdir: "{{ healthchecks_home }}"
changed_when: false
register: output
- debug: var=output
- name: Setting up application assets
blockinfile:
path: "{{ healthchecks_home }}/uwsgi.ini"
block: |
[uwsgi]
http-socket = 0.0.0.0:8000
enable-threads
plugin = python
virtualenv = /opt/healthchecks
module = hc.wsgi:application
static-map = /static=static-collected
static-gzip-dir = static-collected/CACHE
hook-pre-app = exec:./manage.py collectstatic --noinput
hook-pre-app = exec:./manage.py compress --force
attach-daemon = ./manage.py sendalerts
create: yes
- name: Setting up application configuration
blockinfile:
path: "{{ healthchecks_home }}/hc/local_settings.py"
block: |
SITE_NAME = "Check"
DEBUG = False
COMPRESS_ENABLED = True
REGISTRATION_OPEN = False
SECRET = "{{ secret_key }}"
create: yes
- name: Performing maintenance
shell: |
. bin/activate
./manage.py prunepings
./manage.py prunenotifications
./manage.py pruneusers
./manage.py prunetokenbucket
./manage.py pruneflips
./manage.py compress
args:
chdir: "{{ healthchecks_home }}"
changed_when: false
register: output
- debug: var=output
become: true
become_user: "{{ healthchecks_user }}"
- name: Copying supervisord config file
copy:
src: supervisord.conf
dest: /etc/supervisord.conf
mode: '0644'
- name: Ensuring supervisord has been started and enabled
service:
name: supervisord
state: restarted
enabled: yes
changed_when: false
- name: Waiting for supervisor to become active
wait_for:
port: 9100
- name: Waiting for application to become active
wait_for:
port: 8000
- name: Testing if page exists
uri:
url: http://0.0.0.0:8000
return_content: yes
|