├── .gitattributes ├── .gitignore ├── README.md ├── Station ├── Lib │ ├── hash.rb │ ├── station-module.rb │ └── station.rb ├── config.yaml └── modules │ ├── aws │ ├── aws.rb │ ├── config.yaml │ ├── scripts │ │ └── awscli.sh │ └── templates │ │ ├── config.erb │ │ └── credentials.erb │ ├── commands │ ├── commands.rb │ ├── config.yaml │ └── scripts │ │ └── commands.sh │ ├── composer │ ├── composer.rb │ └── config.yaml │ ├── docker │ ├── config.yaml │ ├── docker.rb │ └── scripts │ │ └── install.sh │ ├── elastic-beanstalk │ ├── config.yaml │ ├── elastic-beanstalk.rb │ └── scripts │ │ └── elasticbeanstalk.sh │ ├── folders │ ├── config.yaml │ └── folders.rb │ ├── git-config │ ├── config.yaml │ └── git-config.rb │ ├── known-hosts │ ├── config.yaml │ ├── known-hosts.rb │ └── scripts │ │ └── add-domain.sh │ ├── mysql │ ├── config.yaml │ └── mysql.rb │ ├── oh-my-zsh │ ├── config.yaml │ ├── oh-my-zsh.rb │ └── scripts │ │ └── install-oh-my-zsh.sh │ ├── postgresql │ ├── config.yaml │ └── postgresql.rb │ ├── ruby-gems │ ├── config.yaml │ └── ruby-gems.rb │ ├── sites │ ├── config.yaml │ ├── scripts │ │ ├── clone.sh │ │ └── server.sh │ ├── sites.rb │ └── templates │ │ └── server.erb │ ├── source-aliases │ ├── config.yaml │ ├── scripts │ │ └── check-rcfiles.sh │ ├── source-aliases.rb │ └── templates │ │ └── shellalias.erb │ ├── ssh │ ├── config.yaml │ └── ssh.rb │ ├── variables │ ├── config.yaml │ └── variables.rb │ └── xdebug │ ├── config.yaml │ ├── templates │ └── xdebug_ini.erb │ └── xdebug.rb ├── Vagrantfile ├── aliases ├── bootstrap.rb ├── config-sample.yaml ├── create-module.sh └── www └── .gitkeep /.gitattributes: -------------------------------------------------------------------------------- 1 | * text eol=lf -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Hide system files 2 | .DS_Store 3 | 4 | # Hide PHPStorm project files 5 | .idea 6 | 7 | # Hide sublime project files 8 | *.sublime-project 9 | *.sublime-workspace 10 | 11 | # Hide vagrant folder 12 | .vagrant 13 | 14 | # Ignore custom config file 15 | /config.yaml 16 | 17 | # Keep sites folder, but not any files inside 18 | www/* 19 | !www/.gitkeep -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # What is Station? 2 | 3 | Station is a simple, module based framework for customizing the [laravel/homestead](https://github.com/laravel/homestead) vagrant environment. 4 | 5 | Station extends homesteads Yaml configuration file with features such as: xdebug, zsh, oh-my-zsh, ruby-gem installers and much more. 6 | 7 | ## Installation 8 | 9 | 1. Install requirements (Vagrant & Virtualbox) 10 | * Newest version of virtualbox [download](https://www.virtualbox.org/wiki/Downloads) 11 | * Virtualbox Extension Pack: located on virtualbox downloads page 12 | * Newest Vagrant build: Manages the virtual machine through virtual box [download](https://www.vagrantup.com/downloads.html) 13 | 14 | 2. Add the Laravel Homestead box to your vagrant environment: 15 | * `vagrant box add laravel/homestead` 16 | 17 | ## About Homestead 18 | 19 | From the [Laravel Homestead](http://laravel.com/docs/4.2/homestead) page: 20 | 21 | **Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re-create the box in minutes!** 22 | 23 | ## Getting Started 24 | 25 | The best place to get started is to read the [wiki](https://github.com/mcuyar/station/wiki). -------------------------------------------------------------------------------- /Station/Lib/hash.rb: -------------------------------------------------------------------------------- 1 | class ::Hash 2 | # http://stackoverflow.com/questions/9381553/ruby-merge-nested-hash 3 | def deep_merge(second) 4 | merger = proc { |key, v1, v2| Hash === v1 && Hash === v2 ? v1.merge(v2, &merger) : v2 } 5 | self.merge(second, &merger) 6 | end 7 | 8 | def find?(key, default=nil) 9 | keys = key.split('.') 10 | if keys.length > 1 11 | key = keys.shift 12 | self.has_key?(key) ? self[key].find?(keys.join('.'), default) : default 13 | else 14 | self[key] || default 15 | end 16 | end 17 | 18 | end -------------------------------------------------------------------------------- /Station/Lib/station-module.rb: -------------------------------------------------------------------------------- 1 | class StationModule 2 | 3 | attr_accessor :config, :args, :scripts 4 | 5 | def initialize(config, args, module_path) 6 | @classname = args.is_a?(Hash) ? args.delete('classname') : self.class 7 | @config = config 8 | @args = args 9 | @scripts = module_path + "/scripts" 10 | end 11 | 12 | def shell_provision(inline, args=nil, privileged=true) 13 | @config.vm.provision "shell" do |s| 14 | s.inline = inline 15 | s.args = args 16 | s.privileged = privileged 17 | end 18 | end 19 | end -------------------------------------------------------------------------------- /Station/Lib/station.rb: -------------------------------------------------------------------------------- 1 | class Station 2 | 3 | @@modules = Hash.new 4 | 5 | def self.configure(config, settings, path) 6 | 7 | # Configure The Box 8 | config.vm.box = settings["box"] ||= "laravel/homestead" 9 | config.vm.hostname = settings["hostname"] ||= "station" 10 | 11 | # Configure A Private Network IP 12 | config.vm.network :private_network, ip: settings["ip"] ||= "192.168.10.10" 13 | 14 | # Configure A Few VirtualBox Settings 15 | config.vm.provider "virtualbox" do |vb| 16 | vb.customize ["modifyvm", :id, "--memory", settings["memory"] ||= "2048"] 17 | vb.customize ["modifyvm", :id, "--cpus", settings["cpus"] ||= "1"] 18 | vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"] 19 | vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"] 20 | end 21 | 22 | # Configure Port Forwarding To The Box 23 | config.vm.network "forwarded_port", guest: 80, host: settings["forwarded_ports"]["http"] ||= 8000 24 | config.vm.network "forwarded_port", guest: 3306, host: settings["forwarded_ports"]["mysql"] ||= 33060 25 | config.vm.network "forwarded_port", guest: 5432, host: settings["forwarded_ports"]["postgresql"] ||= 54320 26 | 27 | # Get the modules directory 28 | modules = Dir.glob(path + '/Station/modules/*').select { |f| File.directory? f } 29 | 30 | # loop through and initialize the modules 31 | modules.each do |m| 32 | 33 | basename = File.basename(m) 34 | 35 | # Load the config file 36 | args = YAML::load(File.read(m + '/config.yaml')) 37 | classname = args["classname"] 38 | 39 | # Merge settings with default config 40 | if settings.find?(basename) 41 | if settings[basename].kind_of?(Array) 42 | args = args.deep_merge({basename => settings[basename]}) 43 | elsif settings[basename].kind_of?(Hash) 44 | args = args.deep_merge(settings[basename]) 45 | elsif settings[basename].kind_of?(String) 46 | args = settings[basename]; 47 | end 48 | end 49 | 50 | # run the module provisioner 51 | require m + "/#{basename}.rb" 52 | m.sub! path, '/vagrant' 53 | @@modules[basename] = Kernel.const_get(classname).new(config, args, m) 54 | 55 | end 56 | 57 | end 58 | 59 | def self.modules 60 | @@modules 61 | end 62 | 63 | def self.module(classname) 64 | @@modules.find?(classname) 65 | end 66 | 67 | def self.provision 68 | if ENV.has_key?('MODULE') && @@modules.has_key?(ENV['MODULE']) 69 | @@modules[ENV['MODULE']].provision 70 | else 71 | @@modules.each do |name, object| 72 | object.provision 73 | end 74 | end 75 | end 76 | 77 | end -------------------------------------------------------------------------------- /Station/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | hostname: "station" 3 | ip: "192.168.10.10" 4 | memory: 2048 5 | cpus: 1 6 | 7 | forwarded_ports: 8 | http: 8000 9 | mysql: 33060 10 | postgresql: 54320 11 | 12 | authorize: ~/.ssh/id_rsa.pub 13 | 14 | keys: 15 | - ~/.ssh/id_rsa 16 | 17 | known_hosts: 18 | - github.com 19 | 20 | folders: 21 | - map: ./www 22 | to: /var/www 23 | type: nfs 24 | 25 | sites: 26 | - map: station 27 | to: /var/www -------------------------------------------------------------------------------- /Station/modules/aws/aws.rb: -------------------------------------------------------------------------------- 1 | class AmazonWebServices < StationModule 2 | 3 | attr_accessor :path 4 | 5 | def initialize(config, args, module_path) 6 | super 7 | @path = "#{File.dirname(__FILE__)}" 8 | end 9 | 10 | def generate_template(profiles, template_file) 11 | 12 | # Create the template 13 | template = File.read(path + "/templates/#{template_file}.erb") 14 | result = ERB.new(template).result(binding) 15 | 16 | # Add template to vagrant home directory 17 | script = %{ 18 | echo "#{result}" > "$(sudo -u vagrant pwd)/.aws/#{template_file}"; 19 | } 20 | 21 | shell_provision(script) 22 | 23 | end 24 | 25 | def provision 26 | 27 | if args["install"] 28 | 29 | shell_provision("bash #{@scripts}/awscli.sh") 30 | 31 | default_profile = args["defaults"]["profile"] 32 | profiles = args.find?('profiles', []).map { |profile| default_profile.clone.merge(profile) } 33 | 34 | generate_template(profiles, "credentials") 35 | generate_template(profiles, "config") 36 | 37 | end 38 | 39 | end 40 | 41 | end -------------------------------------------------------------------------------- /Station/modules/aws/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: AmazonWebServices 3 | 4 | install: false 5 | 6 | defaults: 7 | profile: 8 | name: default 9 | access_key: N/A 10 | access_secret: N/A 11 | region: us-east-1 12 | output: text -------------------------------------------------------------------------------- /Station/modules/aws/scripts/awscli.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | home=$(sudo -u vagrant pwd) 4 | 5 | su vagrant < 2 | [<%= values["name"] %>] 3 | region=<%= values["region"] %> 4 | output=<%= values["output"] %> 5 | <% end %> -------------------------------------------------------------------------------- /Station/modules/aws/templates/credentials.erb: -------------------------------------------------------------------------------- 1 | <% profiles.each do |values| %> 2 | [<%= values["name"] %>] 3 | aws_access_key_id=<%= values["access_key"] %> 4 | aws_secret_access_key=<%= values["access_secret"] %> 5 | <% end %> -------------------------------------------------------------------------------- /Station/modules/commands/commands.rb: -------------------------------------------------------------------------------- 1 | class Commands < StationModule 2 | 3 | def execute(command, path) 4 | shell_provision( 5 | "bash #{scripts}/commands.sh $1 \"$2\"", 6 | [path, command] 7 | ) 8 | end 9 | 10 | def provision 11 | args.find?('commands', []).each do |cmd| 12 | execute(cmd, "~/") 13 | end 14 | end 15 | end -------------------------------------------------------------------------------- /Station/modules/commands/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Commands -------------------------------------------------------------------------------- /Station/modules/commands/scripts/commands.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | echo $2 3 | su vagrant < $home/aws_credentials 26 | 27 | if [ "${version/.*}" -lt "3" ]; then 28 | # Download the elastic beanstalk cli and Extract the CLI into the home folder 29 | if [ ! -f $home/AWS-ElasticBeanstalk-CLI-$version.zip ]; then 30 | rm -f $home/AWS-ElasticBeanstalk-CLI-*.zip 31 | wget https://s3.amazonaws.com/elasticbeanstalk/cli/AWS-ElasticBeanstalk-CLI-$version.zip 32 | unzip $home/AWS-ElasticBeanstalk-CLI-$version.zip 33 | rm -rf $home/AWS-ElasticBeanstalk-CLI 34 | mv $home/AWS-ElasticBeanstalk-CLI-$version $home/AWS-ElasticBeanstalk-CLI 35 | fi 36 | else 37 | sudo pip install awsebcli 38 | fi 39 | 40 | #Export CLI & Key Path for bash | zsh 41 | if [ ! -f $home/eb_exported ]; then 42 | echo -e "$path\n$credentials" >> $home/.bashrc 43 | echo -e "export $path\nexport $credentials" >> $home/.zshrc 44 | touch $home/eb_exported 45 | fi 46 | EOF -------------------------------------------------------------------------------- /Station/modules/folders/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Folders -------------------------------------------------------------------------------- /Station/modules/folders/folders.rb: -------------------------------------------------------------------------------- 1 | class Folders < StationModule 2 | 3 | def provision 4 | # Register All Of The Configured Shared Folders 5 | args.find?('folders', []).each do |folder| 6 | if folder.find?('type', nil) === 'nfs' 7 | config.vm.synced_folder folder["map"], folder["to"], create: folder["create"] ||= false, disabled: folder["disabled"] ||= false, mount_options: folder["mount_options"] ||= [], type: folder["type"] ||= nil 8 | else 9 | config.vm.synced_folder folder["map"], folder["to"], create: folder["create"] ||= false, disabled: folder["disabled"] ||= false, group: folder["group"] ||= 'vagrant', owner: folder["owner"] ||= 'vagrant', mount_options: folder["mount_options"] ||= [], type: folder["type"] ||= nil 10 | end 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /Station/modules/git-config/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: GitConfig 3 | 4 | colors.ui: "true" 5 | push.default: simple -------------------------------------------------------------------------------- /Station/modules/git-config/git-config.rb: -------------------------------------------------------------------------------- 1 | # todo: add option for mapping local .git-config file 2 | class GitConfig < StationModule 3 | 4 | def set(key, value, global = false, path = '~/') 5 | 6 | Station.module('commands').execute( 7 | "git config #{global ? '--global' : ''} #{key} \"#{value}\"", 8 | path 9 | ) 10 | 11 | end 12 | 13 | def fill(hash, global = false, path = '~/') 14 | hash.each do |key, value| 15 | set(key, value, global, path) 16 | end 17 | end 18 | 19 | def provision 20 | 21 | # Delete existing global .gitconfig file 22 | shell_provision(' 23 | echo "Setting git config" 24 | home=$(sudo -u vagrant pwd) 25 | 26 | if [ -f $home/.gitconfig ]; then 27 | rm -f $home/.gitconfig 28 | fi 29 | ') 30 | 31 | if args.is_a? String 32 | shell_provision( 33 | "echo \"$1\" > .gitconfig", 34 | [File.read(File.expand_path(args))], 35 | false 36 | ) 37 | elsif args.is_a? Hash 38 | fill(args, true) 39 | end 40 | end 41 | 42 | end -------------------------------------------------------------------------------- /Station/modules/known-hosts/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: KnownHosts 3 | 4 | domains: 5 | - github.com 6 | - bitbucket.org -------------------------------------------------------------------------------- /Station/modules/known-hosts/known-hosts.rb: -------------------------------------------------------------------------------- 1 | class KnownHosts < StationModule 2 | 3 | def add_domain(domain) 4 | shell_provision("bash #{@scripts}/add-domain.sh #{domain}") 5 | end 6 | 7 | def provision 8 | # Add known hosts 9 | args.find?('domains', []).each do |domain| 10 | add_domain(domain) 11 | end 12 | end 13 | 14 | end -------------------------------------------------------------------------------- /Station/modules/known-hosts/scripts/add-domain.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | su vagrant < ~/.ssh/known_hosts 7 | 8 | EOF -------------------------------------------------------------------------------- /Station/modules/mysql/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Mysql 3 | 4 | databases: 5 | - name: station 6 | user: station 7 | password: secret -------------------------------------------------------------------------------- /Station/modules/mysql/mysql.rb: -------------------------------------------------------------------------------- 1 | class Mysql < StationModule 2 | 3 | def create_db(name, user, drop = false) 4 | 5 | unless drop === true 6 | drop = %{ 7 | echo "deleting database: #{name}" 8 | sudo mysql -uroot -psecret -e " 9 | DROP DATABASE IF EXISTS #{name}; 10 | "} 11 | 12 | shell_provision(drop) 13 | end 14 | 15 | script = %{ 16 | echo "creating database #{name} if it does not exist" 17 | sudo mysql -uroot -psecret -e " 18 | CREATE DATABASE IF NOT EXISTS #{name}; 19 | USE #{name}; 20 | GRANT ALL ON #{name} TO '#{user}'@'localhost'; 21 | "} 22 | 23 | shell_provision(script) 24 | 25 | end 26 | 27 | def create_user(username, password) 28 | 29 | script = %{ 30 | echo "creating user: #{username}" 31 | sudo mysql -uroot -psecret -e " 32 | GRANT USAGE ON *.* TO '#{username}'@'localhost'; 33 | DROP USER '#{username}'@'localhost'; 34 | CREATE USER '#{username}'@'localhost' IDENTIFIED BY '#{password}'; 35 | "} 36 | 37 | shell_provision(script) 38 | 39 | end 40 | 41 | def create(db) 42 | #create user 43 | if db.has_key?("user") && db.has_key?("password") 44 | create_user(db["user"], db["password"]) 45 | end 46 | 47 | if db.has_key?("name") 48 | create_db(db["name"], db.find?('user', 'homestead'), db["drop"] ||= false) 49 | end 50 | end 51 | 52 | def provision 53 | 54 | # Install databases 55 | args.find?('databases', []).each do |db| 56 | create(db) 57 | end 58 | 59 | end 60 | 61 | end -------------------------------------------------------------------------------- /Station/modules/oh-my-zsh/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: OhMyZsh 3 | 4 | install: 5 | zsh: true 6 | oh-my-zsh: true -------------------------------------------------------------------------------- /Station/modules/oh-my-zsh/oh-my-zsh.rb: -------------------------------------------------------------------------------- 1 | class OhMyZsh < StationModule 2 | 3 | def install_zsh 4 | shell_provision("sudo apt-get -y install zsh") 5 | end 6 | 7 | def install_oh_my_zsh 8 | shell_provision("bash #{scripts}/install-oh-my-zsh.sh") 9 | end 10 | 11 | def provision 12 | 13 | # Install Oh My Zsh 14 | if args.find?('install.oh-my-zsh', false) 15 | args['install']['zsh'] = false 16 | install_zsh 17 | install_oh_my_zsh 18 | end 19 | 20 | # Install zsh 21 | if args.find?('install.zsh', false) 22 | install_zsh 23 | end 24 | 25 | end 26 | 27 | end -------------------------------------------------------------------------------- /Station/modules/oh-my-zsh/scripts/install-oh-my-zsh.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # Add composer to path 4 | composer_path='PATH=\$PATH:~/.composer/vendor/bin' 5 | 6 | su vagrant <> $(sudo -u vagrant pwd)/.zshrc 17 | fi 18 | 19 | EOF -------------------------------------------------------------------------------- /Station/modules/postgresql/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Postgresql 3 | 4 | contrib: 5 | install: true 6 | version: 9.3 7 | 8 | databases: 9 | - name: station 10 | user: station 11 | password: secret -------------------------------------------------------------------------------- /Station/modules/postgresql/postgresql.rb: -------------------------------------------------------------------------------- 1 | class Postgresql < StationModule 2 | 3 | def contrib(version) 4 | shell_provision("sudo apt-get -y install postgresql-contrib-#{version}") 5 | end 6 | 7 | def create_db(name, user, drop = false) 8 | 9 | if drop === true 10 | shell_provision("sudo -u postgres psql --command \"DROP DATABASE IF EXISTS #{name}\"") 11 | end 12 | 13 | shell_provision("sudo -u postgres createdb -O #{user} #{name} || true") 14 | end 15 | 16 | def create_user(username) 17 | shell_provision("sudo -u postgres createuser -s #{username} || true") 18 | end 19 | 20 | def create_password(username, password) 21 | shell_provision("sudo -u postgres psql --command \"ALTER USER #{username} with password '#{password}';\"") 22 | end 23 | 24 | def create(db) 25 | #create user 26 | if db.has_key?("user") && db.has_key?("password") 27 | create_user(db["user"]) 28 | create_password(db["user"], db["password"]) 29 | end 30 | 31 | if db.has_key?("name") 32 | create_db(db["name"], db.find?('user', 'homestead'), db.find?('drop', false)) 33 | end 34 | end 35 | 36 | def provision 37 | 38 | # Install postgresql contrib 39 | if args.find?('contrib.install', false) 40 | contrib(args.find?('contrib.version', '9.3') ) 41 | end 42 | 43 | # Install databases 44 | args.find?('databases', []).each do |db| 45 | create(db) 46 | end 47 | 48 | end 49 | 50 | end -------------------------------------------------------------------------------- /Station/modules/ruby-gems/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: RubyGems 3 | 4 | install: 5 | ruby-dev: true 6 | bundler: true 7 | 8 | # gems: 9 | # - sass 10 | # - compass -------------------------------------------------------------------------------- /Station/modules/ruby-gems/ruby-gems.rb: -------------------------------------------------------------------------------- 1 | class RubyGems < StationModule 2 | 3 | def install_ruby_dev 4 | shell_provision("sudo apt-get -y install ruby-dev") 5 | end 6 | 7 | def install_bundler 8 | shell_provision("gem install bundler") 9 | end 10 | 11 | def install_gem(gem) 12 | shell_provision("sudo gem install #{gem}") 13 | end 14 | 15 | def provision 16 | 17 | # Install ruby-dev 18 | if args.find?('install.ruby-dev') 19 | install_ruby_dev 20 | end 21 | 22 | # Install bundler 23 | if args.find?('install.bundler') 24 | install_bundler 25 | end 26 | 27 | # install ruby gems 28 | args.find?('gems', []).each do |gem| 29 | install_gem(gem) 30 | end 31 | 32 | end 33 | 34 | end -------------------------------------------------------------------------------- /Station/modules/sites/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Sites 3 | 4 | defaults: 5 | 6 | fastcgi-server: 7 | split_path_info: '^(.+\.php)(/.+)$' 8 | pass: "unix:/var/run/php5-fpm.sock" 9 | index: index.php 10 | buffers: "8 16k" 11 | buffer_size: 32k 12 | connect_timeout: 300s 13 | send_timeout: 60 14 | read_timeout: 60 15 | 16 | fastcgi-hhvm: 17 | split_path_info: '^(.+\.php)(/.+)$' 18 | pass: '127.0.0.1:9000' 19 | index: index.php 20 | param: 'SCRIPT_FILENAME \$document_root$fastcgi_script_name' -------------------------------------------------------------------------------- /Station/modules/sites/scripts/clone.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | NAME=$1 4 | URL=$2 5 | SITEPATH=$3 6 | 7 | su vagrant < "/etc/nginx/sites-available/$1" 6 | ln -fs "/etc/nginx/sites-available/$1" "/etc/nginx/sites-enabled/$1" 7 | service nginx restart 8 | service php5-fpm restart -------------------------------------------------------------------------------- /Station/modules/sites/sites.rb: -------------------------------------------------------------------------------- 1 | class Sites < StationModule 2 | 3 | attr_accessor :path, :installing 4 | 5 | def initialize(config, args, module_path) 6 | super 7 | @path = "#{File.dirname(__FILE__)}" 8 | @installing = ENV.has_key?('INSTALL') 9 | end 10 | 11 | def sites_available(site) 12 | 13 | # compile fastcgi params 14 | hhvm_restart = '' 15 | if site.find?('hhvm', false) && site['hhvm'] === true 16 | hhvm_restart = 'service hhvm restart;' 17 | fastcgi = args["defaults"]["fastcgi-hhvm"] 18 | else 19 | fastcgi = args["defaults"]["fastcgi-server"] 20 | end 21 | 22 | if site.has_key?("fastcgi") && !site["fastcgi"].empty? 23 | fastcgi = fastcgi.deep_merge(site["fastcgi"]) 24 | end 25 | 26 | # compile php value overrides 27 | php_values = args["defaults"]["php-values"] ||= {} 28 | if site.has_key?("php-values") && !site["php-values"].empty? 29 | php_values = php_values.deep_merge(site["php-values"]) 30 | end 31 | 32 | # add xdebug values 33 | site.find?('xdebug', []).each do |key, value| 34 | php_values["xdebug.#{key}"] = value 35 | end 36 | 37 | # add environment variables 38 | variables = args["defaults"]["variables"] ||= {} 39 | if site.has_key?("variables") && !site["variables"].empty? 40 | variables = variables.deep_merge(site["variables"]) 41 | end 42 | 43 | # Create the server template 44 | template = File.read(path + "/templates/server.erb") 45 | result = ERB.new(template).result(binding) 46 | 47 | # Add site to nginx 48 | script = %{ 49 | echo "#{result}" > "/etc/nginx/sites-available/#{site["map"]}"; 50 | ln -fs "/etc/nginx/sites-available/#{site["map"]}" "/etc/nginx/sites-enabled/#{site["map"]}"; 51 | service nginx restart; 52 | service php5-fpm restart; 53 | #{hhvm_restart} 54 | } 55 | 56 | shell_provision(script) 57 | 58 | end 59 | 60 | def git_clone(name, url, path) 61 | 62 | # Set installing var as true 63 | @installing = true if Dir.exists?(path) 64 | 65 | # Clone the site 66 | shell_provision( 67 | "bash #{scripts}/clone.sh $1 \"$2\" $3", 68 | [name, url, path] 69 | ) 70 | 71 | end 72 | 73 | # @param [Object] vars 74 | def env_vars(vars) 75 | 76 | config.vm.provision 'shell' do |s| 77 | s.inline = "if [ ! -f #{env_path} ]; then touch #{env_path} ; else echo '' > #{env_path} ; fi" 78 | end 79 | 80 | shell_provision( 81 | "if [ ! -f #{env_path} ]; then touch #{env_path} ; else echo '' > #{env_path} ; fi" 82 | ) 83 | 84 | unless vars.empty? 85 | vars.each do |key, value| 86 | shell_provision( 87 | "echo \"$1 = '$2'\" >> #{env_path}", 88 | [key, value] 89 | ) 90 | end 91 | end 92 | end 93 | 94 | def commands_exec(commands, path) 95 | 96 | if installing 97 | # install commands 98 | commands.find?('install', []).each do |cmd| 99 | Station.module('commands').execute(cmd, path) 100 | end 101 | else 102 | # update commands 103 | commands.find?('update', []).each do |cmd| 104 | Station.module('commands').execute(cmd, path) 105 | end 106 | end 107 | 108 | # always commands 109 | commands.find?('always', []).each do |cmd| 110 | Station.module('commands').execute(cmd, path) 111 | end 112 | 113 | end 114 | 115 | def create_db(db) 116 | case db.find?('type', '') 117 | when "mysql" 118 | Station.module('mysql').create(db) 119 | when "postgresql" 120 | Station.module('postgresql').create(db) 121 | else 122 | Station.module('mysql').create(db) 123 | Station.module('postgresql').create(db) 124 | end 125 | end 126 | 127 | def provision 128 | 129 | args.find?('sites', []).each do |site| 130 | 131 | base_path = site.find?('git-clone.path', site["to"]) 132 | 133 | # install configured nginx sites 134 | sites_available(site) 135 | 136 | # install/clone git repository 137 | url = site.find?('git-clone.url') 138 | if url 139 | git_clone(site.find?('git-clone.name', ''), url, base_path) 140 | end 141 | 142 | # Add site db 143 | db = site.find?('db') 144 | if db 145 | create_db(db) 146 | end 147 | 148 | # Run commands in installed site 149 | commands_exec(site.find?('commands', {}), base_path) 150 | 151 | # Add git config variables 152 | Station.module('git-config').fill(site.find?('git-config', {},), false, base_path) 153 | 154 | end 155 | 156 | end 157 | end -------------------------------------------------------------------------------- /Station/modules/sites/templates/server.erb: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | server_name <%= site["map"] %>; 4 | root <%= site["to"] %>; 5 | 6 | index index.html index.htm index.php; 7 | 8 | charset utf-8; 9 | 10 | location / { 11 | try_files \$uri \$uri/ /index.php?\$query_string; 12 | } 13 | 14 | location = /favicon.ico { access_log off; log_not_found off; } 15 | location = /robots.txt { access_log off; log_not_found off; } 16 | 17 | access_log off; 18 | error_log /var/log/nginx/$1-error.log error; 19 | 20 | error_page 404 /index.php; 21 | 22 | sendfile off; 23 | 24 | location ~ \.php$ { 25 | <% fastcgi.each do |key, value| %> 26 | fastcgi_<%= key %> <%= value %>; 27 | <% end %> 28 | 29 | include fastcgi_params; 30 | 31 | <% php_values.each do |key, value| %> 32 | fastcgi_param PHP_VALUE \"<%= key %>=<%= value %>\"; 33 | <% end %> 34 | 35 | <% variables.each do |key, value| %> 36 | fastcgi_param <%= key %> <%= value %>; 37 | <% end %> 38 | } 39 | 40 | location ~ /\.ht { 41 | deny all; 42 | } 43 | } -------------------------------------------------------------------------------- /Station/modules/source-aliases/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: SourceAliases 3 | 4 | defaults: 5 | sites: "cd /var/www" -------------------------------------------------------------------------------- /Station/modules/source-aliases/scripts/check-rcfiles.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | home=$(sudo -u vagrant pwd) 4 | pattern='if [ -f ~/shellalias ]; then source ~/shellalias; fi' 5 | 6 | su vagrant <> $home/.bashrc 10 | fi 11 | 12 | if ! grep -Fxq '$pattern' $home/.zshrc ; then 13 | echo -e "$pattern" >> $home/.zshrc 14 | fi 15 | 16 | EOF -------------------------------------------------------------------------------- /Station/modules/source-aliases/source-aliases.rb: -------------------------------------------------------------------------------- 1 | class SourceAliases < StationModule 2 | 3 | attr_accessor :path 4 | 5 | def initialize(config, args, module_path) 6 | super 7 | @path = "#{File.dirname(__FILE__)}" 8 | end 9 | 10 | def set_aliases(aliases) 11 | 12 | # Create the template 13 | template = File.read(path + "/templates/shellalias.erb") 14 | result = ERB.new(template).result(binding) 15 | 16 | # Add template to vagrant home directory 17 | script = %{ 18 | echo '#{result}' > "$(sudo -u vagrant pwd)/shellalias"; 19 | } 20 | 21 | shell_provision(script) 22 | 23 | end 24 | 25 | def provision 26 | 27 | shell_provision("bash #{@scripts}/check-rcfiles.sh") 28 | 29 | default_aliases = args["defaults"] ||= {} 30 | args.delete('defaults') 31 | 32 | set_aliases(default_aliases.merge(args)) 33 | 34 | end 35 | 36 | end -------------------------------------------------------------------------------- /Station/modules/source-aliases/templates/shellalias.erb: -------------------------------------------------------------------------------- 1 | <% aliases.each do |key, value| %> 2 | alias <%= key %>="<%= value %>" 3 | <% end %> -------------------------------------------------------------------------------- /Station/modules/ssh/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: SSH -------------------------------------------------------------------------------- /Station/modules/ssh/ssh.rb: -------------------------------------------------------------------------------- 1 | class SSH < StationModule 2 | 3 | def authorize 4 | if args.find?('authorize', false) 5 | shell_provision( 6 | "echo $1 | tee -a /home/vagrant/.ssh/authorized_keys", 7 | [File.read(File.expand_path(args["authorize"]))] 8 | ) 9 | end 10 | end 11 | 12 | def keys 13 | args.find?('keys', []).each do |key| 14 | shell_provision( 15 | "echo \"$1\" > /home/vagrant/.ssh/$2 && chmod 600 /home/vagrant/.ssh/$2", 16 | [File.read(File.expand_path(key)), key.split('/').last], 17 | false 18 | ) 19 | end 20 | end 21 | 22 | def provision 23 | # Configure The Public Key For SSH Access 24 | authorize 25 | # Copy The SSH Private Keys To The Box 26 | keys 27 | end 28 | 29 | end -------------------------------------------------------------------------------- /Station/modules/variables/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Variables 3 | 4 | variables: 5 | - key: APP_ENV 6 | value: local -------------------------------------------------------------------------------- /Station/modules/variables/variables.rb: -------------------------------------------------------------------------------- 1 | class Variables < StationModule 2 | 3 | def env_var(key, value = nil) 4 | if key.is_a?(Array) 5 | key.each do |var| 6 | shell_provision( 7 | "echo \"\nenv[$1] = '$2'\" >> /etc/php5/fpm/php-fpm.conf", 8 | [var["key"], var["value"]] 9 | ) 10 | end 11 | elsif key.is_a?(Hash) 12 | key.each do |k,v| 13 | shell_provision( 14 | "echo \"\nenv[$1] = '$2'\" >> /etc/php5/fpm/php-fpm.conf", 15 | [k, v] 16 | ) 17 | end 18 | end 19 | shell_provision("service php5-fpm restart") 20 | end 21 | 22 | def provision 23 | # Configure All Of The Server Environment Variables 24 | if args.find?('variables', false) 25 | env_var(args["variables"]) 26 | end 27 | end 28 | 29 | end -------------------------------------------------------------------------------- /Station/modules/xdebug/config.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | classname: Xdebug 3 | 4 | path: /etc/php5/mods-available/xdebug.ini 5 | 6 | xdebug: 7 | remote_enable: 1 8 | remote_autostart: 1 9 | remote_connect_back: 1 10 | idekey: station 11 | max_nesting_level: 0 12 | remote_port: 9000 13 | cli_color: 1 14 | show_local_vars: 1 15 | scream: 0 16 | profiler_enable_trigger: 1 17 | profiler_output_dir: /var/www/xdebug/profiles 18 | trace_output_dir: /tmp -------------------------------------------------------------------------------- /Station/modules/xdebug/templates/xdebug_ini.erb: -------------------------------------------------------------------------------- 1 | zend_extension=xdebug.so 2 | 3 | <% params.each do |key, value| %> 4 | xdebug.<%= key %> = <%= value.is_a?(Numeric) ? value : "'#{value}'" %>; 5 | <% end %> -------------------------------------------------------------------------------- /Station/modules/xdebug/xdebug.rb: -------------------------------------------------------------------------------- 1 | class Xdebug < StationModule 2 | 3 | attr_accessor :path 4 | 5 | def initialize(config, args, module_path) 6 | super 7 | @path = "#{File.dirname(__FILE__)}" 8 | end 9 | 10 | def xdebug_ini(params) 11 | params = params 12 | ERB.new(File.read(path + "/templates/xdebug_ini.erb")).result(binding) 13 | end 14 | 15 | def provision 16 | 17 | ini = xdebug_ini(args.find?('xdebug', [])) 18 | 19 | script = %{ 20 | echo "Editing xdebug config" 21 | sudo echo "#{ini}" > #{args["path"]} 22 | sudo service php5-fpm restart 23 | } 24 | 25 | shell_provision(script) 26 | 27 | end 28 | 29 | end -------------------------------------------------------------------------------- /Vagrantfile: -------------------------------------------------------------------------------- 1 | VAGRANTFILE_API_VERSION = "2" 2 | 3 | @path = File.dirname(__FILE__) 4 | require @path + '/bootstrap.rb' 5 | 6 | Vagrant.configure(VAGRANTFILE_API_VERSION) do |config| 7 | Station.configure(config, @station_config, @path) 8 | Station.provision 9 | end -------------------------------------------------------------------------------- /aliases: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcuyar/station/a0501938c15d9c97510a4be991a3fbf26d828914/aliases -------------------------------------------------------------------------------- /bootstrap.rb: -------------------------------------------------------------------------------- 1 | require 'yaml' 2 | require 'erb' 3 | require @path + '/Station/Lib/station.rb' 4 | require @path + '/Station/Lib/Hash.rb' 5 | require @path + '/Station/Lib/station-module.rb' 6 | 7 | # Merge config files 8 | default = YAML::load(File.read(@path+'/Station/config.yaml')) 9 | @station_config = File.exist?(@path+'/config.yaml') ? 10 | default.deep_merge(YAML::load(File.read(@path+'/config.yaml'))) : 11 | default -------------------------------------------------------------------------------- /config-sample.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | # ------------------------------------------------------ 3 | # Vagrant Box 4 | # ------------------------------------------------------ 5 | # Configure the vagrant box to use with station 6 | # 7 | # A good option for customizing a box for station 8 | # is using laravel/settler: https://github.com/laravel/settler 9 | box: laravel/homestead 10 | 11 | # ------------------------------------------------------ 12 | # VM Hostname 13 | # ------------------------------------------------------ 14 | # Configure a custom hostname 15 | # for the vagrant environment 16 | hostname: station 17 | 18 | # ------------------------------------------------------ 19 | # VM IP Address 20 | # ------------------------------------------------------ 21 | # Bind a custom ip address to the virtual machine 22 | ip: "192.168.10.10" 23 | 24 | # ------------------------------------------------------ 25 | # VM Memory Allocation 26 | # ------------------------------------------------------ 27 | # Amount of memory to allocate 28 | # from the host environment 29 | memory: 2048 30 | 31 | # ------------------------------------------------------ 32 | # VM CPU 33 | # ------------------------------------------------------ 34 | # Number of CPU's to allocate 35 | # from the host environment 36 | cpus: 1 37 | 38 | # ------------------------------------------------------ 39 | # VM Port Forwarding 40 | # ------------------------------------------------------ 41 | # Forward ports to the host machine 42 | # to allow access from localhost (127.0.0.1) 43 | forwarded_ports: 44 | http: 8000 45 | mysql: 3306 46 | postgresql: 5432 47 | 48 | # ------------------------------------------------------ 49 | # SSH Config 50 | # ------------------------------------------------------ 51 | # Pass ssh public and private keys 52 | # from the host machine to the vm 53 | ssh: 54 | authorize: ~/.ssh/id_rsa.pub 55 | keys: 56 | - ~/.ssh/id_rsa 57 | 58 | # ------------------------------------------------------ 59 | # Set git configuration for the vagrant environment 60 | # ------------------------------------------------------ 61 | 62 | # Set the path to your hosts/user .gitconfig 63 | # git-config: ~/.gitconfig 64 | 65 | # Set config for the environment manually 66 | # Visit http://git-scm.com/book/zh/v2/Customizing-Git-Git-Configuration 67 | # for git config options 68 | git-config: 69 | user.name: "Your Name" 70 | user.email: you@yourdomain.com 71 | # colors.ui: "true" 72 | # push.default: simple 73 | -------------------------------------------------------------------------------- /create-module.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | mkdir ./Station/modules/$1 4 | mkdir ./Station/modules/$1/scripts 5 | touch ./Station/modules/$1/config.yaml 6 | touch ./Station/modules/$1/$1.rb -------------------------------------------------------------------------------- /www/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mcuyar/station/a0501938c15d9c97510a4be991a3fbf26d828914/www/.gitkeep --------------------------------------------------------------------------------