From 551d71750ab4cbfc3846cf091f9d20a60b07d56b Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sun, 25 Mar 2018 14:07:25 +0200 Subject: [PATCH] Shorten CrisisClenup handle --- 00-install.sh | 2 +- basic/srv/portal/index.html | 2 +- ccleanup.sh | 44 +++++++++++++++++++ {crisiscleanup => ccleanup}/Dockerfile | 24 +++++----- ccleanup/createdb.sql | 6 +++ .../etc/init.d/ccleanup | 12 ++--- .../srv/ccleanup}/conf/boot.rb | 0 ccleanup/srv/ccleanup/conf/database.yml | 8 ++++ .../ccleanup}/conf/environments/production.rb | 0 .../srv/ccleanup}/conf/initializers/devise.rb | 2 +- .../srv/ccleanup}/db/seeds.rb | 2 +- crisiscleanup.sh | 44 ------------------- crisiscleanup/createdb.sql | 6 --- .../srv/crisiscleanup/conf/database.yml | 8 ---- 14 files changed, 80 insertions(+), 80 deletions(-) create mode 100755 ccleanup.sh rename {crisiscleanup => ccleanup}/Dockerfile (66%) create mode 100644 ccleanup/createdb.sql rename crisiscleanup/etc/init.d/crisiscleanup => ccleanup/etc/init.d/ccleanup (54%) rename {crisiscleanup/srv/crisiscleanup => ccleanup/srv/ccleanup}/conf/boot.rb (100%) create mode 100644 ccleanup/srv/ccleanup/conf/database.yml rename {crisiscleanup/srv/crisiscleanup => ccleanup/srv/ccleanup}/conf/environments/production.rb (100%) rename {crisiscleanup/srv/crisiscleanup => ccleanup/srv/ccleanup}/conf/initializers/devise.rb (99%) rename {crisiscleanup/srv/crisiscleanup => ccleanup/srv/ccleanup}/db/seeds.rb (98%) delete mode 100755 crisiscleanup.sh delete mode 100644 crisiscleanup/createdb.sql delete mode 100644 crisiscleanup/srv/crisiscleanup/conf/database.yml diff --git a/00-install.sh b/00-install.sh index beb5337..7b16063 100755 --- a/00-install.sh +++ b/00-install.sh @@ -10,7 +10,7 @@ ${SOURCE_DIR}/basic.sh # Install applications ${SOURCE_DIR}/ckan.sh -# ${SOURCE_DIR}/crisiscleanup.sh +# ${SOURCE_DIR}/ccleanup.sh # ${SOURCE_DIR}/cts.sh ${SOURCE_DIR}/gnuhealth.sh ${SOURCE_DIR}/kanboard.sh diff --git a/basic/srv/portal/index.html b/basic/srv/portal/index.html index 9d0b1a7..4ecc494 100644 --- a/basic/srv/portal/index.html +++ b/basic/srv/portal/index.html @@ -56,7 +56,7 @@ -
+

Crisis CleanupCrisis Cleanup

