Skip to main content

Eslöv Decidim

Table of Contents​

  1. New Project Setup
  2. Returning to the Project
  3. Performing Upgrades
  4. Copying Production to Staging
  5. Useful Commands and Resources

1. New Project Setup​

Server Setup​

To set up the server, run the following Ansible playbooks:

ansible-playbook server.yml -e env=eslov-decidim
ansible-playbook server-nodejs.yml -e env=eslov-decidim
ansible-playbook server-decidim.yml -e env=eslov-decidim

Manual Installation​

Install rbenv​

sudo -u web -s
git clone https://github.com/rbenv/rbenv.git ~/.rbenv
echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrc
echo 'eval "$(rbenv init -)"' >> ~/.bashrc
source ~/.bashrc
git clone https://github.com/rbenv/ruby-build.git ~/.rbenv/plugins/ruby-build
rbenv install 2.7.5
rbenv global 2.7.5
echo "gem: --no-document" > ~/.gemrc

Install Gems​

sudo -u web -s
gem install bundler

Install PostgreSQL and Set Up the Application​

cd /srv/www/dialog.eslov.se/current
bundle config set --local path 'vendor/bundle'
bundle install
rake secret
exit
sudo -u postgres psql -c "CREATE USER decidim_app WITH SUPERUSER CREATEDB NOCREATEROLE PASSWORD '<PASSWORD>'"
sudo npm install --global yarn
sudo -u web -s
nano /srv/www/dialog.eslov.se/current/config/application.yml

Add to the configuration file:

DATABASE_URL: postgres://decidim_app:PASSWORD@localhost/decidim_prod
SECRET_KEY_BASE: <GENERATED>

Then continue with:

cd /srv/www/dialog.eslov.se/current
bin/rails db:create RAILS_ENV=production
yarn
bin/rails assets:precompile db:migrate RAILS_ENV=production

Initial Configuration​

Add Super User​

bin/rails console -e production

In the console:

email = "dev@whitespace.se"
password = "<PASSWORD>"
user = Decidim::System::Admin.new(email: email, password: password, password_confirmation: password)
user.save!

2. Returning to the Project​

Accessing the Environment​

sudo -uweb -s
cd /srv/www/dialog.eslov.se/current

Updating the Codebase​

[Instructions for pulling latest changes and updating dependencies would go here]

Restarting the Application​

To restart the application:

bundle exec passenger-config restart-app

3. Performing Upgrades​

Upgrade History​

Upgrade on August 4, 2024​

Gemfile Updates​

Add the following gems to your Gemfile:

gem "decidim-extra_user_fields", git: "https://github.com/PopulateTools/decidim-module-extra_user_fields.git", branch: "release/0.26-stable"
gem "decidim-budgets_paper_ballots", git: "https://github.com/digidemlab/decidim-module-budgets_paper_ballots", tag: "v0.26.0"

Update the following gem versions:

  • gem "decidim", "0.26.2" to gem "decidim", "0.26.4"
  • gem "decidim-decidim_awesome", "~> 0.8" to gem "decidim-decidim_awesome", "~> 0.9"
  • gem "decidim-dev", "0.26.2" to gem "decidim-dev", "0.26.4"

Hacks on August 23, 2024​

Hacks in extra user fields module:

path: ./vendor/bundle/ruby/2.7.0/bundler/gems/decidim-module-extra_user_fields-c0dddad0c1dd/

  1. Engine
  • path: lib/decidim/extra_user_fields/engine.rb
  DEFAULT_GENDER_OPTIONS = [:male, :female, :other].freeze
DEFAULT_YEARS_OPTIONS = [:spann0, :spann10, :spann20, :spann30, :spann40, :spann50, :spann60, :spann70, :spann80, :spann90].freeze
  1. Forms definitions
  • Not required
  1. Application helper
  • path: app/helpers/decidim/extra_user_fields/application_helper.rb
def gender_options_for_select
Decidim::ExtraUserFields::Engine::DEFAULT_GENDER_OPTIONS.map do |gender|
[gender, I18n.t(gender, scope: "decidim.extra_user_fields.genders")]
end
end
def years_options_for_select
Decidim::ExtraUserFields::Engine::DEFAULT_YEARS_OPTIONS.map do |country|
[country, I18n.t(country, scope: "decidim.extra_user_fields.years")]
end
end
  1. Profile form
  • path: app/views/decidim/extra_user_fields/\_profile_form.html.erb
<% if current_organization.activated_extra_field?(:gender) %>
<%= f.collection_select :gender, f.object.gender_options_for_select, :first, :last %>
<% end %>

<% if current_organization.activated_extra_field?(:country) %>
<%= f.collection_select :country, f.object.years_options_for_select, :first, :last %>
<% end %>
  1. Registration form
  • path: app/views/decidim/extra_user_fields/_registration_form.html.erb
<% if current_organization.activated_extra_field?(:gender) %>
<div class="field">
<%= f.collection_select :gender, f.object.gender_options_for_select, :first, :last %>
</div>
<% end %>

<% if current_organization.activated_extra_field?(:country) %>
<div class="field">
<%= f.collection_select :country, f.object.years_options_for_select, :first, :last %>
</div>
<% end %>
  1. Translations
  • path: config/locales/en.yml
en:
activemodel:
attributes:
user:
country: Age
date_of_birth: Date of birth
gender: Gender
postal_code: Address
years:
spann0: 0-10
spann10: 11-20
spann20: 21-30
spann30: 31-40
spann40: 41-50
spann50: 51-60
spann60: 61-70
spann70: 71-80
spann80: 81-90
spann90: 90->

path: config/locales/sv.yml

sv:
activemodel:
attributes:
user:
country: Ålder
date_of_birth: Date of birth
gender: Kön
postal_code: Adress

sv:
activemodel:
attributes:
user:
country: Ålder
date_of_birth: Date of birth
gender: Kön
postal_code: Adress
decidim:
extra_user_fields:
registration_form:
signup:
legend: Mer information
genders:
female: Kvinna
male: Man
other: Annat
years:
spann0: 0-10 år
spann10: 11-20 år
spann20: 21-30 år
spann30: 31-40 år
spann40: 41-50 år
spann50: 51-60 år
spann60: 61-70 år
spann70: 71-80 år
spann80: 81-90 år
spann90: 90 år ->
Installation Steps​

After updating the Gemfile, run:

passenger stop --port 4000
bundle

For decidim-module-budgets_paper_ballots:

bundle exec rails decidim_budgets_paper_ballots:install:migrations
bundle exec rails db:migrate

For decidim-module-extra_user_fields:

bundle exec rake railties:install:migrations
bundle exec rake db:migrate

General Upgrade Steps​

[Generic steps for upgrades would go here]

4. Copying Production to Staging​

Database Copy Process​

pg_dump --no-owner --dbname=postgresql://decidim_app:<PASSWORD>@localhost/decidim_prod > /home/jdg/dump.sql
sudo su - postgres
psql -c "drop database decidim_stage"
psql -c "create database decidim_stage"
psql --set ON_ERROR_STOP=on -1 decidim_stage < /home/jdg/dump.sql

If needed, create a new PostgreSQL user:

sudo -u postgres psql -c "CREATE USER decidim_stage WITH SUPERUSER CREATEDB NOCREATEROLE PASSWORD '<PASSWORD>'"

Configuring the Staging Environment​

Start the staging server:

passenger start --daemonize --address 127.0.0.1 --port 4001 --environment production

If you encounter issues, try:

rm -Rf node_modules
yarn
rm -Rf vendor
bundle
bundle exec rake webpacker:compile

The stage configuration file is located at:

/srv/www/dialog.eslov.se/current/config/application.yml

5. Useful Commands and Resources​

Common Commands​

Rebuild assets:

RAILS_ENV=production bundle exec rails assets:precompile

Compile Webpacker assets:

bundle exec rake webpacker:compile

Start Webpack development server:

bin/webpack-dev-server

Reset database:

sudo -u postgres psql -c "DROP DATABASE decidim_prod"
sudo service postgresql restart

Stop Passenger:

passenger stop --port 4000

Set up Cronjobs:

bin/rails generate delayed_job:active_record
RAILS_ENV=production bin/delayed_job restart

6. Mail functionality​

bin/rails console -e production
mailer = ActionMailer::Base.new
mailer.delivery_method
mailer.smtp_settings
mailer.mail(from: 'kommunikationsavdelningen@eslov.se', to: 'd+test@whitespace.se', subject: 'test', body: "Hello, you've got mail!").deliver
``