- Crear máquina virtual en http://manage.windowsazure.com
- Crear usuario theteam en http://portal.azure.com
- Mediante Reset-password, se escribe user theteam y contraseña deseada
- Configurar ENDPOINTS (Puertos)
| Name | Protocol | Public Port | Private Port |
|---|---|---|---|
| SSH | TCP | 22 | 22 |
| HTTP | TCP | 80 | 3000 |
| PostgreSQL | TCP | 5432 | 5432 |
- Conectar a la máquina virtual
- Configurar la contraseña deseada anterior como ssh public key o en su defecto utilizar el siguiente código para evitar colocar la contraseña en cada conexión futura mediante ssh:
ssh-copy-id theteam@apuntate.cloudapp.net
ssh theteam@apuntate.cloudapp.netsu theteampara cambiar de usuariosudo apt-get updatepara comenzar la actualización- Corregir locale
sudo nano /etc/environment- Agregar linea
LC_ALL="en_US.UTF-8"al archivo - Reiniciar máquina virtual en http://manage.windowsazure.com
sudo dpkg-reconfigure localespara verificar que se logró correctamente- Instalar ruby mediante .rbenv
sudo apt-get install git-core curl zlib1g-dev build-essential libssl-dev libreadline-dev libyaml-dev libsqlite3-dev sqlite3 libxml2-dev libxslt1-dev libcurl4-openssl-dev python-software-properties libffi-dev[LENTO]
cdgit clone git://github.com/sstephenson/rbenv.git .rbenvecho 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bashrcecho 'eval "$(rbenv init -)"' >> ~/.bashrcexec $SHELLgit clone git://github.com/sstephenson/ruby-build.git ~/.rbenv/plugins/ruby-buildecho 'export PATH="$HOME/.rbenv/plugins/ruby-build/bin:$PATH"' >> ~/.bashrcexec $SHELLgit clone https://github.com/sstephenson/rbenv-gem-rehash.git ~/.rbenv/plugins/rbenv-gem-rehashrbenv install 2.2.0[MUUUUY LENTO - coffee time?]rbenv global 2.2.0ruby -vPara verificar instalación- Evitar documentaciones al instalar gemas
- echo "gem: --no-ri --no-rdoc" > ~/.gemrc
- Instalar Nginx
sudo apt-get updatesudo apt-get install curl git-core nginx -y- Instalar PostgreSQL 9.3
psql --versionVerificar que no está instaladosudo apt-get install postgresql-9.3sudo -u postgres psql postgresPara verificar instalación. Para salir:\q- Configurar PostgreSQL
sudo -u postgres createuser --superuser theteamsudo -u postgres psql- postgres=#
\password theteampara setear contraseña
- Crear base de datos production??
- Instalar gemas de rails y bundler
gem install rails[LENTO]gem install bundler- Setear conexión ssh a la repo
ssh -T git@github.com- Handshake (Está bien recibir unPermission denied (publickey))ssh-keygen -t rsa(Dejar todas las opciones en blanco)nano ~/.ssh/id_rsa.pubcopiar texto al ssh keys de la cuenta en github- clonar app
git clone #ssh-repo-url- Preparar App
- utilizar
cd theteampara poscicionarse en el directorio de la app clonada sudo apt-get install libpq-devPara poder instalar gema postgresbundle installsudo apt-get install nodejsPara poder realizar varias funciones de rails- Confirmar datos y configuraciones de puma y pg
- Verificar que las gemas puma y pg están en Gemfile
- Verificar variables para username y password en production en database.yml
- Configurar puma con texto de /home/USER/APP/config/puma.rb (Crear archivo) con el siguiente texto (REEMPLAZAR workers 1 POR EL NUMERO DE NUCLEOS del server!!):
# Change to match your CPU core count
workers 1
# Min and Max threads per worker
threads 1, 6
app_dir = File.expand_path("../..", __FILE__)
shared_dir = "#{app_dir}/shared"
# Default to production
rails_env = ENV['RAILS_ENV'] || "production"
environment rails_env
# Set up socket location
bind "unix://#{shared_dir}/sockets/puma.sock"
# Logging
stdout_redirect "#{shared_dir}/log/puma.stdout.log", "#{shared_dir}/log/puma.stderr.log", true
# Set master PID and state locations
pidfile "#{shared_dir}/pids/puma.pid"
state_path "#{shared_dir}/pids/puma.state"
activate_control_app
on_worker_boot do
require "active_record"
ActiveRecord::Base.connection.disconnect! rescue ActiveRecord::ConnectionNotEstablished
ActiveRecord::Base.establish_connection(YAML.load_file("#{app_dir}/config/database.yml")[rails_env])
end
-
Obtener secret key del developer computer (?)
-
EN LA COMPUTADORA DEVELOPER ejecutar en el directorio de la app
rake secrety guardar key -
Create Puma Upstart script
-
cd ~ -
wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma-manager.conf -
wget https://raw.githubusercontent.com/puma/puma/master/tools/jungle/upstart/puma.conf -
nano puma.conf -
Reemplazar:
setuid *apps* setgid *apps*Por:
setuid theteam setgid theteamY EN EL MISMO ARCHIVO AGREGAR justo debajo de
exec /bin/bash <<'EOT'el siguiente código (REEMPLAZAR CONTRASEÑA Y SECRET KEY):export THETEAM_DATABASE_USER='theteam' export THETEAM_DATABASE_PASSWORD='LA_CONTRASEÑA!' export SECRET_KEY_BASE='LA_SECRET_KEY_GENERADA_ARRIBA!'Salir y guardar el archivo y sus cambios.
-
Copiar los scripts al directorio init
-
sudo cp puma.conf puma-manager.conf /etc/init -
Crear y configurar archivo etc/puma.conf
-
sudo nano /etc/puma.conf -
Escribir
/home/theteam/theteam -
Salir y guardar cambios
-
Configurar Nginx
-
sudo nano /etc/nginx/sites-available/default -
Reemplazar/borrar todo y escribir: (Notar texto específico [...]theteam/theteam/[...] en dos casos)
upstream app { # Path to Puma SOCK file, as defined previously server unix:/home/theteam/theteam/shared/sockets/puma.sock fail_timeout=0; } server { listen 80; server_name localhost; root /home/theteam/theteam/public; try_files $uri/index.html $uri @app; location @app { proxy_pass http://app; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header Host $http_host; proxy_redirect off; } error_page 500 502 503 504 /500.html; client_max_body_size 4G; keepalive_timeout 10; } -
Guardar y salir
-
Preparar producción git
-
mkdir ~/theteam_production -
cd ~/theteam_production -
git init --bare -
Git hook script
-
nano hooks/post-receive -
Escribir en el archivo (CAMBIAR LA CONTRASEÑA!!):
#!/bin/bash GIT_DIR=/home/theteam/theteam_production WORK_TREE=/home/theteam/theteam export THETEAM_DATABASE_USER='theteam' export THETEAM_DATABASE_PASSWORD='LA_CONTRASEÑA!!' export RAILS_ENV=production . ~/.bash_profile while read oldrev newrev ref do if [[ $ref =~ .*/master$ ]]; then echo "Master ref received. Deploying master branch to production..." mkdir -p $WORK_TREE git --work-tree=$WORK_TREE --git-dir=$GIT_DIR checkout -f mkdir -p $WORK_TREE/shared/pids $WORK_TREE/shared/sockets $WORK_TREE/shared/log # start deploy tasks cd $WORK_TREE $HOME/.rbenv/shims/bundle install $HOME/.rbenv/shims/rake db:create $HOME/.rbenv/shims/rake db:migrate $HOME/.rbenv/shims/rake assets:precompile sudo service puma-manager restart sudo service nginx restart # end deploy tasks echo "Git hooks deploy complete" else echo "Ref $ref successfully received. Doing nothing: only the master branch may be deployed on this server." fi done ``` -
Guardar y salir
-
Hacer el script ejecutable
-
chmod +x hooks/post-receive -
sudo sh -c 'echo "theteam ALL=(ALL) NOPASSWD:ALL" > /etc/sudoers.d/90-deploy'para no requerir contraseña con el sudo el user theteam al ejecutar comandos dentro del script (O cualquier comando)
LISTO!! En developer machine:
git remote add production theteam@apuntate.cloudapp.net:theteam_productiongit push production master