From a15a716066a1986d4a8250f8ff26262734e42c37 Mon Sep 17 00:00:00 2001 From: Disassembler Date: Sat, 21 Apr 2018 22:30:25 +0200 Subject: [PATCH] Revert long naming for CrisisCleanup --- 00-install.sh | 2 +- ccleanup.sh | 40 ------------------- ccleanup/createdb.sql | 6 --- ccleanup/etc/init.d/ccleanup | 29 -------------- ccleanup/srv/ccleanup/conf/database.yml | 8 ---- crisiscleanup.sh | 40 +++++++++++++++++++ {ccleanup => crisiscleanup}/Dockerfile | 24 +++++------ crisiscleanup/createdb.sql | 6 +++ crisiscleanup/etc/init.d/crisiscleanup | 29 ++++++++++++++ .../srv/crisiscleanup}/conf/boot.rb | 0 .../srv/crisiscleanup/conf/database.yml | 8 ++++ .../conf/environments/production.rb | 0 .../conf/initializers/devise.rb | 2 +- .../srv/crisiscleanup}/db/seeds.rb | 2 +- 14 files changed, 98 insertions(+), 98 deletions(-) delete mode 100755 ccleanup.sh delete mode 100644 ccleanup/createdb.sql delete mode 100755 ccleanup/etc/init.d/ccleanup delete mode 100644 ccleanup/srv/ccleanup/conf/database.yml create mode 100755 crisiscleanup.sh rename {ccleanup => crisiscleanup}/Dockerfile (69%) create mode 100644 crisiscleanup/createdb.sql create mode 100755 crisiscleanup/etc/init.d/crisiscleanup rename {ccleanup/srv/ccleanup => crisiscleanup/srv/crisiscleanup}/conf/boot.rb (100%) create mode 100644 crisiscleanup/srv/crisiscleanup/conf/database.yml rename {ccleanup/srv/ccleanup => crisiscleanup/srv/crisiscleanup}/conf/environments/production.rb (100%) rename {ccleanup/srv/ccleanup => crisiscleanup/srv/crisiscleanup}/conf/initializers/devise.rb (99%) rename {ccleanup/srv/ccleanup => crisiscleanup/srv/crisiscleanup}/db/seeds.rb (98%) diff --git a/00-install.sh b/00-install.sh index 3c6c1ed..2136874 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}/ccleanup.sh +# ${SOURCE_DIR}/crisiscleanup.sh # ${SOURCE_DIR}/cts.sh ${SOURCE_DIR}/flsms.sh ${SOURCE_DIR}/gnuhealth.sh diff --git a/ccleanup.sh b/ccleanup.sh deleted file mode 100755 index 3184e6b..0000000 --- a/ccleanup.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/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 -service postgres start - -# Build Docker container -docker build -t ccleanup ${SOURCE_DIR} -cp ${SOURCE_DIR}/etc/init.d/ccleanup /etc/init.d/ccleanup -rc-update -u - -# 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 -spotter-appmgr update-login ccleanup "${CCLEANUP_ADMIN_EMAIL}" "${CCLEANUP_ADMIN_PWD}" - -# 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 diff --git a/ccleanup/createdb.sql b/ccleanup/createdb.sql deleted file mode 100644 index ffad201..0000000 --- a/ccleanup/createdb.sql +++ /dev/null @@ -1,6 +0,0 @@ -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/ccleanup/etc/init.d/ccleanup b/ccleanup/etc/init.d/ccleanup deleted file mode 100755 index 16ce925..0000000 --- a/ccleanup/etc/init.d/ccleanup +++ /dev/null @@ -1,29 +0,0 @@ -#!/sbin/openrc-run - -description="Crisis Cleanup docker container" - -depend() { - need docker postfix postgres -} - -start() { - /usr/bin/docker run -d --rm \ - --name ccleanup \ - -h ccleanup \ - --link postfix \ - --link postgres \ - -v /srv/ccleanup/conf:/srv/ccleanup/config \ - ccleanup -} - -start_post() { - /usr/bin/spotter-appmgr register-proxy ccleanup -} - -stop_pre() { - /usr/bin/spotter-appmgr unregister-proxy ccleanup -} - -stop() { - /usr/bin/docker stop ccleanup -} diff --git a/ccleanup/srv/ccleanup/conf/database.yml b/ccleanup/srv/ccleanup/conf/database.yml deleted file mode 100644 index ae8cd4d..0000000 --- a/ccleanup/srv/ccleanup/conf/database.yml +++ /dev/null @@ -1,8 +0,0 @@ -production: - adapter: postgresql - encoding: unicode - database: ccleanup - pool: 5 - host: postgres - username: ccleanup - password: ${CCLEANUP_PWD} diff --git a/crisiscleanup.sh b/crisiscleanup.sh new file mode 100755 index 0000000..bec50b1 --- /dev/null +++ b/crisiscleanup.sh @@ -0,0 +1,40 @@ +#!/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 +service postgres start + +# Build Docker container +docker build -t crisiscleanup ${SOURCE_DIR} +cp ${SOURCE_DIR}/etc/init.d/crisiscleanup /etc/init.d/crisiscleanup +rc-update -u + +# 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 +spotter-appmgr update-login crisiscleanup "${CRISISCLEANUP_ADMIN_EMAIL}" "${CRISISCLEANUP_ADMIN_PWD}" + +# 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 diff --git a/ccleanup/Dockerfile b/crisiscleanup/Dockerfile similarity index 69% rename from ccleanup/Dockerfile rename to crisiscleanup/Dockerfile index 489fcb5..3edc25c 100644 --- a/ccleanup/Dockerfile +++ b/crisiscleanup/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/ccleanup \ + && git clone --depth 1 https://github.com/CrisisCleanup/crisiscleanup /srv/crisiscleanup \ # Hackfix ruby dependency versions - && 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 \ + && 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 \ # Install Ruby and NodeJS dependencies - && cd /srv/ccleanup \ + && cd /srv/crisiscleanup \ && 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/ccleanup/config/secrets.yml \ + && echo -e "production:\n secret_key_base: $(rake secret)" >/srv/crisiscleanup/config/secrets.yml \ # Generate static resources && rake assets:precompile \ # Create OS user - && 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 \ + && addgroup -S -g 8005 cc \ + && adduser -S -u 8005 -h /srv/crisiscleanup -s /bin/false -g cc -G cc cc \ + && chown -R cc:cc /srv/crisiscleanup \ # Cleanup && apk --no-cache del .deps \ - && find /srv/ccleanup -name '.git*' -exec rm -rf {} + \ + && find /srv/crisiscleanup -name '.git*' -exec rm -rf {} + \ && rm -rf /usr/local/share/.cache \ && rm -rf /root/.bundle /root/.config /root/.npm -VOLUME ["/srv/ccleanup/config"] +VOLUME ["/srv/crisiscleanup/config"] EXPOSE 8080 -USER ccleanup -WORKDIR /srv/ccleanup +USER cc +WORKDIR /srv/crisiscleanup CMD ["rails", "server"] diff --git a/crisiscleanup/createdb.sql b/crisiscleanup/createdb.sql new file mode 100644 index 0000000..2b8176a --- /dev/null +++ b/crisiscleanup/createdb.sql @@ -0,0 +1,6 @@ +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/etc/init.d/crisiscleanup b/crisiscleanup/etc/init.d/crisiscleanup new file mode 100755 index 0000000..c58658c --- /dev/null +++ b/crisiscleanup/etc/init.d/crisiscleanup @@ -0,0 +1,29 @@ +#!/sbin/openrc-run + +description="Crisis Cleanup docker container" + +depend() { + need docker postfix postgres +} + +start() { + /usr/bin/docker run -d --rm \ + --name crisiscleanup \ + -h crisiscleanup \ + --link postfix \ + --link postgres \ + -v /srv/crisiscleanup/conf:/srv/crisiscleanup/config \ + crisiscleanup +} + +start_post() { + /usr/bin/spotter-appmgr register-proxy crisiscleanup +} + +stop_pre() { + /usr/bin/spotter-appmgr unregister-proxy crisiscleanup +} + +stop() { + /usr/bin/docker stop crisiscleanup +} diff --git a/ccleanup/srv/ccleanup/conf/boot.rb b/crisiscleanup/srv/crisiscleanup/conf/boot.rb similarity index 100% rename from ccleanup/srv/ccleanup/conf/boot.rb rename to crisiscleanup/srv/crisiscleanup/conf/boot.rb diff --git a/crisiscleanup/srv/crisiscleanup/conf/database.yml b/crisiscleanup/srv/crisiscleanup/conf/database.yml new file mode 100644 index 0000000..da8b643 --- /dev/null +++ b/crisiscleanup/srv/crisiscleanup/conf/database.yml @@ -0,0 +1,8 @@ +production: + adapter: postgresql + encoding: unicode + database: crisiscleanup + pool: 5 + host: postgres + username: crisiscleanup + password: ${CRISISCLEANUP_PWD} diff --git a/ccleanup/srv/ccleanup/conf/environments/production.rb b/crisiscleanup/srv/crisiscleanup/conf/environments/production.rb similarity index 100% rename from ccleanup/srv/ccleanup/conf/environments/production.rb rename to crisiscleanup/srv/crisiscleanup/conf/environments/production.rb diff --git a/ccleanup/srv/ccleanup/conf/initializers/devise.rb b/crisiscleanup/srv/crisiscleanup/conf/initializers/devise.rb similarity index 99% rename from ccleanup/srv/ccleanup/conf/initializers/devise.rb rename to crisiscleanup/srv/crisiscleanup/conf/initializers/devise.rb index 0a5c1d9..cd60e24 100644 --- a/ccleanup/srv/ccleanup/conf/initializers/devise.rb +++ b/crisiscleanup/srv/crisiscleanup/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 = 'ccleanup@spotter.ngo' + config.mailer_sender = 'crisiscleanup@spotter.ngo' # Configure the class responsible to send e-mails. # config.mailer = 'Devise::Mailer' diff --git a/ccleanup/srv/ccleanup/db/seeds.rb b/crisiscleanup/srv/crisiscleanup/db/seeds.rb similarity index 98% rename from ccleanup/srv/ccleanup/db/seeds.rb rename to crisiscleanup/srv/crisiscleanup/db/seeds.rb index d1bb128..6332e0b 100644 --- a/ccleanup/srv/ccleanup/db/seeds.rb +++ b/crisiscleanup/srv/crisiscleanup/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: "${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} + {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} ])