diff --git a/Gemfile.lock b/Gemfile.lock index 83c2acaa..59938a83 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -254,7 +254,7 @@ GEM fog-softlayer (0.3.15) fog-core fog-json - foreman (0.74.0) + foreman (0.75.0) dotenv (~> 0.11.1) thor (~> 0.19.1) formatador (0.2.5) diff --git a/README.md b/README.md index 4e1ceb06..f1ed4751 100644 --- a/README.md +++ b/README.md @@ -32,17 +32,3 @@ Coderwall is built from the following open source components: Plus *lots* of Ruby Gems, a complete list of which is at [/master/Gemfile](https://github.com/assemblymade/coderwall/blob/master/Gemfile). We use [Vagrant](http://www.vagrantup.com/) and [VirtualBox](https://www.virtualbox.org/) to isolate and simplify the local development process. - - -## Copyright / License - -Copyright © 2014, Assembly Made, Inc -All rights reserved. - -Redistribution and use in source and binary forms, with or without modification, are permitted and provided that the following conditions are met: - -* Any redistribution or use is for noncommercial purposes only and is not redistributed or used in connection with any application that is substantially similar to it (Coderwall). -* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. -* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. - -THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OF BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. diff --git a/Vagrantfile b/Vagrantfile index 1fb7f2b6..826272d4 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -10,8 +10,8 @@ puts custom_settings.inspect VAGRANTFILE_API_VERSION = "2" -$box = 'coderwall' -$box_url = 'https://s3.amazonaws.com/coderwall-assets-0/vagrant/coderwall.box' # The box is 1GB. Prepare your +$box = 'coderwall_v2' +$box_url = 'https://s3.amazonaws.com/coderwall-assets-0/vagrant/coderwall_v2.box' # The box is 1.4GB. $provision = 'vagrant/bootstrap.sh' Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| diff --git a/app/assets/images/relic-tee.png b/app/assets/images/relic-tee.png index de83f724..29bf8124 100644 Binary files a/app/assets/images/relic-tee.png and b/app/assets/images/relic-tee.png differ diff --git a/run.bat b/run.bat new file mode 100644 index 00000000..9398339a --- /dev/null +++ b/run.bat @@ -0,0 +1 @@ +vagrant ssh -c ". /home/vagrant/web/vagrant/run" diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..9398339a --- /dev/null +++ b/run.sh @@ -0,0 +1 @@ +vagrant ssh -c ". /home/vagrant/web/vagrant/run" diff --git a/vagrant/bootstrap.sh b/vagrant/bootstrap.sh index ca4a9b77..166b1a5c 100755 --- a/vagrant/bootstrap.sh +++ b/vagrant/bootstrap.sh @@ -1,17 +1,13 @@ #!/bin/bash -x export DEBIAN_FRONTEND=noninteractive -cd /home/vagrant -echo Who am I? You are `whoami`. -echo Where am I? You are in `pwd` -echo I think my home is $HOME -echo export EDITOR=vim >> $HOME/.bashrc -# Enable accessing Postgres from the host machine -apt-get -y install libcurl3 libcurl3-dev libcurl3-gnutls libcurl4-openssl-dev -apt-get -y install libpq-dev -apt-get -y install libxml2 libxml2-dev libxslt1-dev -echo "listen_addresses = '*'" | tee -a /var/pgsql/data/postgresql.conf -echo host all all 0.0.0.0/0 trust | tee -a /var/pgsql/data/pg_hba.conf -sudo su postgres -c 'pg_ctl stop -D /var/pgsql/data 2>&1' -sudo su postgres -c 'pg_ctl start -D /var/pgsql/data 2>&1 &' -su -c "ln -s /vagrant /home/vagrant/web" vagrant -su -c "source /home/vagrant/web/vagrant/user-config.sh" vagrant + +# Ensure the database is started +su -c '/usr/bin/pg_ctl start -l /var/pgsql/data/log/logfile -D /var/pgsql/data' postgres + +sudo su - vagrant <<-'EOF' + cd ~/web + bundle check || bundle install + # Force the app to use the internal Postgres port number and ignore .env + DEV_POSTGRES_PORT=5432 bundle exec rake db:migrate + DEV_POSTGRES_PORT=5432 bundle exec rake db:test:prepare +EOF diff --git a/vagrant/coderwall-box/rebuild.sh b/vagrant/coderwall-box/rebuild.sh new file mode 100755 index 00000000..8922823e --- /dev/null +++ b/vagrant/coderwall-box/rebuild.sh @@ -0,0 +1,11 @@ +cd ~/assemblymade/coderwall +vagrant halt +vagrant destroy -f +vagrant box remove coderwall +cd vagrant/coderwall-box +rm -rf output-virtualbox-iso +rm -rf packer_virtualbox-iso_virtualbox.box +rm -rf packer_cache +packer validate template.json +packer build template.json +vagrant box add coderwall ./packer_virtualbox-iso_virtualbox.box diff --git a/vagrant/coderwall-box/scripts/postinstall.sh b/vagrant/coderwall-box/scripts/postinstall.sh index 152f82f2..d07772dd 100644 --- a/vagrant/coderwall-box/scripts/postinstall.sh +++ b/vagrant/coderwall-box/scripts/postinstall.sh @@ -1,6 +1,61 @@ # postinstall.sh created from Mitchell's official lucid32/64 baseboxes # and then further defaced by just3ws to create the Coderwall devenv +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +echo "Have you set the ENV keys?" +sleep 30 + + set -x date > /etc/vagrant_box_build_time @@ -13,24 +68,87 @@ dpkg-reconfigure --frontend noninteractive tzdata # etc., and remove optional things to trim down the machine. apt-get -y update apt-get -y upgrade -apt-get -y install linux-headers-$(uname -r) build-essential +apt-get -y install linux-headers-$(uname -r) +apt-get -y install build-essential # General dependencies and tools just... mashed, just mashed all together. -apt-get -y install ack-grep autoconf automake bison ca-certificates \ - curl g++ gcc git-core htop iotop libc6-dev libffi-dev \ - libgdbm-dev libncurses5-dev libopenssl-ruby libreadline6 \ - libreadline6-dev libsqlite3-0 libsqlite3-dev libssl-dev \ - libtool libxml2-dev libxslt-dev libyaml-dev make openssl \ - patch pkg-config sqlite3 tmux vim zlib1g zlib1g-dev gawk \ - libxml2-dev curl libcurl4-openssl-dev \ - imagemagick libmagickcore-dev libmagickwand-dev tcl8.5 - -# Install NFS client -apt-get -y install nfs-common portmap - # Apt-install python tools and libraries +# Install NFS client # libpq-dev lets us compile psycopg for Postgres -apt-get -y install python-setuptools python-dev libpq-dev pep8 +apt-get -y install ack-grep +apt-get -y install autoconf +apt-get -y install automake +apt-get -y install bash +apt-get -y install bison +apt-get -y install bzip2 +apt-get -y install ca-certificates +apt-get -y install curl +apt-get -y install g++ +apt-get -y install gawk +apt-get -y install gcc +apt-get -y install git-core +apt-get -y install htop +apt-get -y install imagemagick +apt-get -y install iotop +apt-get -y install libc6-dev +apt-get -y install libcurl3 +apt-get -y install libcurl3-dev +apt-get -y install libcurl3-gnutls +apt-get -y install libcurl4-openssl-dev +apt-get -y install libffi-dev +apt-get -y install libgdbm-dev +apt-get -y install libmagickcore-dev +apt-get -y install libmagickwand-dev +apt-get -y install libncurses5-dev +apt-get -y install libopenssl-ruby +apt-get -y install libpq-dev +apt-get -y install libpq-dev +apt-get -y install libreadline6 +apt-get -y install libreadline6-dev +apt-get -y install libsqlite3-0 +apt-get -y install libsqlite3-dev +apt-get -y install libssl-dev +apt-get -y install libtool +apt-get -y install libxml2 +apt-get -y install libxml2-dev +apt-get -y install libxslt-dev +apt-get -y install libxslt1-dev +apt-get -y install libyaml-dev +apt-get -y install make +apt-get -y install nfs-common +apt-get -y install openssl +apt-get -y install patch +apt-get -y install pep8 +apt-get -y install pkg-config +apt-get -y install portmap +apt-get -y install python-dev +apt-get -y install python-setuptools +apt-get -y install sqlite3 +apt-get -y install tcl8.5 +apt-get -y install tmux +apt-get -y install vim +apt-get -y install zlib1g +apt-get -y install zlib1g-dev + +RUBY_VERSION="2.1.3" +wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-$RUBY_VERSION.tar.bz2 +tar jxf ruby-$RUBY_VERSION.tar.bz2 +cd ruby-$RUBY_VERSION +./configure --prefix=/opt/ruby +make +make install +cd .. +rm -rf ruby-$RUBY_VERSION* +chown -R root:admin /opt/ruby +chmod -R g+w /opt/ruby + +RUBYGEMS_VERSION="2.4.1" +wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBYGEMS_VERSION.tgz +tar xzf rubygems-$RUBYGEMS_VERSION.tgz +cd rubygems-$RUBYGEMS_VERSION +/opt/ruby/bin/ruby setup.rb +cd .. +rm -rf rubygems-$RUBYGEMS_VERSION* # Setup sudo to allow no-password sudo for "admin" cp /etc/sudoers /etc/sudoers.orig @@ -61,25 +179,6 @@ make install cd .. rm -rf node* -RUBY_VERSION="2.1.2" -wget http://ftp.ruby-lang.org/pub/ruby/2.1/ruby-$RUBY_VERSION.tar.bz2 -tar jxf ruby-$RUBY_VERSION.tar.bz2 -cd ruby-$RUBY_VERSION -./configure --prefix=/opt/ruby -make -make install -cd .. -rm -rf ruby-$RUBY_VERSION* -chown -R root:admin /opt/ruby -chmod -R g+w /opt/ruby - -RUBYGEMS_VERSION="2.4.1" -wget http://production.cf.rubygems.org/rubygems/rubygems-$RUBYGEMS_VERSION.tgz -tar xzf rubygems-$RUBYGEMS_VERSION.tgz -cd rubygems-$RUBYGEMS_VERSION -/opt/ruby/bin/ruby setup.rb -cd .. -rm -rf rubygems-$RUBYGEMS_VERSION* # Installing chef & Puppet /opt/ruby/bin/gem install chef --no-ri --no-rdoc @@ -103,7 +202,8 @@ cd .. rm -rf postgresql-$POSTGRES_VERSION* # Add 'vagrant' role -su -c 'createuser vagrant -s' postgres +su -c 'createuser -s vagrant' postgres +su -c 'createuser -s coderwall' postgres # Initialize postgres DB useradd -p postgres postgres @@ -113,6 +213,10 @@ su -c "/usr/bin/initdb -D /var/pgsql/data --locale=en_US.UTF-8 --encoding=UNICOD mkdir /var/pgsql/data/log chown postgres /var/pgsql/data/log +# Set the PG instance to listen and accept connections from anywhere +echo "listen_addresses = '*'" | tee -a /var/pgsql/data/postgresql.conf +echo host all all 0.0.0.0/0 trust | tee -a /var/pgsql/data/pg_hba.conf + # Start postgres su -c '/usr/bin/pg_ctl start -l /var/pgsql/data/log/logfile -D /var/pgsql/data' postgres @@ -183,14 +287,66 @@ rm /lib/udev/rules.d/75-persistent-net-generator.rules # Install Heroku toolbelt wget -qO- https://toolbelt.heroku.com/install-ubuntu.sh | sh +# Set locale +echo 'LC_ALL="en_US.UTF-8"' >> /etc/default/locale + +# Configure the user. +su postgres -c 'createuser -s vagrant' +su postgres -c 'createuser -s coderwall' + +su postgres -c 'pg_ctl stop -D /var/pgsql/data 2>&1' +su -c '/usr/bin/pg_ctl start -l /var/pgsql/data/log/logfile -D /var/pgsql/data' postgres + +sudo su - vagrant <<-'EOF' + echo export EDITOR=vim >> $HOME/.bashrc + echo insecure > $HOME/.curlrc + echo progress-bar >> $HOME/.curlrc + + echo rvm_install_on_use_flag=1 >> $HOME/.rvmrc + echo rvm_project_rvmrc=1 >> $HOME/.rvmrc + echo rvm_trust_rvmrcs_flag=1 >> $HOME/.rvmrc + + curl -k -L https://get.rvm.io | bash -s stable --autolibs=install-packages + source "$HOME/.rvm/scripts/rvm" + [[ -s "$rvm_path/hooks/after_cd_bundle" ]] && chmod +x $rvm_path/hooks/after_cd_bundle + rvm autolibs enable + rvm requirements + rvm reload + + _RUBY_VERSION=ruby-2.1.3 + rvm install $_RUBY_VERSION + rvm gemset create coderwall + rvm use $_RUBY_VERSION --default + rvm use $_RUBY_VERSION@coderwall + gem update --system && gem update bundler + gem install curb -v '0.8.6' + + mkdir -p ~/tmp + + git clone https://github.com/assemblymade/coderwall.git ~/bootstrap/coderwall + cd ~/bootstrap/coderwall + rvm current + + bundle config --global jobs 3 + bundle install + + echo "IMPORTANT: Set the ENV Keys!!! + export ENV_KEYS=somevalue + + bundle exec rake db:drop:all + bundle exec rake db:create:all + RAILS_ENV=test bundle exec rake db:create + bundle exec rake db:schema:load + bundle exec rake db:migrate + bundle exec rake db:seed + bundle exec rake db:test:prepare +EOF + # Install some libraries apt-get -y clean apt-get -y autoclean apt-get -y autoremove -# Set locale -echo 'LC_ALL="en_US.UTF-8"' >> /etc/default/locale - echo "==> Installed packages before cleanup" dpkg --get-selections | grep -v deinstall @@ -200,12 +356,12 @@ dpkg --list | awk '{ print $2 }' | grep 'linux-image-3.*-generic' | grep -v $(un echo "==> Removing linux source" dpkg --list | awk '{ print $2 }' | grep linux-source | xargs apt-get -y purge echo "==> Removing development packages" -dpkg --list | awk '{ print $2 }' | grep -- '-dev$' | xargs apt-get -y purge +#dpkg --list | awk '{ print $2 }' | grep -- '-dev$' | xargs apt-get -y purge echo "==> Removing documentation" dpkg --list | awk '{ print $2 }' | grep -- '-doc$' | xargs apt-get -y purge echo "==> Removing development tools" -#dpkg --list | grep -i compiler | awk '{ print $2 }' | xargs apt-get -y purge -#apt-get -y purge cpp gcc g++ +dpkg --list | grep -i compiler | awk '{ print $2 }' | xargs apt-get -y purge +apt-get -y purge cpp gcc g++ apt-get -y purge build-essential echo "==> Removing default system Ruby" apt-get -y purge ruby ri doc diff --git a/vagrant/coderwall-box/scripts/user-config.sh b/vagrant/coderwall-box/scripts/user-config.sh new file mode 100644 index 00000000..ac0386f2 --- /dev/null +++ b/vagrant/coderwall-box/scripts/user-config.sh @@ -0,0 +1,7 @@ +sudo su - vagrant <<-'EOF' + cd ~/web + rvm requirements + bundle check && bundle install + cd + rm -rf ~/bootstrap +EOF diff --git a/vagrant/coderwall-box/template.json b/vagrant/coderwall-box/template.json index 55a57a9c..079e1601 100644 --- a/vagrant/coderwall-box/template.json +++ b/vagrant/coderwall-box/template.json @@ -1,8 +1,8 @@ { "builders": [{ "type": "virtualbox-iso", - "boot_wait": "15s", - "disk_size": 32768, + "boot_wait": "30s", + "disk_size": 65536, "guest_additions_path": "VBoxGuestAdditions_{{.Version}}.iso", "guest_os_type": "Ubuntu_64", "http_directory": "http", @@ -13,7 +13,7 @@ "ssh_password": "vagrant", "ssh_port": 22, "ssh_username": "vagrant", - "ssh_wait_timeout": "10000s", + "ssh_wait_timeout": "30000s", "virtualbox_version_file": ".vbox_version", "boot_command": [ "", @@ -35,7 +35,10 @@ ], "provisioners": [ { "type": "shell", - "scripts": [ "scripts/postinstall.sh" ], + "scripts": [ + "scripts/postinstall.sh", + "scripts/user-config.sh" + ], "override": { "virtualbox-iso": { "execute_command": "echo 'vagrant'|sudo -S sh '{{.Path}}'" } } diff --git a/vagrant/run b/vagrant/run new file mode 100755 index 00000000..a1424c4d --- /dev/null +++ b/vagrant/run @@ -0,0 +1,14 @@ +#!/bin/bash -e + +cd /home/vagrant/web + +rvm current +bundle check || bundle install +bundle clean --force + +bundle exec foreman check + +bundle exec rake db:migrate +bundle exec rake db:test:prepare + +bundle exec foreman start all diff --git a/vagrant/user-config.sh b/vagrant/user-config.sh deleted file mode 100755 index 08f3dcf1..00000000 --- a/vagrant/user-config.sh +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/bash -x -export DEBIAN_FRONTEND=noninteractive -cd /home/vagrant -echo Who am I? You are `whoami`. -echo Where am I? You are in `pwd` -echo I think my home is $HOME - -echo export EDITOR=vim >> $HOME/.bashrc - -echo insecure > $HOME/.curlrc - -echo rvm_install_on_use_flag=1 >> $HOME/.rvmrc -echo rvm_project_rvmrc=1 >> $HOME/.rvmrc -echo rvm_trust_rvmrcs_flag=1 >> $HOME/.rvmrc -curl -k -L https://get.rvm.io | bash -s stable --autolibs=enabled -source "$HOME/.rvm/scripts/rvm" -[[ -s "$rvm_path/hooks/after_cd_bundle" ]] && chmod +x $rvm_path/hooks/after_cd_bundle -rvm autolibs enable -rvm requirements -rvm reload -_RUBY_VERSION=ruby-2.1.2 -rvm install $_RUBY_VERSION -rvm gemset create coderwall -rvm use $_RUBY_VERSION --default -rvm use $_RUBY_VERSION@coderwall -cd $HOME/web -gem update --system && gem update bundler -bundle config --global jobs 3 -bundle install - -# Setup .env -cp .env.example .env -n - -sudo su postgres -c 'pg_ctl stop -D /var/pgsql/data 2>&1' -sudo su postgres -c 'pg_ctl start -D /var/pgsql/data 2>&1 &' - -export DEV_POSTGRES_PORT=5432 -export REDIS_URL=redis://127.0.0.1:6379 - -bundle exec rake db:drop:all -bundle exec rake db:create:all -bundle exec rake db:schema:load -bundle exec rake db:migrate -bundle exec rake db:seed -bundle exec rake db:test:prepare