Installation/Dokku
Running Diaspora in your own PaaS with Dokku
Introduction
This guide outlines the steps to run your own Platform as a Service (PaaS) using Dokku and deploy diaspora to it. To keep this guide brief and to make sure you read the most up to date instructions, for some steps we simply link to instructions elsewhere. This is somewhat experimental. We simply describe steps that worked, there may be other ways to achieve the same.
Requirements
- A linux server running ubuntu 16.04 with at least 1GB memory
- A local development machine.
- (Optional) a domain name.
Let's say your domain name is yourdomain.tld
, if you don't have a domain name just replace it with the IP address of the server.
After completing this guide we will have Dokku on the linux server. This allows us to simply git push changes made on Diaspora to our server. Then Dokku will take care of the rest. It receives the changes builds and deploys the new version.
We assume you have setup and secured your linux server and have root access to it via ssh.
Install Dokku
Install Dokku following the their instructions. If you have a domain name, dokku can setup "Virtual Hosts" for each application you deploy. This means you can visit diaspora at diaspora.yourdomain.tld
and if you deploy another app called "myapp" you can visit it at myapp.yourdomain.tld
. Otherwise the address of each app will be <ip address>:<app port nr>
. You can also get the domain name later and enable the Virtual Hosts later.
After dokku is installed run
# on the server dokku apps:create diaspora
Local copy with Dokku as remote
On your local machine (not the server) make sure you have a clone of diaspora
git clone git@github.com:diaspora/diaspora.git
or clone it from your own fork. Create a branch from which we will push to dokku, and add dokku as a remote.
git checkout -b dokku_branch git remote add dokku dokku@yourdomain.tld:diaspora
The local branch can have any name you want. Here we name it dokku_branch
to distinguish it from the remote branch dokku
that we will create later. They can both be called dokku, that is fine.
Dokku plugins
postgres
#install postgresql. On the server run dokku plugin:install https://github.com/dokku/dokku-postgres.git # create a postgres database for diaspora dokku postgres:create diaspora-db dokku postgres:link diaspora-db diaspora
The postgres:link command creates an environment variable DATABASE_URL and makes that available to the diaspora app. Then diaspora can use this url within its database.yml configuration.
letsencrypt
Do this last. You must have a deployed app running, before you can secure it with the letsencrypt plugin.
Configuration
Diaspora is configured with two files. database.yml and diaspora.yml. In git these two files are ignored and so they won't be pushed when we push to dokku.
Open the .gitignore file and remove these two lines
config/diaspora.yml config/database.yml
Never write anything secret in these files. Only use environment variables. Open config/database.yml.example. Edit the part near the bottom, change the production section to
production: <<: *combined database: diaspora-db url: <%= ENV['DATABASE_URL'] %>
then save the file as config/database.yml. Copy config/diaspora.yml.example and save it as config/diaspora.yml, but don't edit this file.
Open the Gemfile and add this line as the second line:
ruby "2.4.1"
Then run
echo 2.4.1 > .ruby-version bin/bundle install
Commit all changes on your dokku_branch
.
git add . git commit
Environment Variables
The rest of the configuration can be done on the server. Every value in diaspora.yml can be set with an environment variable as described in the file itself.
Here we set a few as example
dokku config:set --no-restart diaspora SETTINGS_POD_NAME='MyPod' ENVIRONMENT_ASSETS_SERVE=true ENVIRONMENT_URL=yourdomain.tld RAILS_SERVE_STATIC_FILES=true SERVER_RAILS_ENVIRONMENT=production SERVER_EMBED_SIDEKIQ_WORKER=true ENVIRONMENT_CERTIFICATE_AUTHORITIES=/etc/ssl/certs/ca-certificates.crt
These variables are not in diaspora.yml, but we set them as well
dokku config:set --no-restart diaspora RAILS_ENV=production BUNDLE_WITH=postgresql PORT=5000 BUNDLE_BUILD__SIGAR="--with-cppflags='-fgnu89-inline'" BUNDLE_WITH="production:postgresql"
Push and deploy
Now we can push and deploy with
git push dokku dokku_branch:master
This will create the master branch in the remote dokku repository. Note the name of the remote branch must be master
.
The first push and deploy will take a long time. Once it's done the app starts, but the database is not created yet. On the server run
# on the server dokku run diaspora "env RAILS_ENV=production bin/rake db:create db:migrate" dokku ps:restart diaspora