I have an existing Sal instance installed on a server somewhere. I've heard about this Docker thing and now I want to do something cool with it. How do I get my existing data from Sal into a Docker instance?
- Navigate to your Sal location:
cd /usr/local/sal_env/
- Activate your virtualenv:
source bin/activate
cd sal
python manage.py dumpdata --format json > saldata.json
- Copy the saldata.json file to the Docker host.
- Install Docker (as you'd expect).
docker pull postgres
- We're using Postgres simply because it's recommended.
docker pull macadmins/sal
- Obtain the setup_db.sh script from the Sal github:
curl -o https://raw.githubusercontent.com/macadmins/sal/master/setup_db.sh
chmod +x setup_db.sh
mkdir -p /usr/local/sal_data/settings/
- Obtain the settings.py from the Sal github:
curl -o /usr/local/sal_data/settings/settings.py https://raw.githubusercontent.com/macadmins/sal/master/settings.py
- If you need to make any changes, such as importing extra apps like WHDImport, edit the settings.py file now.
- If you're adding WHDImport, then just add 'whdimport' to the list of INSTALLED_APPS in settings.py.
- If you plan to add WHDImport, you'll also need to clone that in:
git clone https://github.com/nmcspadden/Sal-WHDImport.git /usr/local/sal_data/whdimport
- Start your Postgres Docker container:
docker run --name "postgres-sal" -d -v /usr/local/sal_data/db:/var/lib/postgresql/data postgres
./setup_db.sh
to execute the Postgres setup.- Copy the saldata.json file into a directory called "saldata". In this example, I created this in my home.
docker run --name "sal-loaddata" --link postgres-sal:db -e ADMIN_PASS=pass -e DB_NAME=sal -e DB_USER=saldbadmin -e DB_PASS=pass -i -t --rm -v /home/nmcspadden/saldata:/saldata -v /usr/local/sal_data/whdimport:/home/docker/sal/whdimport -v /usr/local/sal_data/settings/settings.py:/home/docker/sal/sal/settings.py macadmins/sal /bin/bash
- Several things happening in this example. First, we're linking the local "saldata" directory into the container so it can access the Sal dump at /saldata/saldata.json.
- Second, we're linking in the 'whdimport' app. If you are not using this, you can skip this entire -v argument.
- Third, we're linking in our custom 'settings.py' file. If you didn't make any modifications or add custom apps, you may not need to do this.
- Make sure your ADMIN_PASS, DB_NAME, DB_USER, and DB_PASS match what you did in setup_db.sh.
- Last, we're running an interactive shell on this container so we can load the data.
This process sets up Sal to accommodate WHDImport, which introduces extra steps. If you are not using WHDImport, after #1, skip directly to #7 on this list.
cd /home/docker/sal
echo "no" | python manage.py syncdb | xargs
python manage.py migrate
echo "TRUNCATE django_content_type CASCADE;" | python manage.py dbshell | head -3 | xargs
python manage.py schemamigration whdimport --auto
python manage.py migrate whdimport
python manage.py loaddata /saldata/saldata.json
exit
when done to remove the container.
Final step:
docker run -d --name="sal" -p 80:8000 --link postgres-sal:db -e ADMIN_PASS=pass -e DB_NAME=sal -e DB_USER=saldbadmin -e DB_PASS=pass -v /usr/local/sal_data/whdimport:/home/docker/sal/whdimport -v /usr/local/sal_data/settings/settings.py:/home/docker/sal/sal/settings.py macadmins/sal
Now you can access Sal via your web browser, using your old user account and password, with all existing data migrated.