Beginning to Install OpenFoodNetwork Package

Loving https://github.com/openfoodfoundation/openfoodnetwork.

Looking at the deployment package.

Start with our vars.yml package.

It says the checkout_zone is as defined by Spree. This spree? Same as this one?

Why are the repositories using http instead of git://? And is the US i10n usable?

Does there actually need to be a seeds.rb file in the i10n repo?

Forked Ansible deployment repo.

Got deployed with the Australian i10n_au data and been fiddling around with i10n_en us data with seed data for Spree, which is a Ruby ecommerce platform.

Renamed the headers in the “suburbs” csv file and now trying to see if removing the counties helps. Regex to do that: ^(\d{5},[\d.]*,[-\d.]*,[\w ]*,\w{2}),[\w ]+$

Install is working, but some of the US outlying territories are not currently included in active i10n data.

NOTE Ask about: Before you can create a producer profile you’ll need to email us at hello@openfoodnetwork.org. This is a spam prevention method, but once we know you aren’t a robot, we’ll give you permission to make extra enterprise profiles.

Ask About:

OFN monitoring and instrumentation

newrelic_key – the Newrelic key for application monitoring. Set to “none” to NOT use newrelic.

bugsnag_key – the Bugnsag key for bug monitoring. Set to “none” to not use bugsnag.

newrelic_key: none
bugsnag_key: none

vagrant@vagrant-ubuntu-precise-64:~/apps/pcolacoop/current/log$ tail -10 test.log 
  CACHE (0.0ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON ...
  CACHE (0.0ms)  SELECT COUNT(*) FROM "spree_roles" INNER JOIN "spree_roles_users" ON "spree_roles"."id" = "spree_roles_users"."role_id" WHERE "spree_roles_users"."user_id" = 1 AND "spree_roles"."name" = 'admin'
Completed 500 Internal Server Error in 43.0ms
** [Bugsnag] No API key configured, couldn't notify

I though maybe a permission issue, but am new to Nginx and Ruby. Recursively
* files seem to be set to 664
* directories to 775.

(Aside – cool set of admin/Vagrant video tutorials)

In the log/test.log final lines are:

SELECT 1 AS one FROM "enterprises" WHERE "enterprises"."permalink" = 'my-enterprise' LIMIT 1
rollback

Let’s login to postgres and poke around:

$ su - postgres
$ psql
# \list
openfoodnetwork
# \c openfoodnetwork 
You are now connected to database "openfoodnetwork" as user "postgres".
# \d
long list of all tables
# \q #to exit
# SELECT 1 AS one FROM "enterprises" WHERE "enterprises"."permalink" = 'my-enterprise' LIMIT 1;

ERROR: syntax error at or near “select”
LINE 2: select postgres
^

Hmmm. Source of error?

# SELECT 1 AS one FROM "enterprises" WHERE "enterprises"."permalink" = 'my_enterprise' LIMIT 1;
 one 
-----

No. That syntax error isn’t recurring.

Ah. The postgres log files located in /var/log/postgresql/:

sudo less /var/log/postgresql/postgresql-9.1-main.log
        pg_get_expr(d.adbin, d.adrelid), a.attnotnull, a.atttypid, a.atttypmod
                                                FROM pg_attribute a LEFT JOIN pg_attrdef d
                                                    ON a.attrelid = d.adrelid AND a.attnum = d.adnum
                                             WHERE a.attrelid = '"versions"'::regclass
                                                 AND a.attnum > 0 AND NOT a.attisdropped
                                             ORDER BY a.attnum

    2015-09-18 06:11:48 UTC FATAL:  role "vagrant" does not exist
    2015-09-18 06:12:23 UTC FATAL:  role "root" does not exist
    2015-09-18 06:12:48 UTC ERROR:  relation "enterprises" does not exist at character 22

Add users to database?

Was having authentication issues using su -. Solution:

su asks for the root password. Since ubuntu doesn’t use a root account, you normally do not have this password set.

To become root use sudo su with your personal password in this case “vagrant”.


$ su - postgres
# psql openfoodnetwork
openfoodnetwork=# CREATE USER vagrant WITH PASSWORD 'vagrant';
ERROR:  role "vagrant" already exists
openfoodnetwork=# GRANT ALL PRIVILEGES ON DATABASE openfoodnetwork to vagrant;
GRANT
openfoodnetwork=# 

Same error, apparently.

Deleted and recreated log/test.log and now nothing’s being written to it.


Issue with nothing being written to test log turned out to be due to the permissions being wrong for the recreated file. Should be 664.

As it turned out, the “test” environment in this Ansible/Vagrant install doesn’t get (the Spree seeds?) configured correctly, but the “development” environment does.

There is an issue where the port in the URL get’s cut off in certain links, so 127.0.0.1:3000 becomes 127.0.0.1 and a 404 not found error is returned. Also – when the Vagrant port is different from the Rails app port, the server needs to be run with the -bind flag: bundle exec rails server -b 0.0.0.0 in order to come up at 127.0.0.1:vagrant_port_number_here in a browser running on the host computer. But if the ports match, no port flag is necessary. I think. This is actually not completely confirmed.

TO check rails environment settings from command line, within app directory: bundle exec rails r "print Rails.env"

For bugsnag to work, the bugsnag.rb file needs to reside in config/initializers directory, but current ofn_deployment ansible script puts it in config so needs to be moved manually subsequent to provisioning.

Spree Mail settings for using Google SMTP are supposedly:

  • SMTP DOMAIN NAME: smtp.gmail.com
  • SMTP MAIL HOST: smtp.gmail.com
  • SMTP PORT: 587
  • SECURE CONNECTION TYPE: TLS
  • SMTP AUTHENTICATION TYPE: login
  • SMTP USERNAME: me@gmail.com
  • SMTP PASSWORD: *********

Spree reports that mail is working, but mails are not coming through. Installed postfix mail (sudo apt-get update && sudo apt-get install postfix && sudo apt-get install mailutils) and tried to send a test email from the console using echo "we will work?" | mail -s "testing" mike@madhappy.com And got bounceback:

Reporting-MTA: dns; vagrant-ubuntu-precise-64
X-Postfix-Queue-ID: D65F0C24EE
X-Postfix-Sender: rfc822; vagrant@vagrant-ubuntu-precise-64
Arrival-Date: Fri, 25 Sep 2015 05:23:47 +0000 (UTC)

Final-Recipient: rfc822; mike@madhappy.com
Action: failed
Status: 5.4.4
Diagnostic-Code: X-Postfix; Host or domain name not found. Name service error
    for name=madhappy.com type=AAAA: Host not found

Found a web thread making me think maybe need to create an A record for the Vagrant box. Or NO, maybe need to use DNSMasq to fool the network into thinking there is one.

Let’s first confirm that the rails app/spree even needs mail set up in the underlying OS. Okay actually let’s try to set up Vagrant box’s postfix to use gmail SMTP.

These are the ofn_settings for /etc/postfix/main.cf:

    # TLS parameters
    smtpd_tls_cert_file=/etc/ssl/certs/ssl-cert-snakeoil.pem
    smtpd_tls_key_file=/etc/ssl/private/ssl-cert-snakeoil.key
    smtpd_use_tls=yes
    smtpd_tls_session_cache_database = btree:${data_directory}/smtpd_scache
    smtp_tls_session_cache_database = btree:${data_directory}/smtp_scache

    # See /usr/share/doc/postfix/TLS_README.gz in the postfix-doc package for
    # information on enabling SSL in the smtp client.

    myhostname = vagrant-ubuntu-precise-64
    alias_maps = hash:/etc/aliases
    alias_database = hash:/etc/aliases
    mydestination = ofn_development, vagrant-ubuntu-precise-64, localhost.localdomain, localhost
    relayhost =
    mynetworks = 127.0.0.0/8 [::ffff:127.0.0.0]/104 [::1]/128
    mailbox_size_limit = 0
    recipient_delimiter = +
    inet_interfaces = all
    inet_protocols = all

Configured as documented in link. Log file /var/log/mail.log shows:

Sep 27 04:47:22 vagrant-ubuntu-precise-64 postfix/smtp[15421]: 60091C269F: to=<mike@madhappy.com>, 
relay=none, delay=1.4, delays=0/0/1.4/0, dsn=4.4.1, status=deferred (connect to 
smtp.gmail.com[2607:f8b0:4002:c06::6c]:587: Network is unreachable)

SO, we need to test our connection with telnet: telnet gmail-smtp-in.l.google.com 25… And we can’t connect, which likely means our Internet Service Provider is blocking, and I need to use it’s SMTP server. Fuck. Or maybe not! Uverse blocks port 25 by default but apparently you can ask them to unblock it.

After the ISP unblocked port 25 getting Gmail Authentication errors. Experimenting with enabling Less secure apps at bottom of this page, and dealing with the Unlock Captcha. There tech support is really good, but still struggling…

Finally managed to get past all the gmail SMTP issues by insuring that the gmail app settings were set to “allow less secure apps”.

Still haven’t found a workaround for losing the port number on links and form actions. Decided to look back at the basic install instructions for OpenFoodNetwork, which states to “Prepare the test database using bundle exec rake db:test:prepare, then tests can be run with bundle exec rspec spec“. However I believe that overwrote at least the admin account that Ansible had created based on the vars.yml configuration, as my user credentials stopped working. Dug around in the code and somewhere between models/spree and spec/models/spree, discovered that there’s a Spree.User object. Opened to rails console and called:

Spree::User.find_all_by_id([0..10]), which returned an empty set.

Probably could have done something like u = Spree::User.create :userid => "myuserid", :password => "mypasswd", :user_first_name => "test", :user_last_name => "testovich", :user_status => "mystatus", :user_type => "mytype" and @u.save!, but ended up doing a Vagrant destroy and Vagrant up --provision and was able to log back in again. Then had to install (and configure) mail again. At least the google app settings are still correctly configured. Now Spree::User.find_all_by_id([0..10]) returns the user as defined in the Ansible config file (vars.yml).

But wait! After running bundle exec rspec spec, Spree::User.find_all_by_id([0..10]) is returning an empty set again. And the credentials are invalid. Now we can try adding a user via the console: bundle exec rake spree_auth:admin:create. That was so easy. I’m glad we’re using spree_auth_devise!

Considering reinstalling Zues, which I had installed prior to realizing that the user credentials had been deleted.

(PS – it also appears the en/US translation files are missing)