Skip to content

DO NOT MERGE: Docker compose for development and deploy #62

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 22 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
ce92720
Prepare rails configuration/secrets for running in Docker
gnucifer Dec 16, 2019
7971639
Fix ember configuration so can be run with docker compose
gnucifer Jan 8, 2020
1983b66
Revert ember-cli-rails
gnucifer Jan 9, 2020
27b8620
Add solr config
gnucifer Jan 13, 2020
f804d7c
Add docker stuff
gnucifer Jan 15, 2020
d5d85f4
Get development docker-compose in some kind of working state
gnucifer Jan 16, 2020
3db4237
Add help script for running in deploy/production mode
gnucifer Jan 16, 2020
e21df8c
Tidy up and add ready baked posgres image for deployment without mounts
gnucifer Jan 17, 2020
f81f85f
Add ansible playbook for deploy
gnucifer Jan 24, 2020
77c2f48
Add lab to environment.js
gnucifer Jan 27, 2020
2206b07
Fix previously screwed up renaming from GUP_SERVICE_PORT to GUP_BACKE…
gnucifer Jan 27, 2020
e817dc3
Fix variable scope screw up for lab environment
gnucifer Jan 27, 2020
6541119
Add missing environment variables in ansible deploy playbook
gnucifer Jan 29, 2020
563c44a
Add build help scripts
gnucifer Jan 29, 2020
e7a2fb1
Add rails rake migration task in deploy playbook
gnucifer Jan 30, 2020
4dad6c4
Set entpoint_mode to dnsrr so that list of all service ips are expose…
gnucifer Jul 22, 2020
15bb6a8
Set FQDN for lab, use DNS for service discovery instead of ip
gnucifer Jul 22, 2020
d6a03cf
Namespace stacks per deploy enviroment
gnucifer Jul 23, 2020
9b4a88e
Fix endpoint_mode
gnucifer Jul 23, 2020
f71aa94
Strip full path from inventory_file
gnucifer Jul 23, 2020
79ed29f
Use overlay network for haproxy, remove exposed ports and set correct…
gnucifer Jul 24, 2020
b17fb6e
Fix migrations container network name
gnucifer Sep 7, 2020
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 28 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@

