It's a memo, so it's rough. I was able to do something like this
I'm developing multiple Django apps and deploying them using Fabric and Cuisine. There are variables that differ depending on the description and environment (development, staging, production) in settings.py that I do not want to put on github, so I want to reflect them from the local file to the remote server file
project_root/settings/production.py
#Common setting items are project in all environments_root/settings/common.I have it in common with py.
from sample_app.settings.common import *
SECRET_KEY = '{{ secret_key }}'
DEBUG = False
ALLOWED_HOSTS = ['127.0.0.1']
DATABASES = {
'default': {
'ENGINE': '{{ databases.default.engine }}',
'NAME': '{{ databases.default.name }}',
'USER': '{{ databases.default.user }}',
'PASSWORD': '{{ databases.default.password }}',
'HOST': '{{ databases.default.host }}',
'PORT': {{ databases.default.port }},
}
}
The value is appropriate
secrets.yml
django:
settings:
production:
secret_key: ''
databases:
default:
engine: django.db.backends.mysql
name: sample_app
user: root
password: ''
host: 127.0.0.1
port: 3306
Rather than uploading, it is more correct to say that you are creating a file with the contents specified remotely.
from jinja2 import Environment, FileSystemLoader
from cuisine import file_write
secrets = yaml.load(file('secrets.yml'))
local_template_name = local_template_path.split('/')[-1]
local_template_dir = local_template_path.replace(local_template_name, '')
#The following 3 lines are the main processing. Get the string with the variable embedded in the template and create a file containing it on the remote server.
jinja2_env = Environment(loader=FileSystemLoader(local_template_dir))
content = jinja2_env.get_template(local_template_name).render(secrets['django']['settings']['production'])
file_write(remote_path, content.encode('utf-8'))
https://gist.github.com/wrunk/1317933
Recommended Posts