only add superuser if no superuser yet, serve static content with whitenoise
This commit is contained in:
parent
a52059ae94
commit
bf03e92f04
|
@ -8,6 +8,7 @@
|
|||
- 'tar'
|
||||
- 'python3-psycopg2'
|
||||
- 'python3-gunicorn'
|
||||
- 'python3-whitenoise'
|
||||
state: 'present'
|
||||
|
||||
- name: 'Create im user'
|
||||
|
@ -19,13 +20,17 @@
|
|||
|
||||
- name: 'download latest im stable'
|
||||
get_url:
|
||||
url: https://gitea.caret.be/jens/im/archive/main.tar.gz
|
||||
dest: "{{im_home}}/im-latest.tar.gz"
|
||||
owner: im
|
||||
group: im
|
||||
mode: '0400'
|
||||
force: true
|
||||
|
||||
- name: 'remove previous install stable'
|
||||
file:
|
||||
dest: "{{im_home}}/im"
|
||||
state: absent
|
||||
|
||||
- name: 'unarchive latest im stable'
|
||||
unarchive:
|
||||
src: "{{im_home}}/im-latest.tar.gz"
|
||||
|
@ -60,11 +65,24 @@
|
|||
django_manage:
|
||||
command: migrate
|
||||
app_path: "{{im_home}}/im"
|
||||
become: true
|
||||
become_user: "{{im_user}}"
|
||||
|
||||
- name: 'create superjuser for django im app'
|
||||
- name: check if django superuser exists
|
||||
django_manage:
|
||||
command: 'shell -c "from django.contrib.auth.models import User; print(User.objects.filter(is_superuser=True).exists())"'
|
||||
app_path: "{{im_home}}/im"
|
||||
register: superuser_exists
|
||||
become: true
|
||||
become_user: "{{im_user}}"
|
||||
|
||||
- name: "create superjuser for django im app if it doesn't exist"
|
||||
django_manage:
|
||||
command: "createsuperuser --noinput --username=admin --email={{im_admin_email}}"
|
||||
app_path: "{{im_home}}/im"
|
||||
become: true
|
||||
become_user: "{{im_user}}"
|
||||
when: superuser_exists.out.find("True") == -1
|
||||
|
||||
- name: 'collect static content'
|
||||
django_manage:
|
||||
|
|
|
@ -44,6 +44,7 @@ INSTALLED_APPS = [
|
|||
|
||||
MIDDLEWARE = [
|
||||
'django.middleware.security.SecurityMiddleware',
|
||||
'whitenoise.middleware.WhiteNoiseMiddleware',
|
||||
'django.contrib.sessions.middleware.SessionMiddleware',
|
||||
'django.middleware.common.CommonMiddleware',
|
||||
'django.middleware.csrf.CsrfViewMiddleware',
|
||||
|
@ -123,5 +124,8 @@ USE_TZ = True
|
|||
|
||||
# Static files (CSS, JavaScript, Images)
|
||||
# https://docs.djangoproject.com/en/2.1/howto/static-files/
|
||||
# http://whitenoise.evans.io/en/stable/django.html
|
||||
|
||||
STATIC_URL = '/static/'
|
||||
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
||||
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
|
||||
|
|
|
@ -12,3 +12,4 @@ im_db_password: ''
|
|||
im_workers: 4
|
||||
im_http_listen: 'localhost'
|
||||
im_http_port: 80
|
||||
im_admin_email: root@localhost
|
||||
|
|
Loading…
Reference in New Issue