From 8211e5d3afc0667c92a74bde5e185da13a84331d Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 9 May 2016 14:11:49 -0700 Subject: [PATCH 1/5] first pass at getting vagrant/ansible working for prod --- .../{celerybeat.conf => celerybeat_prod.conf} | 0 deploy/{celeryd.conf => celeryd_prod.conf} | 0 deploy/setup-just.sh | 3 + deploy/setup-please.sh | 3 + deploy/setup-prod.sh | 3 + requirements_versioned.pip | 1 + vagrant/Vagrantfile | 56 +++++++++++++++++++ vagrant/dev.yml | 17 +++++- 8 files changed, 82 insertions(+), 1 deletion(-) rename deploy/{celerybeat.conf => celerybeat_prod.conf} (100%) rename deploy/{celeryd.conf => celeryd_prod.conf} (100%) create mode 100644 deploy/setup-just.sh create mode 100644 deploy/setup-please.sh create mode 100644 deploy/setup-prod.sh diff --git a/deploy/celerybeat.conf b/deploy/celerybeat_prod.conf similarity index 100% rename from deploy/celerybeat.conf rename to deploy/celerybeat_prod.conf diff --git a/deploy/celeryd.conf b/deploy/celeryd_prod.conf similarity index 100% rename from deploy/celeryd.conf rename to deploy/celeryd_prod.conf diff --git a/deploy/setup-just.sh b/deploy/setup-just.sh new file mode 100644 index 00000000..216f7a8c --- /dev/null +++ b/deploy/setup-just.sh @@ -0,0 +1,3 @@ +cd /opt/regluit +source ENV/bin/activate +export DJANGO_SETTINGS_MODULE=regluit.settings.just diff --git a/deploy/setup-please.sh b/deploy/setup-please.sh new file mode 100644 index 00000000..0815d361 --- /dev/null +++ b/deploy/setup-please.sh @@ -0,0 +1,3 @@ +cd /opt/regluit +source ENV/bin/activate +export DJANGO_SETTINGS_MODULE=regluit.settings.please diff --git a/deploy/setup-prod.sh b/deploy/setup-prod.sh new file mode 100644 index 00000000..ae3230c7 --- /dev/null +++ b/deploy/setup-prod.sh @@ -0,0 +1,3 @@ +cd /opt/regluit +source ENV/bin/activate +export DJANGO_SETTINGS_MODULE=regluit.settings.prod diff --git a/requirements_versioned.pip b/requirements_versioned.pip index f852b7f2..a726cf4b 100644 --- a/requirements_versioned.pip +++ b/requirements_versioned.pip @@ -13,6 +13,7 @@ WebOb==1.2.3 WebTest==1.4.0 amqplib==1.0.2 anyjson==0.3.3 +awscli==1.10.26 billiard==2.7.3.12 boto==2.8.0 #git+ssh://git@github.com/Gluejar/boto.git@2.3.0 diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile index fe5e0a97..d3ba7909 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/Vagrantfile @@ -188,7 +188,63 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end + config.vm.define "prod" do |node| + + node.vm.box = "ubuntu/trusty64" + node.vm.network "private_network", type: "dhcp" + #node.vm.network "private_network", ip: "192.168.33.10" + + node.ssh.forward_agent = true + + node.vm.provision 'ansible' do |ansible| + ansible.playbook = 'dev.yml' + ansible.verbose = "vv" + # ansible.inventory_path = '.vagrant/provisioners/ansible/inventory/' + ansible.raw_arguments = [ + "--inventory-file=.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory", + "--limit=prod,127.0.0.1", + "-e vname=prod", + "-e class=prod", + "-e hostname=unglue.it", + "-e setdns=false", + "-e do_migrate=true", + "-e branch=sysadmin" + ] + + end + + node.vm.provider "virtualbox" do |v| + v.memory = 1024 + v.cpus = 2 + end + + node.vm.provider :aws do |aws, override| + aws.access_key_id = ENV['AWS_ACCESS_KEY_ID'] + aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] + + aws.keypair_name = "ry-laptop" + + # Ubuntu 12.04 LTS Precise / PV EBS-SSD boot + # alestic 2015.05.05 + + aws.instance_type="c1.medium" + + aws.region = "us-east-1" + aws.availability_zone = "us-east-1c" + aws.ami = "ami-d8132bb0" + aws.security_groups = ["web-production"] + + aws.tags = { + 'Name' => 'prod_vagrant' + } + + override.vm.box = "dummy" + override.ssh.username = "ubuntu" + override.ssh.private_key_path = "/Users/raymondyee/.ssh/id_rsa" + end + + end config.vm.define "localvm" do |node| diff --git a/vagrant/dev.yml b/vagrant/dev.yml index f988ebc6..b3e85dea 100644 --- a/vagrant/dev.yml +++ b/vagrant/dev.yml @@ -5,6 +5,7 @@ aws_secret_key: "{{ lookup('env','AWS_SECRET_ACCESS_KEY') }}" target: '{{vname}}' dev_ssh_host: "{{ hostvars[target]['ansible_ssh_host'] }}" + migrate: "{{do_migrate | default('true')}}" tasks: @@ -119,7 +120,7 @@ args: github_auth_key: "{{github_auth_key}}" repo_name: Gluejar/regluit - key_name: "{{hostname}} {{ ansible_date_time.date }}" + key_name: "{{hostname}} {{ ansible_date_time.iso8601 }}" key_path: /home/{{user}}/.ssh/id_rsa.pub - name: postfix install @@ -218,6 +219,8 @@ #run('django-admin.py syncdb --migrate --noinput --settings regluit.settings.please') #Run syncdb on the application + # TO DO: syncdb might be deprecated + # http://stackoverflow.com/a/29683785 - name: django syncdb django_manage: > @@ -225,6 +228,7 @@ app_path=/opt/regluit/ settings="regluit.settings.{{class}}" virtualenv=/opt/regluit/ENV + when: migrate notify: - restart apache2 @@ -234,6 +238,7 @@ app_path=/opt/regluit/ settings="regluit.settings.{{class}}" virtualenv=/opt/regluit/ENV + when: migrate notify: - restart apache2 @@ -423,6 +428,16 @@ state=present when: class in ['just'] + - name: set up script file to load environment for interactive use + command: cp "/opt/regluit/deploy/setup-{{class}}.sh" /home/{{user}}/setup.sh + + - name: set up script to dump database + command: cp "/opt/regluit/deploy/dump_db_{{class}}.sh" /home/{{user}}/dump.sh + when: class in ['prod'] + + - name: put an empty file in main dir to help identify this instance + command: touch "/home/{{user}}/{{class}}_{{ ansible_date_time.iso8601 }}" + handlers: - name: restart apache2 From 3f9a7b15e5a3ba219a017ff8ec5565170601666a Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 9 May 2016 14:26:24 -0700 Subject: [PATCH 2/5] define migrate --- vagrant/dev.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/vagrant/dev.yml b/vagrant/dev.yml index b3e85dea..e378c4a0 100644 --- a/vagrant/dev.yml +++ b/vagrant/dev.yml @@ -5,8 +5,6 @@ aws_secret_key: "{{ lookup('env','AWS_SECRET_ACCESS_KEY') }}" target: '{{vname}}' dev_ssh_host: "{{ hostvars[target]['ansible_ssh_host'] }}" - migrate: "{{do_migrate | default('true')}}" - tasks: - name: print dev_ssh_host @@ -43,6 +41,7 @@ aws_access_key: "{{ lookup('env','AWS_ACCESS_KEY_ID') }}" aws_secret_key: "{{ lookup('env','AWS_SECRET_ACCESS_KEY') }}" target: '{{vname}}' + migrate: "{{do_migrate | default('true')}}" sudo: yes pre_tasks: From 1699c8af7d67b97ff04d74e57420780b5e6fd3f5 Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 9 May 2016 14:32:58 -0700 Subject: [PATCH 3/5] add dump_db_prod.sh --- deploy/dump_db_prod.sh | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 deploy/dump_db_prod.sh diff --git a/deploy/dump_db_prod.sh b/deploy/dump_db_prod.sh new file mode 100644 index 00000000..5d0c6f4c --- /dev/null +++ b/deploy/dump_db_prod.sh @@ -0,0 +1,2 @@ +#!/bin/sh +mysqldump -h production.cboagmr25pjs.us-east-1.rds.amazonaws.com -u root --password=unglue1t --ignore-table=unglueit.core_key unglueit From 7d6c57dfa8557b14cf7cb3ba1e87720f14c9397e Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 9 May 2016 14:48:50 -0700 Subject: [PATCH 4/5] prod2 added to Vagrantfile --- vagrant/Vagrantfile | 63 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 61 insertions(+), 2 deletions(-) diff --git a/vagrant/Vagrantfile b/vagrant/Vagrantfile index d3ba7909..9720003a 100644 --- a/vagrant/Vagrantfile +++ b/vagrant/Vagrantfile @@ -188,7 +188,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end - config.vm.define "prod" do |node| + config.vm.define "prod" do |node| node.vm.box = "ubuntu/trusty64" node.vm.network "private_network", type: "dhcp" @@ -209,7 +209,7 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| "-e hostname=unglue.it", "-e setdns=false", "-e do_migrate=true", - "-e branch=sysadmin" + "-e branch=production" ] end @@ -246,6 +246,65 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| end + config.vm.define "prod2" do |node| + + node.vm.box = "ubuntu/trusty64" + node.vm.network "private_network", type: "dhcp" + #node.vm.network "private_network", ip: "192.168.33.10" + + + node.ssh.forward_agent = true + + node.vm.provision 'ansible' do |ansible| + ansible.playbook = 'dev.yml' + ansible.verbose = "vv" + # ansible.inventory_path = '.vagrant/provisioners/ansible/inventory/' + ansible.raw_arguments = [ + "--inventory-file=.vagrant/provisioners/ansible/inventory/vagrant_ansible_inventory", + "--limit=prod,127.0.0.1", + "-e vname=prod", + "-e class=prod", + "-e hostname=unglue.it", + "-e setdns=false", + "-e do_migrate=true", + "-e branch=production" + ] + + end + + node.vm.provider "virtualbox" do |v| + v.memory = 1024 + v.cpus = 2 + end + + node.vm.provider :aws do |aws, override| + aws.access_key_id = ENV['AWS_ACCESS_KEY_ID'] + aws.secret_access_key = ENV['AWS_SECRET_ACCESS_KEY'] + + aws.keypair_name = "ry-laptop" + + # Ubuntu 12.04 LTS Precise / PV EBS-SSD boot + # alestic 2015.05.05 + + aws.instance_type="c1.medium" + + aws.region = "us-east-1" + aws.availability_zone = "us-east-1c" + aws.ami = "ami-d8132bb0" + aws.security_groups = ["web-production"] + + aws.tags = { + 'Name' => 'prod_vagrant' + } + + override.vm.box = "dummy" + override.ssh.username = "ubuntu" + override.ssh.private_key_path = "/Users/raymondyee/.ssh/id_rsa" + end + + end + + config.vm.define "localvm" do |node| node.vm.box = "ubuntu/precise64" From c0afa2cc9556e061fa665b493d192c9bf11f22ee Mon Sep 17 00:00:00 2001 From: Raymond Yee Date: Mon, 9 May 2016 14:52:46 -0700 Subject: [PATCH 5/5] fix output log for prod.conf: switch from logrotate to cronolog --- deploy/prod.conf | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/deploy/prod.conf b/deploy/prod.conf index b6860b99..e76d39c1 100644 --- a/deploy/prod.conf +++ b/deploy/prod.conf @@ -51,9 +51,8 @@ BrowserMatch "MSIE [2-6]" \ # MSIE 7 and newer should be able to use keepalive BrowserMatch "MSIE [17-9]" ssl-unclean-shutdown -ErrorLog ${APACHE_LOG_DIR}/unglue.it-ssl-error.log +ErrorLog "|/usr/bin/cronolog /var/log/apache2/%Y%m%d_error.log" LogLevel warn -CustomLog ${APACHE_LOG_DIR}/unglue.it-ssl-access.log combined - +CustomLog "|/usr/bin/cronolog /var/log/apache2/%Y%m%d_access.log" combined \ No newline at end of file