# Ignore all logfiles and tempfiles.
/log/*.log
/tmp
tmp

config/database.yml
*~
\#*#
.#*
Expand All @@ -24,13 +23,9 @@ config/database.yml
# Ignore Aptana .project files.
.project

# Ignore all vim and vi backup files.
*.sw*

#Ignore nbproject
nbproject/

config/config_secret.yml
config/passwd
config/deploy.yml
# Ignore generated css etc.
Expand All @@ -51,3 +46,30 @@ doc/app/
#Ignore code climate coverage directory
/coverage

#Ignore database dumps
*.sql.gz

## VIM:

# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~

# Remove this later and replace with ansible vault variables instead
ansible/vars/docker_credentials.yml
4 changes: 1 addition & 3 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ group :test do
gem 'webmock'
end

gem "ember-cli-rails"

gem "codeclimate-test-reporter", group: :test, require: nil
gem 'rack-cors'

Expand All @@ -47,4 +45,4 @@ gem 'rsolr'
gem 'will_paginate', '~> 3.0.5'
gem 'spreadsheet'
gem 'oai'
gem 'naturalsort', :require => 'natural_sort_kernel'
gem 'naturalsort', :require => 'natural_sort_kernel'
11 changes: 0 additions & 11 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,6 @@ GEM
capistrano-rvm (0.1.2)
capistrano (~> 3.0)
sshkit (~> 1.2)
climate_control (0.2.0)
cocaine (0.5.8)
climate_control (>= 0.0.3, < 1.0)
codeclimate-test-reporter (1.0.8)
simplecov (<= 0.13)
concurrent-ruby (1.0.5)
Expand All @@ -71,12 +68,6 @@ GEM
docile (1.1.5)
domain_name (0.5.20170404)
unf (>= 0.0.5, < 1.0.0)
ember-cli-rails (0.10.0)
cocaine (~> 0.5.8)
ember-cli-rails-assets (~> 0.6.2)
html_page (~> 0.1.0)
railties (>= 3.2)
ember-cli-rails-assets (0.6.2)
erubis (2.7.0)
factory_girl (4.9.0)
activesupport (>= 3.0.0)
Expand All @@ -90,7 +81,6 @@ GEM
globalid (0.4.1)
activesupport (>= 4.2.0)
hashdiff (0.3.7)
html_page (0.1.0)
http-cookie (1.0.3)
domain_name (~> 0.5)
i18n (0.9.3)
Expand Down Expand Up @@ -233,7 +223,6 @@ DEPENDENCIES
capistrano-rvm
codeclimate-test-reporter
database_cleaner
ember-cli-rails
factory_girl_rails (~> 4.0)
jbuilder (~> 2.0)
mime-types (< 3.0)
Expand Down
120 changes: 120 additions & 0 deletions ansible/deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
---
- hosts: gup_deploy_swarm_managers
become: true
vars_files:
- vars/docker_credentials.yml # Replace with vault variables
tasks:
- name: Log into Docker
docker_login:
registry: docker.ub.gu.se
username: "{{ ub__docker_username }}"
password: "{{ ub__docker_password }}"
state: present
reauthorize: yes
debug: yes

# Variable for gup-docker-deploy?
- name: Ensure remote working directory exists
file:
path: /opt/gup-docker-deploy
state: directory

- name: Copy compose files to server
copy:
src: "{{ playbook_dir }}/../docker/{{ item }}"
dest: "/opt/gup-docker-deploy/{{ item }}"
loop:
- docker-compose.yml
- docker-compose.deploy.yml

- name: Ensure database initialization directory exists
file:
path: /opt/gup-docker-deploy/postgres-initdb.d
state: directory

- name: Copy database dump if exists
copy: src="{{ item }}" dest=/opt/gup-docker-deploy/postgres-initdb.d
with_fileglob: postgres-initdb.d/*.gz

# Revisions log instead
- name: Get local username from whoami
become: false
local_action: command whoami
register: local_username_result

- name: Set local username fact
set_fact:
deploy_local_username: "{{ local_username_result.stdout }}"

- name: Set target deploy stage name
set_fact:
stage_name: "{{ inventory_file | basename | splitext | first }}"

- name: Copy deploy .env file to server
template:
src: deploy_env.j2
dest: "/opt/gup-docker-deploy/.env"

- name: Deploy container stack from compose file
environment:
GIT_REVISION: "{{ deploy_git_revision }}"
docker_stack:
state: present
with_registry_auth: yes
name: "{{ 'gup_' ~ stage_name }}"
compose:
- /opt/gup-docker-deploy/docker-compose.yml
- /opt/gup-docker-deploy/docker-compose.deploy.yml
- version: '3.7'
services:
frontend:
environment:
- "EMBER_ENVIRONMENT={{ stage_name }}"
- "GUP_SERVICE_PORT={{ gup_backend_port }}"
# ports:
# - "{{ gup_frontend_port }}:8080"
backend:
environment:
- "GUP_ENVIRONMENT={{ stage_name }}"
- "GUP_DB={{ gup_db }}"
- "GUP_DB_USER={{ gup_db_user }}"
- "GUP_DB_PASSWORD={{ gup_db_password }}"
- "GUP_SCOPUS_API_KEY={{ gup_scopus_api_key }}"
- "GUP_MQ_API_KEY={{ gup_mq_api_key }}"
- "GUP_SECRET_KEY_BASE={{ gup_secret_key_base }}"
# ports:
# - "{{ gup_backend_port }}:3000"
solr:
environment:
- "GUP_SOLR_DATA_IMPORT_DB_URL=jdbc:postgresql://db:5432/{{ gup_db }}"
- "GUP_SOLR_DATA_IMPORT_DB_USER={{ gup_db_user }}"
- "GUP_SOLR_DATA_IMPORT_DB_PASSWORD={{ gup_db_password }}"
# ports:
# - "{{ gup_solr_port }}:8983"
db:
environment:
- "POSTGRES_DB={{ gup_db }}"
- "POSTGRES_USER={{ gup_db_user}}"
- "POSTGRES_PASSWORD={{ gup_db_password }}"

- name: Run rails migrations
docker_container:
name: gup_db_migrate
image: "docker.ub.gu.se/gup-backend:{{ deploy_git_revision }}"
command: "rake db:migrate"
env:
RAILS_ENV: "{{ stage_name }}" # RAILS_ENV instead of GUP_ENVIRONMENT for rake
GUP_DB: "{{ gup_db }}"
GUP_DB_USER: "{{ gup_db_user }}"
GUP_DB_PASSWORD: "{{ gup_db_password }}"
GUP_SECRET_KEY_BASE: "{{ gup_secret_key_base }}"
state: started
auto_remove: no
detach: no
cleanup: yes
networks:
- name: "{{ 'gup_' ~ stage_name ~ '_backend' }}"
register: rails_db_migrate_result

- debug:
var: rails_db_migrate_result.ansible_facts.docker_container.Output
4 changes: 4 additions & 0 deletions ansible/inventory/group_vars/all
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
---
gup_solr_port: 8989
gup_frontend_port: 8181
gup_backend_port: 3111
17 changes: 17 additions & 0 deletions ansible/inventory/lab.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
all:
hosts:
utv02:
ansible_host: 130.241.35.164
ansible_user: dockeruser
children:
gup_deploy_swarm_managers:
hosts:
utv02:
vars:
deploy_git_revision: docker-friendly-config-v1
gup_db: gup_db
gup_db_user: gup_user
gup_db_password: gup_pass
gup_scopus_api_key: <scopus_key>
gup_mq_api_key: <mq_key>
gup_secret_key_base: 29f01727314845cd7351aace2c4453e28cb95089dadafb49e299e5750e382c303d483d25c2854832fe274d6d27e09442fce906c2621e311ff650fd79644c8ea8
2 changes: 2 additions & 0 deletions ansible/templates/deploy_env.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
GIT_REVISION={{ deploy_git_revision }}
DEPLOYED_BY={{ deploy_local_username }}
Empty file added ansible/vars/.gitkeep
Empty file.
53 changes: 53 additions & 0 deletions config/config_secret.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
---
api_key_users:
-
username: "test_key_user"
first_name: "Test"
last_name: "Key User"
role: "API_KEY"
api_key: <%= ENV["GUP_TEST_USER_API_KEY"] %>


external_auth_url: 'https://login-server.ub.gu.se/auth'
journal_index_url: 'http://solr:8983/solr/gup-journals/'
publication_index_url: 'http://solr:8983/solr/gup-publications/'
person_index_url: 'http://solr:8983/solr/gup-people/'
gu_research_index_url: 'http://solr:8983/solr/gup-guresearch/'

file_upload_root_dir: '/data/gup'
sitemaps_dir: '/apps/gup/sitemaps'

datasource_api_keys:
scopus: <%= ENV["GUP_SCOPUS_API_KEY"] %>

mail_settings:
delivery_options:
address: <%= ENV["GUP_MAIL_SMTP_HOST"] %>
port: 25
from_email: <%= ENV["GUP_MAIL_FROM"] %>
to_email: <%= ENV["GUP_MAIL_TO"] %>

public_base_url: <%= ENV["GUP_PUBLIC_BASE_URL"] %>
publication_path: 'publication/'
file_path: 'file/'

university:
name_sv: 'Göteborgs universitet'
name_en: 'Gothenburg University'
repository_name: <%= ENV["GUP_REPOSITORY_NAME"] %>


oai_settings:
max_no_of_records: 100
repository_name: <%= ENV["GUP_OAI_REPOSITORY_NAME"] %>
repository_url: <%= ENV["GUP_OAI_REPOSITORY_URL"] %>
record_prefix: <%= ENV["GUP_OAI_RECORD_PREFIX"] %>
admin_email: '[email protected]'
record_content_source: 'gu'

mq_settings:
enable: true
base_url: <%= ENV["GUP_MQ_BASE_URL"] %>
api_key: <%= ENV["GUP_MQ_API_KEY"] %>

override_file: '/tmp/gup_auth_override.enable'
24 changes: 24 additions & 0 deletions config/database.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
default: &default
host: db
port: 5432
pool: 10
timeout: 5000
adapter: postgresql
encoding: unicode
database: <%= ENV["GUP_DB"] %>
template: template0
username: <%= ENV["GUP_DB_USER"] %>
password: <%= ENV["GUP_DB_PASSWORD"] %>

development:
<<: *default

production:
<<: *default
pool: 100

staging:
<<: *default

lab:
<<: *default
3 changes: 0 additions & 3 deletions config/initializers/ember.rb

This file was deleted.

2 changes: 0 additions & 2 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,5 @@
get "gup/lists/publications/departments/xml/index.xsql" => "guresearch/general#list_publications_special", :defaults => { :param_type => 'departments' }
get "gup/lists/publications/people/xml/index.xsql" => "guresearch/general#list_publications_special", :defaults => { :param_type => 'people' }
get "gup/lists/publications/series/xml/index.xsql" => "guresearch/general#list_publications_special", :defaults => { :param_type => 'series' }

mount_ember_app :frontend, to: "/"
end

6 changes: 3 additions & 3 deletions config/secrets.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ test:
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_key_base: <%= ENV["GUP_SECRET_KEY_BASE"] %>

lab:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_key_base: <%= ENV["GUP_SECRET_KEY_BASE"] %>

staging:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
secret_key_base: <%= ENV["GUP_SECRET_KEY_BASE"] %>
19 changes: 0 additions & 19 deletions docker-compose.yml

This file was deleted.

Loading