Mapování krizové pomoci při odstraňování následků katastrof a koordinaci práce. Jde o majetek, ne o lidi.

    diff --git a/ccleanup.sh b/ccleanup.sh new file mode 100755 index 0000000..3874722 --- /dev/null +++ b/ccleanup.sh @@ -0,0 +1,44 @@ +#!/bin/sh + +SOURCE_DIR=$(realpath $(dirname "${0}"))/ccleanup + +# Check prerequisites +docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh +docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh +docker image ls | grep -q ruby || $(realpath $(dirname "${0}"))/ruby.sh + +# Build Docker container +docker build -t ccleanup ${SOURCE_DIR} + +# Create database +export CCLEANUP_PWD=$(head -c 18 /dev/urandom | base64) +envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql + +# Copy existing config files into persistent storage +mkdir -p /srv/ccleanup/conf +chown 8005:8005 /srv/ccleanup/conf +docker run --rm -v /srv/ccleanup/conf:/mnt/conf ccleanup cp -rp /srv/ccleanup/config/. /mnt/conf +chown root:root /srv/ccleanup/conf + +# Configure CrisisCleanup +export CCLEANUP_ADMIN_USER="Admin" +export CCLEANUP_ADMIN_EMAIL="admin@example.com" +export CCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) +envsubst <${SOURCE_DIR}/srv/ccleanup/conf/database.yml >/srv/ccleanup/conf/database.yml +cp ${SOURCE_DIR}/srv/ccleanup/conf/boot.rb /srv/ccleanup/conf/boot.rb +cp ${SOURCE_DIR}/srv/ccleanup/conf/initializers/devise.rb /srv/ccleanup/conf/initializers/devise.rb +cp ${SOURCE_DIR}/srv/ccleanup/conf/environments/production.rb /srv/ccleanup/conf/environments/production.rb + +# Populate database +envsubst <${SOURCE_DIR}/srv/ccleanup/db/seeds.rb >/tmp/seeds.rb +docker run --rm -h ccleanup --link postgres -v /srv/ccleanup/conf:/srv/ccleanup/config ccleanup rake db:schema:load +docker run --rm -h ccleanup --link postgres -v /srv/ccleanup/conf:/srv/ccleanup/config -v /tmp/seeds.rb:/srv/ccleanup/db/seeds.rb ccleanup rake db:seed +rm /tmp/seeds.rb + +# Create CrisisCleanup service +cp ${SOURCE_DIR}/etc/init.d/ccleanup /etc/init.d/ccleanup +rc-update add ccleanup +service ccleanup start + +# Add application definition +spotter-appmgr add-app ccleanup "https://ccleanup.{host}/" "${CCLEANUP_ADMIN_EMAIL}" "${CCLEANUP_ADMIN_PWD}" diff --git a/crisiscleanup/Dockerfile b/ccleanup/Dockerfile similarity index 66% rename from crisiscleanup/Dockerfile rename to ccleanup/Dockerfile index a4e59ca..489fcb5 100644 --- a/crisiscleanup/Dockerfile +++ b/ccleanup/Dockerfile @@ -19,33 +19,33 @@ RUN \ # Install build dependencies apk --no-cache add --virtual .deps build-base git libxml2-dev libxslt-dev linux-headers postgresql-dev yarn zlib-dev \ # Clone CrisisCleanup - && git clone --depth 1 https://github.com/CrisisCleanup/crisiscleanup /srv/crisiscleanup \ + && git clone --depth 1 https://github.com/CrisisCleanup/crisiscleanup /srv/ccleanup \ # Hackfix ruby dependency versions - && sed -i 's/2\.2\.5/2.3.6/' /srv/crisiscleanup/Gemfile \ - && sed -i 's/rdoc (4\.2\.0)/rdoc (4.3.0)/' /srv/crisiscleanup/Gemfile.lock \ + && sed -i 's/2\.2\.5/2.3.6/' /srv/ccleanup/Gemfile \ + && sed -i 's/rdoc (4\.2\.0)/rdoc (4.3.0)/' /srv/ccleanup/Gemfile.lock \ # Install Ruby and NodeJS dependencies - && cd /srv/crisiscleanup \ + && cd /srv/ccleanup \ && bundle config build.nokogiri --use-system-libraries \ && bundle install \ && npm install \ && yarn \ # Create CrisisCleanup secret - && echo -e "production:\n secret_key_base: $(rake secret)" >/srv/crisiscleanup/config/secrets.yml \ + && echo -e "production:\n secret_key_base: $(rake secret)" >/srv/ccleanup/config/secrets.yml \ # Generate static resources && rake assets:precompile \ # Create OS user - && addgroup -S -g 8005 crisiscleanup \ - && adduser -S -u 8005 -h /srv/crisiscleanup -s /bin/false -g crisiscleanup -G crisiscleanup crisiscleanup \ - && chown -R crisiscleanup:crisiscleanup /srv/crisiscleanup \ + && addgroup -S -g 8005 ccleanup \ + && adduser -S -u 8005 -h /srv/ccleanup -s /bin/false -g ccleanup -G ccleanup ccleanup \ + && chown -R ccleanup:ccleanup /srv/ccleanup \ # Cleanup && apk --no-cache del .deps \ - && find /srv/crisiscleanup -name '.git*' -exec rm -rf {} + \ + && find /srv/ccleanup -name '.git*' -exec rm -rf {} + \ && rm -rf /usr/local/share/.cache \ && rm -rf /root/.bundle /root/.config /root/.npm -VOLUME ["/srv/crisiscleanup/config"] +VOLUME ["/srv/ccleanup/config"] EXPOSE 8080 -USER crisiscleanup -WORKDIR /srv/crisiscleanup +USER ccleanup +WORKDIR /srv/ccleanup CMD ["rails", "server"] diff --git a/ccleanup/createdb.sql b/ccleanup/createdb.sql new file mode 100644 index 0000000..ffad201 --- /dev/null +++ b/ccleanup/createdb.sql @@ -0,0 +1,6 @@ +CREATE ROLE ccleanup NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${CCLEANUP_PWD}'; +CREATE DATABASE ccleanup; +REVOKE ALL ON DATABASE ccleanup FROM public; +ALTER DATABASE ccleanup OWNER TO ccleanup; +\c ccleanup +CREATE EXTENSION hstore; diff --git a/crisiscleanup/etc/init.d/crisiscleanup b/ccleanup/etc/init.d/ccleanup similarity index 54% rename from crisiscleanup/etc/init.d/crisiscleanup rename to ccleanup/etc/init.d/ccleanup index 291f67f..828ff96 100755 --- a/crisiscleanup/etc/init.d/crisiscleanup +++ b/ccleanup/etc/init.d/ccleanup @@ -9,18 +9,18 @@ depend() { start() { /usr/bin/docker run -d --rm \ - --name crisiscleanup \ - -h crisiscleanup \ + --name ccleanup \ + -h ccleanup \ --link postfix \ --link postgres \ - -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config \ - crisiscleanup + -v /srv/ccleanup/conf:/srv/ccleanup/config \ + ccleanup } start_post() { - /usr/local/bin/spotter-appmgr update-hosts crisiscleanup + /usr/local/bin/spotter-appmgr update-hosts ccleanup } stop() { - /usr/bin/docker stop crisiscleanup + /usr/bin/docker stop ccleanup } diff --git a/crisiscleanup/srv/crisiscleanup/conf/boot.rb b/ccleanup/srv/ccleanup/conf/boot.rb similarity index 100% rename from crisiscleanup/srv/crisiscleanup/conf/boot.rb rename to ccleanup/srv/ccleanup/conf/boot.rb diff --git a/ccleanup/srv/ccleanup/conf/database.yml b/ccleanup/srv/ccleanup/conf/database.yml new file mode 100644 index 0000000..ae8cd4d --- /dev/null +++ b/ccleanup/srv/ccleanup/conf/database.yml @@ -0,0 +1,8 @@ +production: + adapter: postgresql + encoding: unicode + database: ccleanup + pool: 5 + host: postgres + username: ccleanup + password: ${CCLEANUP_PWD} diff --git a/crisiscleanup/srv/crisiscleanup/conf/environments/production.rb b/ccleanup/srv/ccleanup/conf/environments/production.rb similarity index 100% rename from crisiscleanup/srv/crisiscleanup/conf/environments/production.rb rename to ccleanup/srv/ccleanup/conf/environments/production.rb diff --git a/crisiscleanup/srv/crisiscleanup/conf/initializers/devise.rb b/ccleanup/srv/ccleanup/conf/initializers/devise.rb similarity index 99% rename from crisiscleanup/srv/crisiscleanup/conf/initializers/devise.rb rename to ccleanup/srv/ccleanup/conf/initializers/devise.rb index cd60e24..0a5c1d9 100644 --- a/crisiscleanup/srv/crisiscleanup/conf/initializers/devise.rb +++ b/ccleanup/srv/ccleanup/conf/initializers/devise.rb @@ -10,7 +10,7 @@ Devise.setup do |config| # Configure the e-mail address which will be shown in Devise::Mailer, # note that it will be overwritten if you use your own mailer class # with default "from" parameter. - config.mailer_sender = 'crisiscleanup@spotter.ngo' + config.mailer_sender = 'ccleanup@spotter.ngo' # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' diff --git a/crisiscleanup/srv/crisiscleanup/db/seeds.rb b/ccleanup/srv/ccleanup/db/seeds.rb similarity index 98% rename from crisiscleanup/srv/crisiscleanup/db/seeds.rb rename to ccleanup/srv/ccleanup/db/seeds.rb index 6332e0b..d1bb128 100644 --- a/crisiscleanup/srv/crisiscleanup/db/seeds.rb +++ b/ccleanup/srv/ccleanup/db/seeds.rb @@ -19,5 +19,5 @@ Legacy::LegacySite.create!([ {address: "200 Epcot Center Drive", blurred_latitude: 28.3849506927356, blurred_longitude: -81.5443968549352, case_number: "A7", city: "Orlando", claimed_by: 2, legacy_event_id: 1, latitude: 28.383045, longitude: -81.5485919, name: "Timothy Schmidt", phone1: "1234567890", reported_by: 2, requested_at: nil, state: "Florida", status: "Open, unassigned", work_type: "Debris", data: {"email"=>"", "notes"=>"", "habitable"=>"n", "assigned_to"=>"", "electricity"=>"n", "prepared_by"=>"", "rent_or_own"=>"", "unsafe_roof"=>"n", "cross_street"=>"", "status_notes"=>"", "time_to_call"=>"", "older_than_60"=>"n", "other_hazards"=>"", "roof_collapse"=>"n", "special_needs"=>"", "num_trees_down"=>"0", "num_wide_trees"=>"0", "chainsaw_needed"=>"n", "first_responder"=>"n", "autofill_disable"=>"", "electrical_lines"=>"n", "total_volunteers"=>"", "destruction_level"=>"", "meal_location_poc"=>"", "do_not_work_before"=>"", "meal_serving_times"=>"", "structural_problems"=>"n", "required_daily_meals"=>"", "work_without_resident"=>"n", "interior_debris_removal"=>"n", "unsalvageable_structure"=>"n", "heavy_machinary_required"=>"n", "vegitative_debris_removal"=>"n", "hours_worked_per_volunteer"=>"", "initials_of_resident_present"=>"", "nonvegitative_debris_removal"=>"n", "member_of_assessing_organization"=>"n"}, request_date: "2017-09-18", appengine_key: nil, zip_code: "32821", county: "Orange County", phone2: "", work_requested: "", name_metaphone: "TM0 SXMTT", city_metaphone: "ORLNT", county_metaphone: "ORNJ KNT", address_metaphone: " EPKT SNTR TRF", user_id: 2} ]) User.create!([ - {email: "${CRISISCLEANUP_ADMIN_EMAIL}", password: "${CRISISCLEANUP_ADMIN_PWD}", name: "${CRISISCLEANUP_ADMIN_USER}", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, legacy_organization_id: 1, current_sign_in_at: "2016-07-15 03:45:59", last_sign_in_at: "2016-06-08 16:56:37", current_sign_in_ip: "1.1.1.1", last_sign_in_ip: "173.164.56.105", referring_user_id: nil, admin: true, role: nil, mobile: nil, accepted_terms: true, accepted_terms_timestamp: "2017-09-18 20:46:31", title: nil} + {email: "${CCLEANUP_ADMIN_EMAIL}", password: "${CCLEANUP_ADMIN_PWD}", name: "${CCLEANUP_ADMIN_USER}", reset_password_token: nil, reset_password_sent_at: nil, remember_created_at: nil, sign_in_count: 1, legacy_organization_id: 1, current_sign_in_at: "2016-07-15 03:45:59", last_sign_in_at: "2016-06-08 16:56:37", current_sign_in_ip: "1.1.1.1", last_sign_in_ip: "173.164.56.105", referring_user_id: nil, admin: true, role: nil, mobile: nil, accepted_terms: true, accepted_terms_timestamp: "2017-09-18 20:46:31", title: nil} ]) diff --git a/crisiscleanup.sh b/crisiscleanup.sh deleted file mode 100755 index 435c309..0000000 --- a/crisiscleanup.sh +++ /dev/null @@ -1,44 +0,0 @@ -#!/bin/sh - -SOURCE_DIR=$(realpath $(dirname "${0}"))/crisiscleanup - -# Check prerequisites -docker image ls | grep -q postfix || $(realpath $(dirname "${0}"))/postfix.sh -docker image ls | grep -q postgres || $(realpath $(dirname "${0}"))/postgres.sh -docker image ls | grep -q ruby || $(realpath $(dirname "${0}"))/ruby.sh - -# Build Docker container -docker build -t crisiscleanup ${SOURCE_DIR} - -# Create database -export CRISISCLEANUP_PWD=$(head -c 18 /dev/urandom | base64) -envsubst <${SOURCE_DIR}/createdb.sql | docker exec -i postgres psql - -# Copy existing config files into persistent storage -mkdir -p /srv/crisiscleanup/conf -chown 8005:8005 /srv/crisiscleanup/conf -docker run --rm -v /srv/crisiscleanup/conf:/mnt/conf crisiscleanup cp -rp /srv/crisiscleanup/config/. /mnt/conf -chown root:root /srv/crisiscleanup/conf - -# Configure CrisisCleanup -export CRISISCLEANUP_ADMIN_USER="Admin" -export CRISISCLEANUP_ADMIN_EMAIL="admin@example.com" -export CRISISCLEANUP_ADMIN_PWD=$(head -c 12 /dev/urandom | base64) -envsubst <${SOURCE_DIR}/srv/crisiscleanup/conf/database.yml >/srv/crisiscleanup/conf/database.yml -cp ${SOURCE_DIR}/srv/crisiscleanup/conf/boot.rb /srv/crisiscleanup/conf/boot.rb -cp ${SOURCE_DIR}/srv/crisiscleanup/conf/initializers/devise.rb /srv/crisiscleanup/conf/initializers/devise.rb -cp ${SOURCE_DIR}/srv/crisiscleanup/conf/environments/production.rb /srv/crisiscleanup/conf/environments/production.rb - -# Populate database -envsubst <${SOURCE_DIR}/srv/crisiscleanup/db/seeds.rb >/tmp/seeds.rb -docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config crisiscleanup rake db:schema:load -docker run --rm -h crisiscleanup --link postgres -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config -v /tmp/seeds.rb:/srv/crisiscleanup/db/seeds.rb crisiscleanup rake db:seed -rm /tmp/seeds.rb - -# Create CrisisCleanup service -cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup -rc-update add crisiscleanup -service crisiscleanup start - -# Add application definition -spotter-appmgr add-app crisiscleanup "https://crisiscleanup.{host}/" "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}" diff --git a/crisiscleanup/createdb.sql b/crisiscleanup/createdb.sql deleted file mode 100644 index 2b8176a..0000000 --- a/crisiscleanup/createdb.sql +++ /dev/null @@ -1,6 +0,0 @@ -CREATE ROLE crisiscleanup NOSUPERUSER NOCREATEDB NOCREATEROLE NOINHERIT LOGIN ENCRYPTED PASSWORD '${CRISISCLEANUP_PWD}'; -CREATE DATABASE crisiscleanup; -REVOKE ALL ON DATABASE crisiscleanup FROM public; -ALTER DATABASE crisiscleanup OWNER TO crisiscleanup; -\c crisiscleanup -CREATE EXTENSION hstore; diff --git a/crisiscleanup/srv/crisiscleanup/conf/database.yml b/crisiscleanup/srv/crisiscleanup/conf/database.yml deleted file mode 100644 index da8b643..0000000 --- a/crisiscleanup/srv/crisiscleanup/conf/database.yml +++ /dev/null @@ -1,8 +0,0 @@ -production: - adapter: postgresql - encoding: unicode - database: crisiscleanup - pool: 5 - host: postgres - username: crisiscleanup - password: ${CRISISCLEANUP_PWD}