Baby BuddyΒΆ
Baby Buddy is an open source activity management system for your infant child. It is designed to keep track of sleep, feedings, diaper changes and tummy time β[β¦] to learn about and predict babyβs needs without (as much) guess workβ. It is written in Python and based on the popular Django-Framework.
Error
This guide seems to be broken as it requires a newer version of Python. We would be happy if you want to work on a solution and create a Pull Request. See also the related issue: https://github.com/Uberspace/lab/issues/1184
Note
For this guide you should be familiar with the basic concepts of
LicenseΒΆ
All relevant legal information can be found here
PrerequisitesΒΆ
Youβll need your MySQL credentials. Get them with my_print_defaults
:
[isabell@stardust ~]$ my_print_defaults client
--default-character-set=utf8mb4
--user=isabell
--password=MySuperSecretPassword
[isabell@stardust ~]$
Your URL needs to be setup:
[isabell@stardust ~]$ uberspace web domain list
isabell.uber.space
[isabell@stardust ~]$
You need pipenv, a package manager/virtual environment tool for Python, so install that:
[isabell@stardust ~]$ pip3 install pipenv --user
Collecting pipenv
Downloading https://files.pythonhosted.org/packages/13/b4/3ffa55f77161cff9a5220f162670f7c5eb00df52e00939e203f601b0f579/pipenv-2018.11.26-py3-none-any.whl (5.2MB)
100% |ββββββββββββββββββββββββββββββββ| 5.2MB 242kB/s
Requirement already satisfied: setuptools>=36.2.1 in /usr/lib/python3.6/site-packages (from pipenv)
Collecting virtualenv (from pipenv)
Downloading https://files.pythonhosted.org/packages/33/5d/314c760d4204f64e4a968275182b7751bd5c3249094757b39ba987dcfb5a/virtualenv-16.4.3-py2.py3-none-any.whl (2.0MB)
100% |ββββββββββββββββββββββββββββββββ| 2.0MB 614kB/s
[β¦]
Note
You have to install uwsgi
with the same python version as the app.
Babybuddy now requires at least python 3.7.
E.g. if you use 3.9, install uwsgi
with pip3.9 install uwsgi --user
Install the required uwsgi package with pip.
[isabell@stardust ~]$ pip3.6 install uwsgi --user
[isabell@stardust ~]$
After that, continue with setting it up as a service.
Create ~/etc/services.d/uwsgi.ini
with the following content:
[program:uwsgi]
command=uwsgi --master --emperor %(ENV_HOME)s/uwsgi/apps-enabled
autostart=true
autorestart=true
stderr_logfile = ~/uwsgi/err.log
stdout_logfile = ~/uwsgi/out.log
stopsignal=INT
Create needed folders and files for uwsgi:
[isabell@stardust ~]$ mkdir -p ~/uwsgi/apps-enabled
[isabell@stardust ~]$ touch ~/uwsgi/err.log
[isabell@stardust ~]$ touch ~/uwsgi/out.log
[isabell@stardust ~]$
After creating the configuration, tell supervisord to refresh its configuration and start the service:
[isabell@stardust ~]$ supervisorctl reread
SERVICE: available
[isabell@stardust ~]$ supervisorctl update
SERVICE: added process group
[isabell@stardust ~]$ supervisorctl status
SERVICE RUNNING pid 26020, uptime 0:03:14
[isabell@stardust ~]$
If itβs not in state RUNNING
, check the logs.
InstallationΒΆ
PythonΒΆ
During the installation process, you want to use Python in version 3.7+. Set an alias for that:
[isabell@stardust ~]$ alias python=python3.9
[isabell@stardust ~]$ python --version
Python 3.9.13
[isabell@stardust ~]$
DatabaseΒΆ
Baby Buddy can store its data in a MySQL database. Create one with the name <username>_babybuddy
.
[isabell@stardust ~]$ mysql -e "CREATE DATABASE ${USER}_babybuddy DEFAULT CHARACTER SET utf8 DEFAULT COLLATE utf8_general_ci;"
[isabell@stardust ~]$
DownloadΒΆ
Create two folders, one for the source code and one for the applicationβs data.
[isabell@stardust ~]$ mkdir -p ~/babybuddy/public ~/babybuddy/data/media
[isabell@stardust ~]$
Clone the Baby Buddy source code from Github into the first folder.
[isabell@stardust ~]$ git clone https://github.com/cdubz/babybuddy.git ~/babybuddy/public
[...]
remote: Total 4593 (delta 27), reused 80 (delta 19), pack-reused 4477
Receiving objects: 100% (4593/4593), 8.15 MiB | 3.33 MiB/s, done.
Resolving deltas: 100% (2734/2734), done.
[isabell@stardust ~]$
DependenciesΒΆ
Install all the requirements.
[isabell@stardust ~]$ cd ~/babybuddy/public/
[isabell@stardust public]$ pipenv install --python python3.9
[...]
π ββββββββββββββββββββββββββββββββ 39/39 β 00:00:54
To activate this project's virtualenv, run pipenv shell.
Alternatively, run a command inside the virtualenv with pipenv run.
[isabell@stardust ~/babybuddy/public]$
ConfigurationΒΆ
Copy the template configuration file and adapt it based on the following example.
[isabell@stardust ~]$ cp ~/babybuddy/public/babybuddy/settings/production.example.py ~/babybuddy/public/babybuddy/settings/production.py
[isabell@stardust ~]$
Warning
Replace <secretkey>
with a random sequence of characters!
Use this snippet to generate a random string to use as secret key:
[isabell@stardust ~] pwgen 32 1
extremerandom
[isabell@stardust ~]$
Warning
Replace <host>
with your host!
Warning
Replace <username>
with your username!
Warning
Replace <databasepassword>
with your database password!
from .base import *
# Production settings
# See babybuddy.settings.base for additional settings information.
SECRET_KEY = '<secretkey>'
ALLOWED_HOSTS = ['<host>']
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': '<username>_babybuddy',
'USER': '<username>',
'PASSWORD': '<databasepassword>',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
# Static files
MEDIA_ROOT = os.path.join(BASE_DIR, '../data/media')
To work correctly with the Uberspace Proxy, you need to add this option to the end of the file:
USE_X_FORWARDED_HOST = True
In our example, the file ~/babybuddy/public/babybuddy/settings/production.py
should look like this:
from .base import *
# Production settings
# See babybuddy.settings.base for additional settings information.
SECRET_KEY = 'MyRandomSecretKey'
ALLOWED_HOSTS = ['isabell.uber.space']
# Database
# https://docs.djangoproject.com/en/1.11/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'isabell_babybuddy',
'USER': 'isabell',
'PASSWORD': 'MySuperSecretPassword',
'HOST': '127.0.0.1',
'PORT': '3306',
}
}
# Static files
MEDIA_ROOT = os.path.join(BASE_DIR, '../data/media')
USE_X_FORWARDED_HOST = True
Database SchemaΒΆ
Enter the virtual environment, initialize the database tables and exit the virtual environment again:
[isabell@stardust ~]$ cd ~/babybuddy/public/
[isabell@stardust ~/babybuddy/public]$ pipenv shell
Launching subshell in virtual environmentβ¦
. /home/isabell/.local/share/virtualenvs/public-xxxxxx/bin/activate
[isabell@stardust ~/babybuddy/public]$ export DJANGO_SETTINGS_MODULE=babybuddy.settings.production
[isabell@stardust ~/babybuddy/public]$ python manage.py migrate
[isabell@stardust ~/babybuddy/public]$ python manage.py createcachetable
[...]
[isabell@stardust ~/babybuddy/public]$ exit && cd
[isabell@stardust ~]$
ConfigurationΒΆ
Configure web serverΒΆ
Note
babybuddy is running on port 8000.
To make the application accessible from the outside, configure a web backend:
[isabell@stardust ~]$ uberspace web backend set / --http --port <port>
Set backend for / to port <port>; please make sure something is listening!
You can always check the status of your backend using "uberspace web backend list".
[isabell@stardust ~]$
Setup serviceΒΆ
To deploy your application with uwsgi, create a file at ~/uwsgi/apps-enabled/babybuddy.ini
with the following content:
Warning
Replace <username>
with your username! (4 times)
Note
Find the location of the pipenv virtual environment for the virtualenv
parameter with the following command:
[isabell@stardust ~]$ cd ~/babybuddy/public/ && pipenv --venv
/home/isabell/.local/share/virtualenvs/public-xxxxxx
[uwsgi]
project = babybuddy
base_dir = $(HOME)/babybuddy
virtualenv = $(HOME)/.local/share/virtualenvs/public-xxxxxx
chdir = %(base_dir)/public
module = %(project).wsgi:application
env = DJANGO_SETTINGS_MODULE=%(project).settings.production
master = True
vacuum = True
http = 0.0.0.0:8000
wsgi-file = %(base_dir)/public/babybuddy/wsgi.py
touch-reload = %(wsgi-file)
app = wsgi
plugin = python
uid = $(USER)
gid = $(USER)
Finishing installationΒΆ
Point your browser to https://isabell.uber.space and log in with the default credentials admin
/admin
.
Warning
Change the default credentials as soon as possible! Otherwise anyone knowing the URL of your instance can login to download, edit or delete your data.
Written by: Christian <christian@kuntzsch.me>