Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@andreslucena
Last active February 21, 2019 14:31
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreslucena/e998518fe510918d5504fe8bab2c2d4b to your computer and use it in GitHub Desktop.
Save andreslucena/e998518fe510918d5504fe8bab2c2d4b to your computer and use it in GitHub Desktop.
Decidim One Command Magick Installer v0.2
#!/usr/bin/env bash
#
# Decidim installation script on Ubuntu 18.04 LTS
# It should also work on other Operating Systems that supports docker / docker-compose
#
# This is a BETA and as such you should be aware that this could break your environment (if you have any)
# This will use the docker image from Docker Hub and set-up a docker-compose environment for you to try Decidim
# It'll take 15 minutes depending on your network connection
#
# This is also proposal to merge to upstream, to fix the docker-compose/Dockerfile/README
# If this is merged then we don't need the copy-* functions
#
set -e # Exit script if anything fails
set -u # unset variables cause an error
set -o pipefail # https://coderwall.com/p/fkfaqq/safer-bash-scripts-with-set-euxo-pipefail
#set -x # for debugging each command
DECIDIM_VERSION=0.15.1
RUBY_VERSION=2.5.3
DOCKER_COMPOSE_VERSION=1.23.2
SEEDS=true
APP_NAME=${@:-DemoApp}
export DEBIAN_FRONTEND="noninteractive"
function check_dependency {
command=$1
if ! [ -x "$(command -v ${command})" ]; then
echo "Error: ${command} is not installed." >&2
install_dependency ${command}
fi
}
function install_dependency {
dependency=$1
case ${dependency} in
"docker")
# https://docs.docker.com/install/linux/docker-ce/ubuntu/
sudo apt-get update -qq
sudo apt-get install -y \
apt-transport-https \
ca-certificates \
curl \
gnupg-agent \
software-properties-common
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo apt-key add -
sudo add-apt-repository \
"deb [arch=amd64] https://download.docker.com/linux/ubuntu \
$(lsb_release -cs) \
stable"
sudo apt-get update -qq
sudo apt-get install -y docker-ce docker-ce-cli containerd.io
sudo gpasswd -a $USER docker
# reloads the group so we don't need to respawn other bash process
newgrp docker
# disables verbose docker pull images with | cat
docker run hello-world | cat
;;
"docker-compose")
# https://docs.docker.com/compose/install/
sudo curl -L "https://github.com/docker/compose/releases/download/${DOCKER_COMPOSE_VERSION}/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
sudo chmod +x /usr/local/bin/docker-compose
;;
esac
}
function check_dependencies {
check_dependency docker
check_dependency docker-compose
}
function banner_decidim {
echo -e "\e[91m ████████ \e[0m"
echo -e "\e[91m ████████ \e[0m"
echo -e "\e[91m ████████ \e[0m"
echo -e "\e[91m ██████ ████████ \e[0m"
echo -e "\e[91m ███████ ████████ \e[0m"
echo -e "\e[91m ███████ ████████ \e[0m"
echo -e "\e[91m ███████ ████████ \e[0m"
echo -e "\e[91m ███████ ████████ ██ ██, :██ ██ \e[0m"
echo -e "\e[91m ███████ ████████ ██ :██ \e[0m"
echo -e "\e[91m ███████ ████████ ██████ ██████ ██████ ██████ ██ ███████ ██ ███████████ \e[0m"
echo -e "\e[91m ███████ ████████ ████████ ██ ██ ███████ ██ , ██ ,██ ███ ██ ██, ██ ██,\e[0m"
echo -e "\e[91m ███████ ████████ ████████ ██ ██ ██~ ██ ██ :██ ███ ██ ██, ██ ██,\e[0m"
echo -e "\e[91m ~██████ ████████ ██████ ██████ ██████ ██████ ██ ███████ ██ ██, ██ ██,\e[0m"
echo -e "\e[91m ,~ ~~ ~: ~ \e[0m"
}
function banner_start {
banner_decidim
echo " Welcome to Decidim installation"
echo " This is a BETA"
echo " This will install decidim on a new directory ==> ${APP_NAME}/"
echo " It'll take from 10 to 30 minutes depending on your network connection"
echo "************************************************************************************************"
echo "Starting on 5 seconds. Press CTRL+C to cancel"
sleep 5
}
function banner_end {
banner_decidim
echo " Decidim installation process finished. All is OK!"
echo "************************************************************************************************"
echo " You can go to http://localhost:3000 and see the website."
echo " It'll take a few minutes to start up the first time. Be patient. "
if [ $SEEDS ] ; then
echo "************************************************************************************************"
echo " ------------------------------------------------------------------------------------------"
echo " | Email | Password | URL | Role |"
echo " ------------------------------------------------------------------------------------------"
echo " | user@example.org | decidim123456 | http://localhost:3000/session/new | Regular user |"
echo " | admin@example.org | decidim123456 | http://localhost:3000/admin | Admin user |"
echo " ------------------------------------------------------------------------------------------"
fi
echo "************************************************************************************************"
echo " To stop the server you need to go to the new directory and stop docker-compose"
echo " cd ${APP_NAME} ; docker-compose down "
}
function bootstrap_docker_app {
# disables verbose docker pull images with | cat
docker run -v "$(pwd):/code" decidim/decidim:${DECIDIM_VERSION} ${APP_NAME} | cat
# FIXME: we shouldn't have to chown nor sudo :/
sudo chown -R $(whoami): ${APP_NAME}
cd ${APP_NAME}
if ! [ -x "$(command -v git)" ]; then
git init
git add .
git commit -m "Initialized with Decidim v${DECIDIM_VERSION}"
fi
#echo 'gem "sidekiq", "~> 5.2" # if you want to enable worker' >> Gemfile
copy-env-file
copy-dockerfile
copy-docker-compose
copy-readme
docker-compose up -d
docker-compose run app rails db:create
docker-compose run app rails db:migrate
$SEEDS && docker-compose run app rails db:seed
}
function copy-readme {
# TODO: remove when it's on upstream decidim/decidim
cat <<EOF > README.md
# ${APP_NAME}
Free Open-Source participatory democracy, citizen participation and open government for cities and organizations
This is the open-source repository for ${APP_NAME}, based on [Decidim](https://decidim.org).
## Starting the application
\`````bash
docker-compose up -d
\`````
## Stoping the application
\`````bash
docker-compose down
\`````
## Upgrading
Update your Gemfile, where 0.16.0 is the [last published version](https://github.com/decidim/decidim/releases).
\`````ruby
DECIDIM_VERSION = "0.16.0"
gem "decidim", DECIDIM_VERSION
gem "decidim-dev", DECIDIM_VERSION
\`````
Run these commands to upgrade and make sure you get all the latest migrations:
\`````bash
docker-compose run app bundle update decidim
docker-compose run app rails decidim:upgrade
docker-compose run app rails db:migrate
\`````
## Setting up the application
### Development
For quick-starting on development environment, we recommend on using the demo data (seeds). You can use them with:
\`````bash
docker-compose run app rails db:seed
\`````
### Production
For production environment, you will want to start on a new database.
You will need to do some steps before having the app working properly once you've deployed it:
1. Open a Rails console in the server: \`bundle exec rails console\`
2. Create a System Admin user:
\`````ruby
user = Decidim::System::Admin.new(email: <email>, password: <password>, password_confirmation: <password>)
user.save!
\`````
3. Visit \`<your app url>/system\` and login with your system admin credentials
4. Create a new organization. Check the locales you want to use for that organization, and select a default locale.
5. Set the correct default host for the organization, otherwise the app will not work properly. Note that you need to include any subdomain you might be using.
6. Fill the rest of the form and submit it.
You're good to go!
## Documentation
* [Functions and Features](https://docs.decidim.org/features/en/general-description/) - How Decidim works, a detailed feature description, and the roadmap for 2017/2018.
* [Decidim’s Social Contract](https://docs.decidim.org/social-contract/en/social-contract/) - Code for democratic guarantees and open collaboration
* [Developers manual](https://docs.decidim.org/develop/en/introduction/)
* [Checklist](https://docs.decidim.org/develop/en/checklist/)
## Modules
TODO
## License
TODO
Happy Hacking!
EOF
}
function copy-dockerfile {
# TODO: remove when it's on upstream
cat <<EOF > Dockerfile
# Decidim Application Dockerfile
#
# This is an image to be used with docker-compose, to develop Decidim (https://decidim.org) locally.
#
#
# Starts with a clean ruby image from Debian (slim)
FROM ruby:${RUBY_VERSION}
# Installs system dependencies
ENV DEBIAN_FRONTEND noninteractive
RUN apt-get update -qq && apt-get install -y \\
build-essential \\
libpq-dev \\
nodejs \\
imagemagick
# Bleeding edge, I have some doubts with Alpine and glibc
##
## Starts with a clean ruby image from Alpine Linux
#FROM ruby:${RUBY_VERSION}-alpine
#
## Installs system dependencies
#RUN apk add --update --no-cache \\
# build-base \\
# file \\
# imagemagick \\
# libc6-compat \\
# nodejs \\
# postgresql-dev \\
# tzdata \\
# xz-libs
# Sets workdir as /app
RUN mkdir /app
WORKDIR /app
# Installs bundler dependencies
ENV BUNDLE_PATH=/app/vendor/bundle \\
BUNDLE_BIN=/app/vendor/bundle/bin \\
BUNDLE_JOBS=5 \\
BUNDLE_RETRY=3 \\
GEM_HOME=/bundle
ENV PATH="\${BUNDLE_BIN}:\${PATH}"
ADD Gemfile /app/Gemfile
ADD Gemfile.lock /app/Gemfile.lock
RUN bundle install
# Copy all the code to /app
ADD . /app
EOF
}
function copy-env-file {
# TODO: remove when it's on upstream
cat << EOF > .env
DATABASE_HOST=pg
DATABASE_PASSWORD=
DATABASE_PORT=5432
#DATABASE_URL=
DATABASE_USERNAME=postgres
GEOCODER_LOOKUP_APP_CODE=
GEOCODER_LOOKUP_APP_ID=
OMNIAUTH_FACEBOOK_APP_ID=
OMNIAUTH_FACEBOOK_APP_SECRET=
OMNIAUTH_GOOGLE_CLIENT_ID=
OMNIAUTH_GOOGLE_CLIENT_SECRET=
OMNIAUTH_TWITTER_API_KEY=
OMNIAUTH_TWITTER_API_SECRET=
PORT=3000
RAILS_ENV=development
RAILS_MAX_THREADS=5
RAILS_SERVE_STATIC_FILES=false
REDIS_URL=redis://redis:6379
SECRET_KEY_BASE=
SMTP_ADDRESS=
SMTP_DOMAIN=
SMTP_PASSWORD=
SMTP_USERNAME=
WEB_CONCURRENCY=2
EOF
}
function copy-docker-compose {
# TODO: remove when it's on upstream
cat << EOF > docker-compose.yml
version: '3'
services:
app:
build: .
volumes:
- .:/app
- app_assets:/app/public/assets/
- app_bundle:/app/vendor/bundle
- app_file_storage:/app/public/system/
- app_logs:/app/logs/
ports:
- 3000:3000
links:
- pg
command: bundle exec puma
depends_on:
- pg
- redis
env_file: .env
#worker:
# build: .
# volumes:
# - .:/app
# - app_assets:/app/public/assets/
# - app_bundle:/app/vendor/bundle
# - app_file_storage:/app/public/system/
# - app_logs:/app/logs/
# links:
# - pg
# - redis
# command: bundle exec sidekiq
# depends_on:
# - pg
# - redis
# env_file: .env
pg:
image: postgres
restart: always
volumes:
- pg-data:/var/lib/postgresql/data
redis:
image: redis
restart: always
volumes:
- redis-data:/data
volumes:
app_assets: {}
app_bundle: {}
app_file_storage: {}
app_logs: {}
pg-data: {}
redis-data: {}
EOF
}
function main {
banner_start
check_dependencies
bootstrap_docker_app
banner_end
}
main
@andreslucena
Copy link
Author

andreslucena commented Feb 15, 2019

You can use it with these commands:

wget https://gist.githubusercontent.com/andreslucena/e998518fe510918d5504fe8bab2c2d4b/raw/09590c24cfaf60e1d1617afb0508fbf8d2d3dbe7/install-decidim.bash
bash install-decidim.bash YourApp

Dependencies:

  • docker
  • docker-compose
  • git (if you have we'll use it)

If you want to do it on a virtual machine, you can execute this with a Vagrantfile like:

Vagrant.configure("2") do |config|
  config.vm.box = "ubuntu/bionic64"
  config.vm.network "forwarded_port", guest: 3000, host: 3000, host_ip: "127.0.0.1"
  config.vm.provision "shell", path: "https://gist.githubusercontent.com/andreslucena/e998518fe510918d5504fe8bab2c2d4b/raw/09590c24cfaf60e1d1617afb0508fbf8d2d3dbe7/install-decidim.bash"
end

And executing:

vagrant up

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment