-
-
Notifications
You must be signed in to change notification settings - Fork 299
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Programatically changing Base URL #971
Comments
Well, I have solved this by creating a template on ansible called from __future__ import unicode_literals
from django.db import migrations
def update_sites(apps, schema_editor):
"""Populate the sites model"""
Site = apps.get_model('sites', 'Site')
# Update Kiwi base url
site = Site.objects.get(id=1)
site.domain = '{{ kiwi_base_url }}'
site.name = '{{ kiwi_name }}'
site.save()
class Migration(migrations.Migration):
dependencies = [
('core', '0001_squashed'),
]
operations = [
migrations.RunPython(update_sites)
] So I template that to the server and mount it on the docker-compose on the At first I went for an sql approach but the hassle on running the client, passing password, etc, made the migration approach a better way. |
@nicholasamorim this is still a valid request. We should think a bit about it but it can be done. Do you mind sending your ansible playbook as a pull request and we can take things from there? |
Okay, will do that later as the playbook is idempotent - so it automates from zero to the point that Kiwi is running. So I'm going to merge all tasks into one playbook as I use separate playbooks to ensure python, docker and docker-compose are always present. I'll open a PR soon. |
I've simplified several playbooks into one to paste it in here. It depends on the roles Playbook steps:
#### Python
- name: Setting up Python
hosts: kiwi
become: yes
roles:
- role: ndench.python
post_tasks:
- name: Checking if /usr/bin/python symlink exists
stat:
path: /usr/bin/python
register: python_symlink
# This is linking the distro default Python3 - not 3.7 (this might change)
- name: Pointing /usr/bin/python to python3
file:
src: /usr/bin/python3
dest: /usr/bin/python
state: link
when: python_symlink.stat.exists == False
- name: Installing pip
apt:
name: python3-pip
state: present
#### Docker
- name: Setting up Docker
hosts: kiwi
become: yes
vars:
docker_install_compose: true
pip_install_packages:
- name: docker
- name: docker-compose
pre_tasks:
- name: Ensuring dependencies for docker-compose are present
apt:
name:
- libffi-dev
- libssl-dev
state: present
roles:
- geerlingguy.pip
- geerlingguy.docker
### Kiwi
- name: Setting Kiwi
hosts: kiwi
become: yes
vars:
kiwi_folder: /opt/kiwi
kiwi_base_url: "some-kiwi-url"
tasks:
- name: Ensuring kiwi folder exists
file:
path: "{{ kiwi_folder }}"
state: directory
- name: Copying configuration files
copy:
src: "files/kiwi/{{ item }}"
dest: "{{ kiwi_folder }}"
loop:
- docker-compose.yaml
- local_settings.py
- name: Copying base_url migration
template:
src: templates/kiwi/0002_update_sites.py.j2
dest: "{{ kiwi_folder }}/0002_update_sites.py"
- name: Bringing stack up!
docker_compose:
project_src: "{{ kiwi_folder }}"
state: present
restarted: yes
- name: Wait for port 80 to become open on the host
wait_for:
port: 80
- name: Executing migration
shell: "docker exec -it kiwi_web /Kiwi/manage.py migrate" Custom migration from __future__ import unicode_literals
from django.db import migrations
def update_sites(apps, schema_editor):
"""Populate the sites model"""
Site = apps.get_model('sites', 'Site')
# Update Kiwi base url
site = Site.objects.get(id=1)
site.domain = '{{ kiwi_base_url }}'
site.name = 'Some Name for Kiwi TCMS Site'
site.save()
class Migration(migrations.Migration):
dependencies = [
('core', '0001_squashed'),
]
operations = [
migrations.RunPython(update_sites)
] |
@nicholasamorim thanks for sharing code. Can you make this into a pull request so we can start discussing changes and code review ? |
@nicholasamorim ping. Could you send the ansible playbook as a pull request so we can attribute it properly ? |
Hi, I've automated installation of Kiwi in an Ansible playbook.
However, the fact that I need to login and change the base url manually is a let down. Is there any way to change the Base URL programatically?
It's been a long time I don't use Django so should I just update
django_site
using a SQL command or should I write a migration for it?The text was updated successfully, but these errors were encountered: