diff --git a/access/.gitignore b/access/.gitignore index b76cc3b..929162b 100644 --- a/access/.gitignore +++ b/access/.gitignore @@ -18,6 +18,7 @@ pickle-email-*.html # TODO Comment out these rules if you are OK with secrets being uploaded to the repo config/initializers/secret_token.rb config/secrets.yml +config/database.yml ## Environment normalisation: /.bundle @@ -35,4 +36,4 @@ config/secrets.yml bower.json # Ignore pow environment settings -.powenv \ No newline at end of file +.powenv diff --git a/access/Gemfile b/access/Gemfile index 9b7afc4..c2eca55 100644 --- a/access/Gemfile +++ b/access/Gemfile @@ -3,8 +3,7 @@ source 'https://rubygems.org' # Bundle edge Rails instead: gem 'rails', github: 'rails/rails' gem 'rails', '4.2.4' -# Use sqlite3 as the database for Active Record -gem 'sqlite3' +# Use postgresql as the database for Active Record gem 'pg' # Use SCSS for stylesheets gem 'sass-rails', '~> 5.0' diff --git a/access/Gemfile.lock b/access/Gemfile.lock index 9815ca0..7cfdfe0 100644 --- a/access/Gemfile.lock +++ b/access/Gemfile.lock @@ -155,7 +155,6 @@ GEM actionpack (>= 3.0) activesupport (>= 3.0) sprockets (>= 2.8, < 4.0) - sqlite3 (1.3.11) thor (0.19.1) thread_safe (0.3.5) tilt (2.0.1) @@ -192,7 +191,6 @@ DEPENDENCIES simplecov simplecov-rcov spring - sqlite3 turbolinks uglifier (>= 1.3.0) web-console (~> 2.0) diff --git a/access/config/database.yml b/access/config/database.yml deleted file mode 100644 index 260c514..0000000 --- a/access/config/database.yml +++ /dev/null @@ -1,26 +0,0 @@ -# SQLite version 3.x -# gem install sqlite3 -# -# Ensure the SQLite 3 gem is defined in your Gemfile -# gem 'sqlite3' -# - default: &default - adapter: sqlite3 - pool: 5 - timeout: 5000 - - development: - <<: *default - database: db/development.sqlite3 - - # Warning: The database defined as "test" will be erased and - # re-generated from your development database when you run "rake". - # Do not set this db to the same as development or production. - test: - <<: *default - database: db/test.sqlite3 - - production: - <<: *default - database: db/production.sqlite3 - diff --git a/ansible/group_vars/database-servers b/ansible/group_vars/database-servers index 7150ad8..8d6dde4 100644 --- a/ansible/group_vars/database-servers +++ b/ansible/group_vars/database-servers @@ -1,3 +1,14 @@ +db_username: access db_password: some_password_here -db_name: access-db -db_username: access \ No newline at end of file +production: + name: production + db_type: postgresql + db_name: access-db +development: + name: development + db_type: sqlite3 + db_name: db/development.sqlite3 +test: + name: test + db_type: postgresql + db_name: access-db-test diff --git a/ansible/roles/access/tasks/main.yml b/ansible/roles/access/tasks/main.yml index bd794d0..e3916f0 100644 --- a/ansible/roles/access/tasks/main.yml +++ b/ansible/roles/access/tasks/main.yml @@ -25,13 +25,16 @@ service: name=httpd state=restarted enabled=yes - name: Copy secrets.yml - template: src=config/secrets.yml.j2 dest={{application_path}}/access/config/secrets.yml + template: src=config/secrets.yml.j2 dest={{ application_path }}/access/config/secrets.yml owner={{ application_user }} group={{ application_user }} mode=0644 notify: restart apache tags: install_access -- name: restart apache - service: name=httpd state=restarted enabled=yes +- name: Copy database.yml + template: src=config/database.yml.j2 dest={{ application_path }}/access/config/database.yml + owner={{ application_user }} group={{ application_user }} mode=0640 + notify: restart apache + tags: install_access ########################################################## ############ Change owner of the application ############ @@ -76,7 +79,7 @@ ########### Rake db tasks ########### ##################################### - name: rake db:migrate - shell: bash -lc "rake db:migrate" chdir="{{ application_path }}/access" + shell: bash -lc "rake db:schema:load" chdir="{{ application_path }}/access" tags: - rake_db_tasks @@ -91,13 +94,11 @@ tags: install_access - name: Change owner of database - file: path={{ application_path }}/access/db/development.sqlite3 owner={{ application_user }} - group={{ application_user }} + file: path={{ application_path }}/access/db/development.sqlite3 state=touch + owner={{ application_user }} group={{ application_user }} notify: restart apache tags: install_access - -- name: restart apache - service: name=httpd state=restarted enabled=yes + when: development.db_type == 'sqlite3' # This task is to be run once. If the data have already been seeded and the seed # file has changed, the process of updating has to be done manually. @@ -105,6 +106,3 @@ # shell: bash -lc "rake db:seed" chdir="{{ application_path }}/access" # tags: # - rake_db_tasks - -# tranfer all the data needed (e.g.database.yml) -# (maybe) run checks diff --git a/ansible/roles/access/templates/config/database.yml.j2 b/ansible/roles/access/templates/config/database.yml.j2 new file mode 100644 index 0000000..e4d24ec --- /dev/null +++ b/ansible/roles/access/templates/config/database.yml.j2 @@ -0,0 +1,14 @@ +{% for env in [production, development, test] %} +{{ env.name }}: + adapter: {{ env.db_type }} + database: {{ env.db_name }} +{% if env.db_type == 'postgresql' %} + encoding: unicode + username: {{ db_username }} + password: {{ db_password }} +{% elif env.db_type == 'sqlite3'%} + pool: 5 + timeout: 5000 +{% endif %} + +{% endfor %} diff --git a/ansible/roles/postgres/tasks/configure.yml b/ansible/roles/postgres/tasks/configure.yml index 43ec8ee..2e3eae0 100644 --- a/ansible/roles/postgres/tasks/configure.yml +++ b/ansible/roles/postgres/tasks/configure.yml @@ -5,16 +5,23 @@ become: yes become_user: postgres tags: postgres_configure - + - name: Enable password authentication for the new user lineinfile: dest=/var/lib/pgsql/data/pg_hba.conf regexp="^local(.)*{{ db_username }}(\s)*md5$" insertbefore="^local(.)*all(\s)*peer$" line="local all {{ db_username }} md5" state=present tags: postgres_configure - + - name: Create access application database - postgresql_db: name={{ db_name }} encoding='UTF-8' owner={{ db_username }} + postgresql_db: name={{ production.db_name }} encoding='UTF-8' owner={{ db_username }} become: yes become_user: postgres - tags: postgres_configure \ No newline at end of file + tags: postgres_configure + +- name: Create access development application database + postgresql_db: name={{ development.db_name }} encoding='UTF-8' owner={{ db_username }} + become: yes + become_user: postgres + tags: postgres_configure + when: development.db_type == 'postgres'