From 33588456ff8ca29d3dc2d0889c7e1b70d5f34ca9 Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Sat, 17 Sep 2016 20:52:21 +0300 Subject: [PATCH 01/15] argument handler for create-command --- bin/gdev | 85 +++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/bin/gdev b/bin/gdev index 5b68a50..bc19f91 100755 --- a/bin/gdev +++ b/bin/gdev @@ -35,12 +35,15 @@ Commands: up Create and start containers update Update gdev environment sync Syncronize files with data container + create Create new project HEREDOC PROXY_UNMODIFIED_TO_COMPOSE=%w{build kill logs ps pull restart rm start stop} PROXY_MODIFIED=%w{up run} - OTHER_COMMANDS=%w{reload cleanup machine update service status shell exec sync} + OTHER_COMMANDS=%w{reload cleanup machine update service status shell exec sync create} + + CREATE_HELP='Usage: $ gdev create type=wordpress components=dustpress stage=stage.mydomain.com production=cloud.mydomain.com theme=ssh://git@domain:/theme.git name="My app" description="Short description of my app" sitename=myapp envvars=envvars.json stage=stage.mydomain.com production=cloud.mydomain.com git=ssh://git@mydomain:/my-app.git' def initialize(args) if PROXY_UNMODIFIED_TO_COMPOSE.include?(args[0]) @@ -296,6 +299,86 @@ HEREDOC puts "INFO: Sync is ready!" end + # Create new project command (validate arguments and start creating app or use wizard) + def create(args) + # validate arguments + if args.length > 0 + required_args = [ + 'sitename', 'envvars', 'type' + ] + # loop given arguments + args.each { |argument| + arg = argument.split('=') + if arg.length == 2 + # every argument has value, check for required args + + # split argument to key value pair + key = arg[0] + val = arg[1] + + if required_args.include?(key) + required_args.delete(key) + end + + else + # argument value missing, exit script and show help + puts 'Argument '+arg[0]+' needs value' + puts CREATE_HELP + exit + end + } + + if required_args.length == 0 + # all required arguments given, proceed + else + # required arguments missing, exit script and show help + puts "Arguments required:" + puts required_args + puts CREATE_HELP + exit + end + + # start creating project + create_app(args) + + else + # no args given, use wizard + create_wizard() + + end + + end + + # Create new site + def create_app(args) + puts "Creating project..." + + sitename = args[args.find_index { |e| e.match( /sitename/ ) }].split('=')[1] + envvars = args[args.find_index { |e| e.match( /envvars/ ) }].split('=')[1] + type = args[args.find_index { |e| e.match( /type/ ) }].split('=')[1] + + puts "site: "+sitename + puts "vars: "+envvars + puts "type: "+type + puts "---" + + puts "all args:" + puts args + + # TODO: really create app here + + puts "END." + end + + def create_wizard() + # TODO: ask args and start creating app + puts "wizard" + + # temporarily show usage help + puts CREATE_HELP + exit + end + # H.T. https://gist.github.com/lpar/1032297 # Runs a specified shell command in a separate thread. # If it exceeds the given timeout in seconds, kills it. From ee69aeee6e25163ce18ab4fed6752b07d5edc6bf Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Mon, 19 Sep 2016 11:19:46 +0300 Subject: [PATCH 02/15] arguments to hash, prevent duplicate args --- bin/gdev | 48 ++++++++++++++++++++++++++++-------------------- 1 file changed, 28 insertions(+), 20 deletions(-) diff --git a/bin/gdev b/bin/gdev index bc19f91..2920791 100755 --- a/bin/gdev +++ b/bin/gdev @@ -17,7 +17,8 @@ Options: Commands: build Build or rebuild services - cleanup Deletes docker containers, images and volumes + cleanup Deletes docker containers, images and volumes + create Create new project exec Run command inside web container help Get help on a command kill Kill containers @@ -32,10 +33,9 @@ Commands: service Manage gdev services (nginx and dnsmasq, mail) start Start services stop Stop services + sync Syncronize files with data container up Create and start containers update Update gdev environment - sync Syncronize files with data container - create Create new project HEREDOC @@ -43,7 +43,7 @@ HEREDOC PROXY_MODIFIED=%w{up run} OTHER_COMMANDS=%w{reload cleanup machine update service status shell exec sync create} - CREATE_HELP='Usage: $ gdev create type=wordpress components=dustpress stage=stage.mydomain.com production=cloud.mydomain.com theme=ssh://git@domain:/theme.git name="My app" description="Short description of my app" sitename=myapp envvars=envvars.json stage=stage.mydomain.com production=cloud.mydomain.com git=ssh://git@mydomain:/my-app.git' + CREATE_HELP='Usage: $ gdev create --type=wordpress --components=dustpress --stage=stage.mydomain.com --production=cloud.mydomain.com --theme=ssh://git@domain:/theme.git --name="My app" --description="Short description of my app" --sitename=myapp --envvars=envvars.json --stage=stage.mydomain.com --production=cloud.mydomain.com --git=ssh://git@mydomain:/my-app.git' def initialize(args) if PROXY_UNMODIFIED_TO_COMPOSE.include?(args[0]) @@ -302,11 +302,13 @@ HEREDOC # Create new project command (validate arguments and start creating app or use wizard) def create(args) # validate arguments - if args.length > 0 - required_args = [ - 'sitename', 'envvars', 'type' - ] + + # got arguments + unless args.empty? + required_args = ['sitename', 'envvars', 'type'] # loop given arguments + used_args = [] + args_hash = Hash.new args.each { |argument| arg = argument.split('=') if arg.length == 2 @@ -316,6 +318,20 @@ HEREDOC key = arg[0] val = arg[1] + # remove all dashes from beginning of key + key.sub! /\A-+/, '' + # check for duplicate arguments + if used_args.include?(key) + puts "Duplicate arguments" + puts CREATE_HELP + exit + else + # keep track of used arguments + used_args.push(key) + # set key and value to hash + args_hash[key]=val + end + if required_args.include?(key) required_args.delete(key) end @@ -339,10 +355,10 @@ HEREDOC end # start creating project - create_app(args) + create_app(args_hash) else - # no args given, use wizard + # no arguments given, start wizard create_wizard() end @@ -353,17 +369,9 @@ HEREDOC def create_app(args) puts "Creating project..." - sitename = args[args.find_index { |e| e.match( /sitename/ ) }].split('=')[1] - envvars = args[args.find_index { |e| e.match( /envvars/ ) }].split('=')[1] - type = args[args.find_index { |e| e.match( /type/ ) }].split('=')[1] - - puts "site: "+sitename - puts "vars: "+envvars - puts "type: "+type - puts "---" + #puts args.inspect - puts "all args:" - puts args + puts args['sitename'] # TODO: really create app here From 8c1d4198b886c109b0f263de6414da27f665bbff Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Mon, 19 Sep 2016 16:13:35 +0300 Subject: [PATCH 03/15] clone dustpress boilerplate, require dustpress --- bin/gdev | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 55 insertions(+), 3 deletions(-) diff --git a/bin/gdev b/bin/gdev index 2920791..e0e189c 100755 --- a/bin/gdev +++ b/bin/gdev @@ -328,6 +328,9 @@ HEREDOC else # keep track of used arguments used_args.push(key) + + # TODO: validate sitename (only lowercase chars, dashes or numbers) + # set key and value to hash args_hash[key]=val end @@ -367,13 +370,62 @@ HEREDOC # Create new site def create_app(args) - puts "Creating project..." + puts "Creating project "+args['sitename']+"..." #puts args.inspect - puts args['sitename'] + case args['type'] + when "wordpress" + # setup wordpress project + # check if project directory already exists + unless Dir.exists?(args['sitename']) + # clone wp-project from github + puts "Cloning wp-project..." + puts %x(git clone git@github.com:devgeniem/wp-project.git #{args['sitename']}) + if args['theme'] + puts "Cloning theme..." + puts %x(git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{args['sitename']}) + else + # TODO: get default theme url from ~/.gdev/gdevconf.yml + # do not get theme if default is not set + puts "TODO" + puts "Cloning default theme if set ~/.gdev/gdevconf.yml" + end + # check which components to install if any + if args['components'] + components_array=args['components'].split(',') + components_array.each { |component| + case component + when 'dustpress' + # require dustpress components + puts %x(cd #{args['sitename']}; composer require devgeniem/dustpress:1.* devgeniem/dustpress-debugger:1.* devgeniem/dustpress-js:*) + else + puts "Component "+component+" not supported." + end + } + end + # TODO: replace all THEMENAME and PROJECTNAME references from all files from this project to your project name + # TODO: Change project test address in docker-compose.yml for example wordpress.test -> client-name.test + # TODO: Add all people working in the project into authors section of composer.json and rename the project devgeniem/wp-project->devgeniem/client in composer.json + # TODO: composer install + # TODO: gdev up + else + puts "Directory "+args['sitename']+" exists, please use another sitename." + puts CREATE_HELP - # TODO: really create app here + exit + end + + + when "nodejs" + # setup nodejs project + puts "nodejs project not implemented yet." + when "silverbullet" + # setup silverbullet project + puts "silverbullet project not implemented yet." + else + puts "Type "+args['type']+" not supported." + end puts "END." end From 7a09b9f0e3340cc858362d3f8ee8e23fa8fe249c Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Mon, 19 Sep 2016 17:45:05 +0300 Subject: [PATCH 04/15] Install wordpress --- bin/gdev | 52 ++++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 46 insertions(+), 6 deletions(-) diff --git a/bin/gdev b/bin/gdev index e0e189c..d6d4538 100755 --- a/bin/gdev +++ b/bin/gdev @@ -305,6 +305,7 @@ HEREDOC # got arguments unless args.empty? + # TODO: parse_args method required_args = ['sitename', 'envvars', 'type'] # loop given arguments used_args = [] @@ -380,10 +381,10 @@ HEREDOC # check if project directory already exists unless Dir.exists?(args['sitename']) # clone wp-project from github - puts "Cloning wp-project..." + puts "Cloning wp-project from git@github.com:devgeniem/wp-project.git to #{args['sitename']}..." puts %x(git clone git@github.com:devgeniem/wp-project.git #{args['sitename']}) if args['theme'] - puts "Cloning theme..." + puts "Cloning theme from #{args['theme']}..." puts %x(git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{args['sitename']}) else # TODO: get default theme url from ~/.gdev/gdevconf.yml @@ -398,17 +399,56 @@ HEREDOC case component when 'dustpress' # require dustpress components + puts "Installing dustpress, dustpress-debugger and dustpress-js with composer..." puts %x(cd #{args['sitename']}; composer require devgeniem/dustpress:1.* devgeniem/dustpress-debugger:1.* devgeniem/dustpress-js:*) else puts "Component "+component+" not supported." end } end - # TODO: replace all THEMENAME and PROJECTNAME references from all files from this project to your project name - # TODO: Change project test address in docker-compose.yml for example wordpress.test -> client-name.test + # replace all THEMENAME and PROJECTNAME references from all files from this project to your project name + puts "Replacing THEMENAME and PROJECTNAME strings from all project files with #{args['sitename']}..." + themename_file_names = [ + "#{args['sitename']}/.drone.yml", + "#{args['sitename']}/config/application.php", + "#{args['sitename']}/docker-compose.yml" + ] + themename_file_names.each do |file_name| + text = File.read(file_name) + new_contents = text.gsub(/THEMENAME/, "#{args['sitename']}") + File.open(file_name, "w") {|file| file.puts new_contents } + end + projectname_file_names = [ + "#{args['sitename']}/.drone.yml" + ] + projectname_file_names.each do |file_name| + text = File.read(file_name) + new_contents = text.gsub(/PROJECTNAME/, "#{args['sitename']}") + File.open(file_name, "w") {|file| file.puts new_contents } + end + # change project test address in docker-compose.yml for example wordpress.test -> client-name.test + docker_compose = File.read("#{args['sitename']}/docker-compose.yml") + docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test") + File.open("#{args['sitename']}/docker-compose.yml", "w") {|file| file.puts docker_compose_replace } + # TODO: Add all people working in the project into authors section of composer.json and rename the project devgeniem/wp-project->devgeniem/client in composer.json - # TODO: composer install - # TODO: gdev up + + # composer install + puts "Running composer install..." + puts %x(cd #{args['sitename']}; composer install) + # gdev up + puts "Running gdev up..." + puts %x(cd #{args['sitename']}; gdev up) + + # seed (install wp) + puts "Waiting for 10 seconds to be sure that docker instances are up and running..." + sleep(10) + puts "Running scripts/seed.sh..." + puts %x(cd #{args['sitename']}; gdev run web ./scripts/seed.sh) + + puts "Point your browser to https://#{args['sitename']}.test" + + # TODO: help for setting up stage and production else puts "Directory "+args['sitename']+" exists, please use another sitename." puts CREATE_HELP From e61b6b770bf6ea5d005ae85c7793dfbbd8b49aad Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Tue, 20 Sep 2016 09:14:08 +0300 Subject: [PATCH 05/15] changed all %x occurences to backticks --- bin/gdev | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/bin/gdev b/bin/gdev index d6d4538..40b9c05 100755 --- a/bin/gdev +++ b/bin/gdev @@ -240,7 +240,7 @@ HEREDOC data_docker_id=`docker-compose ps -q #{container_name}` if $?.success? and not data_docker_id.empty? # Get the data container port - data_docker_ports = %x(docker inspect --format='{{json .NetworkSettings.Ports}}' #{data_docker_id}) + data_docker_ports = `docker inspect --format='{{json .NetworkSettings.Ports}}' #{data_docker_id}` if $?.success? and data_docker_ports begin data_docker_ports_obj = JSON.parse(data_docker_ports) @@ -382,10 +382,10 @@ HEREDOC unless Dir.exists?(args['sitename']) # clone wp-project from github puts "Cloning wp-project from git@github.com:devgeniem/wp-project.git to #{args['sitename']}..." - puts %x(git clone git@github.com:devgeniem/wp-project.git #{args['sitename']}) + puts `git clone git@github.com:devgeniem/wp-project.git #{args['sitename']}` if args['theme'] puts "Cloning theme from #{args['theme']}..." - puts %x(git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{args['sitename']}) + puts `git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{args['sitename']}` else # TODO: get default theme url from ~/.gdev/gdevconf.yml # do not get theme if default is not set @@ -400,7 +400,7 @@ HEREDOC when 'dustpress' # require dustpress components puts "Installing dustpress, dustpress-debugger and dustpress-js with composer..." - puts %x(cd #{args['sitename']}; composer require devgeniem/dustpress:1.* devgeniem/dustpress-debugger:1.* devgeniem/dustpress-js:*) + puts `cd #{args['sitename']}; composer require devgeniem/dustpress:1.* devgeniem/dustpress-debugger:1.* devgeniem/dustpress-js:*` else puts "Component "+component+" not supported." end @@ -435,18 +435,26 @@ HEREDOC # composer install puts "Running composer install..." - puts %x(cd #{args['sitename']}; composer install) + puts `cd #{args['sitename']}; composer install` # gdev up puts "Running gdev up..." - puts %x(cd #{args['sitename']}; gdev up) + puts `cd #{args['sitename']}; gdev up` # seed (install wp) puts "Waiting for 10 seconds to be sure that docker instances are up and running..." sleep(10) puts "Running scripts/seed.sh..." - puts %x(cd #{args['sitename']}; gdev run web ./scripts/seed.sh) + puts `cd #{args['sitename']}; gdev run web ./scripts/seed.sh` - puts "Point your browser to https://#{args['sitename']}.test" + # temporary fix for redis-cache plugin, remove this when plugin works + puts "Copying object-cache.php in place (temporary fix for redis-cache plugin)..." + `cp #{args['sitename']}/web/app/object-cache.php #{args['sitename']}/web/app/plugins/redis-cache/includes` + + # gdev reload + puts "Reloading gdev..." + puts `cd #{args['sitename']}; gdev reload` + + puts "Point your browser to https://#{args['sitename']}.test/wp-admin and log in" # TODO: help for setting up stage and production else From 86c73818f47f0aa8e24cc4aa7b932384e85e0e66 Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Thu, 22 Sep 2016 15:15:58 +0300 Subject: [PATCH 06/15] wizard with defaults --- bin/gdev | 144 ++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 133 insertions(+), 11 deletions(-) diff --git a/bin/gdev b/bin/gdev index 40b9c05..c5423f4 100755 --- a/bin/gdev +++ b/bin/gdev @@ -371,6 +371,13 @@ HEREDOC # Create new site def create_app(args) + + unless validate_string(args['sitename']) + puts "Sitename not valid." + puts CREATE_HELP + exit + end + puts "Creating project "+args['sitename']+"..." #puts args.inspect @@ -400,7 +407,7 @@ HEREDOC when 'dustpress' # require dustpress components puts "Installing dustpress, dustpress-debugger and dustpress-js with composer..." - puts `cd #{args['sitename']}; composer require devgeniem/dustpress:1.* devgeniem/dustpress-debugger:1.* devgeniem/dustpress-js:*` + puts `cd #{args["sitename"]}; composer require devgeniem/dustpress:1.* devgeniem/dustpress-debugger:1.* devgeniem/dustpress-js:*` else puts "Component "+component+" not supported." end @@ -435,28 +442,49 @@ HEREDOC # composer install puts "Running composer install..." - puts `cd #{args['sitename']}; composer install` + puts `cd #{args["sitename"]}; composer install` # gdev up puts "Running gdev up..." - puts `cd #{args['sitename']}; gdev up` + puts `cd #{args["sitename"]}; gdev up` # seed (install wp) puts "Waiting for 10 seconds to be sure that docker instances are up and running..." sleep(10) puts "Running scripts/seed.sh..." - puts `cd #{args['sitename']}; gdev run web ./scripts/seed.sh` + puts `cd #{args["sitename"]}; gdev run web ./scripts/seed.sh` # temporary fix for redis-cache plugin, remove this when plugin works puts "Copying object-cache.php in place (temporary fix for redis-cache plugin)..." - `cp #{args['sitename']}/web/app/object-cache.php #{args['sitename']}/web/app/plugins/redis-cache/includes` + `cp #{args["sitename"]}/web/app/object-cache.php #{args["sitename"]}/web/app/plugins/redis-cache/includes` # gdev reload puts "Reloading gdev..." - puts `cd #{args['sitename']}; gdev reload` + puts `cd #{args["sitename"]}; gdev reload` puts "Point your browser to https://#{args['sitename']}.test/wp-admin and log in" # TODO: help for setting up stage and production + puts "" + puts "To create stage environment run:" + puts "$ flynn -c stage create #{args['sitename']} --remote=\"\"" + puts "" + puts "Add mysql and redis resources for project:" + puts "$ flynn -c stage -a upi resource add mysql" + puts "$ flynn -c stage -a upi resource add redis" + puts "" + puts "Set environment variables:" + puts "$ flynn -c stage -a #{args['sitename']} env set WP_ENV=staging" + puts "$ flynn -c stage -a #{args['sitename']} env set WP_HOME=https://#{args['sitename']}.#{args['stage']}" + puts "$ flynn -c stage -a #{args['sitename']} env set WP_SITEURL=https://#{args['sitename']}.#{args['stage']}" + puts "" + puts "To deploy your project to stage cluster, go to project directory root and run:" + puts "$ docker build --pull -t devgeniem/#{args['sitename']}:stable ." + puts "$ flynn -c stage -a #{args['sitename']} docker push devgeniem/#{args['sitename']}:stable" + puts "" + puts "Scale cluster as needed:" + puts "$ flynn -c stage -a #{args['sitename']} scale app=1" + puts "" + puts "More help with Flynn, visit: " else puts "Directory "+args['sitename']+" exists, please use another sitename." puts CREATE_HELP @@ -475,15 +503,109 @@ HEREDOC puts "Type "+args['type']+" not supported." end - puts "END." + end + + # validate string (alphanumeric chars and -) + def validate_string(string) + !string.match(/\A[-a-zA-Z0-9]*\z/).nil? + end + + def get_defaults(type) + defaults = Hash.new + if File.exist?(ENV['HOME']+'/.gdev/gdevconf.yml') + config = YAML.load(File.read(ENV['HOME']+"/.gdev/gdevconf.yml")) + defaults = config['create']['defaults'][type] + end + return defaults end def create_wizard() - # TODO: ask args and start creating app - puts "wizard" + # load default values + defaults = get_defaults('wordpress') + default_marker = "[default]" + project = Hash.new + puts "----------------------= Create new project =---------------------" + + puts "Name for the project:" + project['name']=gets.chomp + puts "" + puts "Project description:" + project['description']=gets.chomp + puts "" + puts "Sitename (lowercase characters, dashes and numbers only):" + project['sitename']=gets.chomp + unless validate_string(project['sitename']) + puts "Sitename (lowercase characters, dashes and numbers only):" + project['sitename']=gets.chomp + end + puts "" + puts "Project type (wordpress"+default_marker+", nodejs, silverbullet):" + project['type']=gets.chomp + # wordpress specific settings + if ['','wordpress'].include?(project['type']) + # show selected default value + if project['type'] == "" + project['type']="wordpress" + puts "wordpress" + end + puts "" + puts "Components (dustpress):" + project['components']=gets.chomp + puts "" + puts "Theme repository address, ssh or https (ssh://git@domain/theme.git):" + project['theme']=gets.chomp + puts "" + end + # set stage cluster domain + if defaults['stage'] + puts "Flynn stage cloud address ("+defaults['stage']+default_marker+"):" + else + puts "Flynn stage cloud address (stage.mydomain.com):" + end + project['stage']=gets.chomp + if project['stage'] == '' and defaults['stage'] + project['stage']=defaults['stage'] + puts defaults['stage'] + else + puts '-- not set --' + end + puts "" + # set production cluster domain + if defaults['production'] + puts "Flynn production cloud address ("+defaults['production']+default_marker+"):" + else + puts "Flynn production cloud address (cloud.mydomain.com):" + end + project['production']=gets.chomp + if project['production'] == '' and defaults['production'] + project['production']=defaults['production'] + puts defaults['production'] + else + puts '-- not set --' + end + puts "" + + puts "Environment variables file (envvars.yml)" + project['envvars']=gets.chomp + puts "" + puts "Project git repository, ssh or https (ssh://git@domain/my-app.git):" + project['git']=gets.chomp + + puts "" + puts "------------------------= Confirm input =------------------------" + project.each { |key,val| + puts key+": "+val + } + puts "-----= Enter Y to create project, something else to cancel =-----" + puts "" + confirm = gets.chomp + puts "" + if ['Y','y'].include?(confirm) + create_app(project) + else + puts "Cancelled." + end - # temporarily show usage help - puts CREATE_HELP exit end From 02e9f6f3a84999e0f092b1e4f4212a5d2745fa81 Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Thu, 22 Sep 2016 15:23:46 +0300 Subject: [PATCH 07/15] default theme from yaml file --- bin/gdev | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/bin/gdev b/bin/gdev index c5423f4..77ea394 100755 --- a/bin/gdev +++ b/bin/gdev @@ -552,8 +552,17 @@ HEREDOC puts "Components (dustpress):" project['components']=gets.chomp puts "" - puts "Theme repository address, ssh or https (ssh://git@domain/theme.git):" + if (defaults['theme']) + puts "Theme repository address, ssh or https ("+defaults['theme']+default_marker+"):" + else + puts "Theme repository address, ssh or https (ssh://git@domain/theme.git):" + end project['theme']=gets.chomp + if project['theme'] == '' and defaults['theme'] + project['theme']=defaults['theme'] + puts defaults['theme'] + else + end puts "" end # set stage cluster domain From 9952658cb819df15e646f3d759a3874ca6298e96 Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Thu, 22 Sep 2016 15:47:25 +0300 Subject: [PATCH 08/15] fixed stage setup help --- bin/gdev | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bin/gdev b/bin/gdev index 77ea394..b6c74b8 100755 --- a/bin/gdev +++ b/bin/gdev @@ -469,8 +469,8 @@ HEREDOC puts "$ flynn -c stage create #{args['sitename']} --remote=\"\"" puts "" puts "Add mysql and redis resources for project:" - puts "$ flynn -c stage -a upi resource add mysql" - puts "$ flynn -c stage -a upi resource add redis" + puts "$ flynn -c stage -a #{args['sitename']} resource add mysql" + puts "$ flynn -c stage -a #{args['sitename']} resource add redis" puts "" puts "Set environment variables:" puts "$ flynn -c stage -a #{args['sitename']} env set WP_ENV=staging" From 0941be269ed7d9c2553c3004dc59f8d72934401f Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Thu, 29 Sep 2016 23:47:19 +0300 Subject: [PATCH 09/15] remove theme .git directory, install node modules, set git remote url --- bin/gdev | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/bin/gdev b/bin/gdev index 40f9470..c8daa16 100755 --- a/bin/gdev +++ b/bin/gdev @@ -394,6 +394,9 @@ HEREDOC if args['theme'] puts "Cloning theme from #{args['theme']}..." puts `git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{args['sitename']}` + puts "Removing .git directory from theme..." + `rm -rf #{args['sitename']}/web/app/themes/#{args['sitename']}/.git` + puts "" else # TODO: get default theme url from ~/.gdev/gdevconf.yml # do not get theme if default is not set @@ -444,6 +447,8 @@ HEREDOC # composer install puts "Running composer install..." puts `cd #{args["sitename"]}; composer install` + puts "Running composer update..." + puts `cd #{args["sitename"]}; composer update` # gdev up puts "Running gdev up..." puts `cd #{args["sitename"]}; gdev up` @@ -453,14 +458,32 @@ HEREDOC sleep(10) puts "Running scripts/seed.sh..." puts `cd #{args["sitename"]}; gdev run web ./scripts/seed.sh` + puts "" # temporary fix for redis-cache plugin, remove this when plugin works puts "Copying object-cache.php in place (temporary fix for redis-cache plugin)..." `cp #{args["sitename"]}/web/app/object-cache.php #{args["sitename"]}/web/app/plugins/redis-cache/includes` + puts "" + + # install theme npm modules + puts "Installing theme node modules..." + puts `cd #{args["sitename"]}/web/app/themes/#{args["sitename"]}; npm install` + puts "" # gdev reload puts "Reloading gdev..." puts `cd #{args["sitename"]}; gdev reload` + puts "" + + # set git repository + if args['git'] == "" + puts "NO GIT REPOSITORY GIVEN!" + puts `cd #{args["sitename"]}; git remote rm origin` + else + puts "Changing git remote to #{args['git']}..." + puts `cd #{args["sitename"]}; git remote set-url origin #{args["git"]}` + end + puts "" puts "Point your browser to https://#{args['sitename']}.test/wp-admin and log in" From 61411fb973d8c4b852c426a40200defeef579c67 Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Fri, 30 Sep 2016 00:59:15 +0300 Subject: [PATCH 10/15] ask wether or not run npm install in theme directory --- bin/gdev | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/bin/gdev b/bin/gdev index c8daa16..759f1ed 100755 --- a/bin/gdev +++ b/bin/gdev @@ -466,9 +466,11 @@ HEREDOC puts "" # install theme npm modules - puts "Installing theme node modules..." - puts `cd #{args["sitename"]}/web/app/themes/#{args["sitename"]}; npm install` - puts "" + if args['npm_install'] + puts "Installing theme node modules..." + puts `cd #{args["sitename"]}/web/app/themes/#{args["sitename"]}; npm install` + puts "" + end # gdev reload puts "Reloading gdev..." @@ -589,6 +591,16 @@ HEREDOC end puts "" end + # run npm install in theme directory? + # TODO: default value + puts "Run npm install in theme directory? (Y/N)" + npm_install=gets.chomp + if ['Y','y'].include?(npm_install) + project['npm_install']=true + else + project['npm_install']=false + end + puts "" # set stage cluster domain if defaults['stage'] puts "Flynn stage cloud address ("+defaults['stage']+default_marker+"):" @@ -627,7 +639,7 @@ HEREDOC puts "" puts "------------------------= Confirm input =------------------------" project.each { |key,val| - puts key+": "+val + puts key+": "+val.to_s } puts "-----= Enter Y to create project, something else to cancel =-----" puts "" From 107a4ab79db17c6259fb4cd3b440f1d05d9b90bd Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Tue, 4 Apr 2017 11:43:29 +0300 Subject: [PATCH 11/15] removed unused parameters from create command, updated readme --- README.md | 29 ++++++++++++++++++++++++++++- bin/gdev | 12 +++--------- 2 files changed, 31 insertions(+), 10 deletions(-) mode change 100644 => 100755 README.md diff --git a/README.md b/README.md old mode 100644 new mode 100755 index 377db19..f683889 --- a/README.md +++ b/README.md @@ -86,6 +86,30 @@ $ docker ps -a # Open bash into any container $ docker exec -it $CONTAINER_ID bash + +# Create new project (interactive wizard for setting up project) +$ gdev create +``` + +## Creating new project +Before creating a new project you should setup a GIT repository for your new project. + +It's also advisable to create a config file to your home directory with some default values. File should be named ~/.gdev/gdevconf.yml + +Example gdevconf.yml: +``` +create: + defaults: + wordpress: + # Flynn stage cloud address + stage: stage.yourdomain.com + # Flynn production cloud address + production: production.yourdomain.com + smtp_host: "172.17.0.1" + components: "dustpress" + theme: "ssh://git@gitdomain.com/path/dustpress-theme-boilerplate.git" + nodejs: TODO + silverbullet: TODO ``` ## Workflow @@ -105,6 +129,8 @@ To resolve this delete stopped containers, dangling images and dangling volumes. $ gdev cleanup ``` +If Docker for Mac still has a bug with freeing up disk space, dump databases you need and reset Docker for Mac settings. This will free all the space Docker is hogging. Then you will need to set up your projects again (import databases). + #### When in doubt, update and restart everything To update all containers and settings run following global commands: @@ -129,6 +155,7 @@ $ gdev reload * [Nicholas Silva](https://github.com/silvamerica), creator. * [Onni Hakala](https://github.com/onnimonni), forked the gdev version. +* [Ville Pietarinen](https://github.com/villepietarinen), initial sync and create commands, fixes and development. ## Contributing @@ -142,4 +169,4 @@ $ gdev reload `gdev` is available under the MIT license. See the LICENSE file for more info. -Copyright 2016 Geniem Oy. +Copyright 2017 Geniem Oy. diff --git a/bin/gdev b/bin/gdev index 37895aa..955d544 100755 --- a/bin/gdev +++ b/bin/gdev @@ -43,7 +43,7 @@ HEREDOC PROXY_MODIFIED=%w{up run} OTHER_COMMANDS=%w{wait reload cleanup machine update service status shell exec sync create} - CREATE_HELP='Usage: $ gdev create --type=wordpress --components=dustpress --stage=stage.mydomain.com --production=cloud.mydomain.com --theme=ssh://git@domain:/theme.git --name="My app" --description="Short description of my app" --sitename=myapp --envvars=envvars.json --stage=stage.mydomain.com --production=cloud.mydomain.com --git=ssh://git@mydomain:/my-app.git' + CREATE_HELP='Usage: $ gdev create --type=wordpress --components=dustpress --stage=stage.mydomain.com --production=cloud.mydomain.com --theme=ssh://git@domain:/theme.git --sitename=myapp --envvars=envvars.json --stage=stage.mydomain.com --production=production.mydomain.com --git=ssh://git@mydomain:/my-app.git' def initialize(args) if PROXY_UNMODIFIED_TO_COMPOSE.include?(args[0]) @@ -642,12 +642,6 @@ HEREDOC project = Hash.new puts "----------------------= Create new project =---------------------" - puts "Name for the project:" - project['name']=gets.chomp - puts "" - puts "Project description:" - project['description']=gets.chomp - puts "" puts "Sitename (lowercase characters, dashes and numbers only):" project['sitename']=gets.chomp unless validate_string(project['sitename']) @@ -683,7 +677,7 @@ HEREDOC end # run npm install in theme directory? # TODO: default value - puts "Run npm install in theme directory? (Y/N)" + puts "Run npm install in theme directory after setup? (Y/N)" npm_install=gets.chomp if ['Y','y'].include?(npm_install) project['npm_install']=true @@ -709,7 +703,7 @@ HEREDOC if defaults['production'] puts "Flynn production cloud address ("+defaults['production']+default_marker+"):" else - puts "Flynn production cloud address (cloud.mydomain.com):" + puts "Flynn production cloud address (production.mydomain.com):" end project['production']=gets.chomp if project['production'] == '' and defaults['production'] From 5f88115ec0809709f98a1e0b53e8b44dad84f9fb Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Tue, 4 Apr 2017 13:42:52 +0300 Subject: [PATCH 12/15] correct default theme, more help, removed unnessessary steps from wizard --- README.md | 2 +- bin/gdev | 74 ++++++++++++++++++++++++++++++++----------------------- 2 files changed, 44 insertions(+), 32 deletions(-) diff --git a/README.md b/README.md index f683889..0375ace 100755 --- a/README.md +++ b/README.md @@ -107,7 +107,7 @@ create: production: production.yourdomain.com smtp_host: "172.17.0.1" components: "dustpress" - theme: "ssh://git@gitdomain.com/path/dustpress-theme-boilerplate.git" + theme: "git@github.com:devgeniem/wp-starter-dustpress-theme.git" nodejs: TODO silverbullet: TODO ``` diff --git a/bin/gdev b/bin/gdev index 955d544..a1e5953 100755 --- a/bin/gdev +++ b/bin/gdev @@ -43,7 +43,7 @@ HEREDOC PROXY_MODIFIED=%w{up run} OTHER_COMMANDS=%w{wait reload cleanup machine update service status shell exec sync create} - CREATE_HELP='Usage: $ gdev create --type=wordpress --components=dustpress --stage=stage.mydomain.com --production=cloud.mydomain.com --theme=ssh://git@domain:/theme.git --sitename=myapp --envvars=envvars.json --stage=stage.mydomain.com --production=production.mydomain.com --git=ssh://git@mydomain:/my-app.git' + CREATE_HELP='Usage: $ gdev create --type=wordpress --components=dustpress --stage=stage.mydomain.com --production=cloud.mydomain.com --theme=ssh://git@domain:/theme.git --sitename=myapp --stage=stage.mydomain.com --production=production.mydomain.com --git=ssh://git@mydomain:/my-app.git' def initialize(args) if PROXY_UNMODIFIED_TO_COMPOSE.include?(args[0]) @@ -397,7 +397,7 @@ HEREDOC # got arguments unless args.empty? # TODO: parse_args method - required_args = ['sitename', 'envvars', 'type'] + required_args = ['sitename', 'type'] # loop given arguments used_args = [] args_hash = Hash.new @@ -512,7 +512,12 @@ HEREDOC themename_file_names = [ "#{args['sitename']}/.drone.yml", "#{args['sitename']}/config/application.php", - "#{args['sitename']}/docker-compose.yml" + "#{args['sitename']}/docker-compose.yml", + "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/extras.php", + "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/images.php", + "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/setup.php", + "#{args['sitename']}/web/app/themes/#{args['sitename']}/package.json", + "#{args['sitename']}/web/app/themes/#{args['sitename']}/style.css" ] themename_file_names.each do |file_name| text = File.read(file_name) @@ -527,6 +532,9 @@ HEREDOC new_contents = text.gsub(/PROJECTNAME/, "#{args['sitename']}") File.open(file_name, "w") {|file| file.puts new_contents } end + + # TODO: replace themename-textdomain (lowercase) from lib/setup.php and style.css + # change project test address in docker-compose.yml for example wordpress.test -> client-name.test docker_compose = File.read("#{args['sitename']}/docker-compose.yml") docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test") @@ -535,25 +543,10 @@ HEREDOC # TODO: Add all people working in the project into authors section of composer.json and rename the project devgeniem/wp-project->devgeniem/client in composer.json # composer install - puts "Running composer install..." - puts `cd #{args["sitename"]}; composer install` + #puts "Running composer install..." + #puts `cd #{args["sitename"]}; composer install` puts "Running composer update..." puts `cd #{args["sitename"]}; composer update` - # gdev up - puts "Running gdev up..." - puts `cd #{args["sitename"]}; gdev up` - - # seed (install wp) - puts "Waiting for 10 seconds to be sure that docker instances are up and running..." - sleep(10) - puts "Running scripts/seed.sh..." - puts `cd #{args["sitename"]}; gdev run web ./scripts/seed.sh` - puts "" - - # temporary fix for redis-cache plugin, remove this when plugin works - puts "Copying object-cache.php in place (temporary fix for redis-cache plugin)..." - `cp #{args["sitename"]}/web/app/object-cache.php #{args["sitename"]}/web/app/plugins/redis-cache/includes` - puts "" # install theme npm modules if args['npm_install'] @@ -561,11 +554,24 @@ HEREDOC puts `cd #{args["sitename"]}/web/app/themes/#{args["sitename"]}; npm install` puts "" end + + # TODO: seed (install wp) + #puts "Waiting for 10 seconds to be sure that docker instances are up and running..." + #sleep(10) + #puts "Running scripts/seed.sh..." + #puts `cd #{args["sitename"]}; gdev run web ./scripts/seed.sh` + #puts "" + + # temporary fix for redis-cache plugin, remove this when plugin works + #puts "Copying object-cache.php in place (temporary fix for redis-cache plugin)..." + #`cp #{args["sitename"]}/web/app/object-cache.php #{args["sitename"]}/web/app/plugins/redis-cache/includes` + #puts "" + # gdev reload - puts "Reloading gdev..." - puts `cd #{args["sitename"]}; gdev reload` - puts "" + #puts "Reloading gdev..." + #puts `cd #{args["sitename"]}; gdev reload` + #puts "" # set git repository if args['git'] == "" @@ -577,6 +583,11 @@ HEREDOC end puts "" + # gdev up + puts "Running gdev up..." + puts `cd #{args["sitename"]}; gdev up` + puts "" + puts "Point your browser to https://#{args['sitename']}.test/wp-admin and log in" # TODO: help for setting up stage and production @@ -592,15 +603,19 @@ HEREDOC puts "$ flynn -c stage -a #{args['sitename']} env set WP_ENV=staging" puts "$ flynn -c stage -a #{args['sitename']} env set WP_HOME=https://#{args['sitename']}.#{args['stage']}" puts "$ flynn -c stage -a #{args['sitename']} env set WP_SITEURL=https://#{args['sitename']}.#{args['stage']}" + puts "$ flynn -c stage -a #{args['sitename']} env set SERVER_NAME=#{args['sitename']}.#{args['stage']}" + puts "" + puts "Set other environment variables as needed (eg. SMTP_HOST, SMTP_USER etc)" + puts "Refer to your (company) specific documentation for more settings to set up" puts "" puts "To deploy your project to stage cluster, go to project directory root and run:" - puts "$ docker build --pull -t devgeniem/#{args['sitename']}:stable ." - puts "$ flynn -c stage -a #{args['sitename']} docker push devgeniem/#{args['sitename']}:stable" + puts "$ docker build --pull -t devgeniem/#{args['sitename']} ." + puts "$ flynn -c stage -a #{args['sitename']} docker push devgeniem/#{args['sitename']}" puts "" puts "Scale cluster as needed:" puts "$ flynn -c stage -a #{args['sitename']} scale app=1" puts "" - puts "More help with Flynn, visit: " + puts "More help with Flynn, visit: https://flynn.io/docs/basics" else puts "Directory "+args['sitename']+" exists, please use another sitename." puts CREATE_HELP @@ -663,9 +678,9 @@ HEREDOC project['components']=gets.chomp puts "" if (defaults['theme']) - puts "Theme repository address, ssh or https ("+defaults['theme']+default_marker+"):" + puts "Theme repository address ("+defaults['theme']+default_marker+"):" else - puts "Theme repository address, ssh or https (ssh://git@domain/theme.git):" + puts "Theme repository address (git@domain/theme.git):" end project['theme']=gets.chomp if project['theme'] == '' and defaults['theme'] @@ -714,9 +729,6 @@ HEREDOC end puts "" - puts "Environment variables file (envvars.yml)" - project['envvars']=gets.chomp - puts "" puts "Project git repository, ssh or https (ssh://git@domain/my-app.git):" project['git']=gets.chomp From d9c8b54c2e04fcb85da38002c9dad5c59ba05eb8 Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Wed, 5 Apr 2017 13:54:48 +0300 Subject: [PATCH 13/15] textdomain replaces to theme --- bin/gdev | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/bin/gdev b/bin/gdev index a1e5953..6b181c7 100755 --- a/bin/gdev +++ b/bin/gdev @@ -524,6 +524,15 @@ HEREDOC new_contents = text.gsub(/THEMENAME/, "#{args['sitename']}") File.open(file_name, "w") {|file| file.puts new_contents } end + textdomain_file_names = [ + "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/setup.php", + "#{args['sitename']}/web/app/themes/#{args['sitename']}/style.css" + ] + textdomain_file_names.each do |file_name| + text = File.read(file_name) + new_contents = text.gsub(/themename-textdomain/, "#{args['sitename'].downcase}-textdomain") + File.open(file_name, "w") {|file| file.puts new_contents } + end projectname_file_names = [ "#{args['sitename']}/.drone.yml" ] @@ -533,8 +542,6 @@ HEREDOC File.open(file_name, "w") {|file| file.puts new_contents } end - # TODO: replace themename-textdomain (lowercase) from lib/setup.php and style.css - # change project test address in docker-compose.yml for example wordpress.test -> client-name.test docker_compose = File.read("#{args['sitename']}/docker-compose.yml") docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test") @@ -657,10 +664,10 @@ HEREDOC project = Hash.new puts "----------------------= Create new project =---------------------" - puts "Sitename (lowercase characters, dashes and numbers only):" + puts "Sitename (normal characters, dashes and numbers only):" project['sitename']=gets.chomp unless validate_string(project['sitename']) - puts "Sitename (lowercase characters, dashes and numbers only):" + puts "Sitename (normal characters, dashes and numbers only):" project['sitename']=gets.chomp end puts "" From ce3ccad87c69b8169ebb3d7149b904e2eca8213d Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Tue, 11 Apr 2017 14:17:18 +0300 Subject: [PATCH 14/15] string replaces to wp-project --- bin/gdev | 50 +++++++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 23 deletions(-) diff --git a/bin/gdev b/bin/gdev index 6b181c7..008d66f 100755 --- a/bin/gdev +++ b/bin/gdev @@ -508,7 +508,7 @@ HEREDOC } end # replace all THEMENAME and PROJECTNAME references from all files from this project to your project name - puts "Replacing THEMENAME and PROJECTNAME strings from all project files with #{args['sitename']}..." + puts "Replacing 'THEMENAME' strings from all project files with '#{args['sitename']}'..." themename_file_names = [ "#{args['sitename']}/.drone.yml", "#{args['sitename']}/config/application.php", @@ -524,28 +524,32 @@ HEREDOC new_contents = text.gsub(/THEMENAME/, "#{args['sitename']}") File.open(file_name, "w") {|file| file.puts new_contents } end + puts "Replacing 'themename-textdomain' strings from all project files with '#{args['sitename'].downcase}-td'..." textdomain_file_names = [ "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/setup.php", "#{args['sitename']}/web/app/themes/#{args['sitename']}/style.css" ] textdomain_file_names.each do |file_name| text = File.read(file_name) - new_contents = text.gsub(/themename-textdomain/, "#{args['sitename'].downcase}-textdomain") + new_contents = text.gsub(/themename-textdomain/, "#{args['sitename'].downcase}-td") File.open(file_name, "w") {|file| file.puts new_contents } end - projectname_file_names = [ - "#{args['sitename']}/.drone.yml" + puts "Replacing 'wordpress.test' strings from all project files with '#{args['sitename'].downcase}.test'..." + wordpresstest_file_names = [ + "#{args['sitename']}/.drone.yml", + "#{args['sitename']}/docker-compose.yml", + "#{args['sitename']}/scripts/seed.sh" ] - projectname_file_names.each do |file_name| + wordpresstest_file_names.each do |file_name| text = File.read(file_name) - new_contents = text.gsub(/PROJECTNAME/, "#{args['sitename']}") + new_contents = text.gsub(/wordpress.test/, "#{args['sitename'].downcase}.test") File.open(file_name, "w") {|file| file.puts new_contents } end # change project test address in docker-compose.yml for example wordpress.test -> client-name.test - docker_compose = File.read("#{args['sitename']}/docker-compose.yml") - docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test") - File.open("#{args['sitename']}/docker-compose.yml", "w") {|file| file.puts docker_compose_replace } + #docker_compose = File.read("#{args['sitename']}/docker-compose.yml") + #docker_compose_replace = docker_compose.gsub(/wordpress.test/, "#{args['sitename']}.test") + #File.open("#{args['sitename']}/docker-compose.yml", "w") {|file| file.puts docker_compose_replace } # TODO: Add all people working in the project into authors section of composer.json and rename the project devgeniem/wp-project->devgeniem/client in composer.json @@ -595,36 +599,36 @@ HEREDOC puts `cd #{args["sitename"]}; gdev up` puts "" - puts "Point your browser to https://#{args['sitename']}.test/wp-admin and log in" + puts "Point your browser to https://#{args['sitename'].downcase}.test/wp-admin and log in" # TODO: help for setting up stage and production puts "" puts "To create stage environment run:" - puts "$ flynn -c stage create #{args['sitename']} --remote=\"\"" + puts "$ flynn -c stage create #{args['sitename'].downcase} --remote=\"\"" puts "" puts "Add mysql and redis resources for project:" - puts "$ flynn -c stage -a #{args['sitename']} resource add mysql" - puts "$ flynn -c stage -a #{args['sitename']} resource add redis" + puts "$ flynn -c stage -a #{args['sitename'].downcase} resource add mysql" + puts "$ flynn -c stage -a #{args['sitename'].downcase} resource add redis" puts "" puts "Set environment variables:" - puts "$ flynn -c stage -a #{args['sitename']} env set WP_ENV=staging" - puts "$ flynn -c stage -a #{args['sitename']} env set WP_HOME=https://#{args['sitename']}.#{args['stage']}" - puts "$ flynn -c stage -a #{args['sitename']} env set WP_SITEURL=https://#{args['sitename']}.#{args['stage']}" - puts "$ flynn -c stage -a #{args['sitename']} env set SERVER_NAME=#{args['sitename']}.#{args['stage']}" + puts "$ flynn -c stage -a #{args['sitename'].downcase} env set WP_ENV=staging" + puts "$ flynn -c stage -a #{args['sitename'].downcase} env set WP_HOME=https://#{args['sitename'].downcase}.#{args['stage']}" + puts "$ flynn -c stage -a #{args['sitename'].downcase} env set WP_SITEURL=https://#{args['sitename'].downcase}.#{args['stage']}" + puts "$ flynn -c stage -a #{args['sitename'].downcase} env set SERVER_NAME=#{args['sitename'].downcase}.#{args['stage']}" puts "" puts "Set other environment variables as needed (eg. SMTP_HOST, SMTP_USER etc)" puts "Refer to your (company) specific documentation for more settings to set up" puts "" puts "To deploy your project to stage cluster, go to project directory root and run:" - puts "$ docker build --pull -t devgeniem/#{args['sitename']} ." - puts "$ flynn -c stage -a #{args['sitename']} docker push devgeniem/#{args['sitename']}" + puts "$ docker build --pull -t devgeniem/#{args['sitename'].downcase} ." + puts "$ flynn -c stage -a #{args['sitename'].downcase} docker push devgeniem/#{args['sitename'].downcase}" puts "" puts "Scale cluster as needed:" - puts "$ flynn -c stage -a #{args['sitename']} scale app=1" + puts "$ flynn -c stage -a #{args['sitename'].downcase} scale app=1" puts "" puts "More help with Flynn, visit: https://flynn.io/docs/basics" else - puts "Directory "+args['sitename']+" exists, please use another sitename." + puts "Directory "+args['sitename'].downcase+" exists, please use another sitename." puts CREATE_HELP exit @@ -664,10 +668,10 @@ HEREDOC project = Hash.new puts "----------------------= Create new project =---------------------" - puts "Sitename (normal characters, dashes and numbers only):" + puts "Sitename (CamelCase alphanumeric string, dashes allowed):" project['sitename']=gets.chomp unless validate_string(project['sitename']) - puts "Sitename (normal characters, dashes and numbers only):" + puts "Sitename (CamelCase alphanumeric string, dashes allowed):" project['sitename']=gets.chomp end puts "" From 39adbc793edd091d4ad3506545b8470a6c9fd84b Mon Sep 17 00:00:00 2001 From: Ville Pietarinen Date: Tue, 11 Apr 2017 15:10:54 +0300 Subject: [PATCH 15/15] run seed after wp install --- bin/gdev | 64 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/bin/gdev b/bin/gdev index 008d66f..49e709e 100755 --- a/bin/gdev +++ b/bin/gdev @@ -473,6 +473,8 @@ HEREDOC #puts args.inspect + themename=args['sitename'].tr('-',''); + case args['type'] when "wordpress" # setup wordpress project @@ -483,9 +485,9 @@ HEREDOC puts `git clone git@github.com:devgeniem/wp-project.git #{args['sitename']}` if args['theme'] puts "Cloning theme from #{args['theme']}..." - puts `git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{args['sitename']}` + puts `git clone #{args['theme']} #{args['sitename']}/web/app/themes/#{themename}` puts "Removing .git directory from theme..." - `rm -rf #{args['sitename']}/web/app/themes/#{args['sitename']}/.git` + `rm -rf #{args['sitename']}/web/app/themes/#{themename}/.git` puts "" else # TODO: get default theme url from ~/.gdev/gdevconf.yml @@ -507,27 +509,28 @@ HEREDOC end } end - # replace all THEMENAME and PROJECTNAME references from all files from this project to your project name + # replace all THEMENAME (namespace) references from all files from this project to your project name puts "Replacing 'THEMENAME' strings from all project files with '#{args['sitename']}'..." themename_file_names = [ "#{args['sitename']}/.drone.yml", "#{args['sitename']}/config/application.php", "#{args['sitename']}/docker-compose.yml", - "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/extras.php", - "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/images.php", - "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/setup.php", - "#{args['sitename']}/web/app/themes/#{args['sitename']}/package.json", - "#{args['sitename']}/web/app/themes/#{args['sitename']}/style.css" + "#{args['sitename']}/web/app/themes/#{themename}/lib/extras.php", + "#{args['sitename']}/web/app/themes/#{themename}/lib/images.php", + "#{args['sitename']}/web/app/themes/#{themename}/lib/setup.php", + "#{args['sitename']}/web/app/themes/#{themename}/package.json", + "#{args['sitename']}/web/app/themes/#{themename}/style.css" ] themename_file_names.each do |file_name| text = File.read(file_name) - new_contents = text.gsub(/THEMENAME/, "#{args['sitename']}") + # remove dashes from namespace strings + new_contents = text.gsub(/THEMENAME/, "#{args['sitename'].tr('-','')}") File.open(file_name, "w") {|file| file.puts new_contents } end puts "Replacing 'themename-textdomain' strings from all project files with '#{args['sitename'].downcase}-td'..." textdomain_file_names = [ - "#{args['sitename']}/web/app/themes/#{args['sitename']}/lib/setup.php", - "#{args['sitename']}/web/app/themes/#{args['sitename']}/style.css" + "#{args['sitename']}/web/app/themes/#{themename}/lib/setup.php", + "#{args['sitename']}/web/app/themes/#{themename}/style.css" ] textdomain_file_names.each do |file_name| text = File.read(file_name) @@ -562,28 +565,10 @@ HEREDOC # install theme npm modules if args['npm_install'] puts "Installing theme node modules..." - puts `cd #{args["sitename"]}/web/app/themes/#{args["sitename"]}; npm install` + puts `cd #{args["sitename"]}/web/app/themes/#{themename}; npm install` puts "" end - # TODO: seed (install wp) - #puts "Waiting for 10 seconds to be sure that docker instances are up and running..." - #sleep(10) - #puts "Running scripts/seed.sh..." - #puts `cd #{args["sitename"]}; gdev run web ./scripts/seed.sh` - #puts "" - - # temporary fix for redis-cache plugin, remove this when plugin works - #puts "Copying object-cache.php in place (temporary fix for redis-cache plugin)..." - #`cp #{args["sitename"]}/web/app/object-cache.php #{args["sitename"]}/web/app/plugins/redis-cache/includes` - #puts "" - - - # gdev reload - #puts "Reloading gdev..." - #puts `cd #{args["sitename"]}; gdev reload` - #puts "" - # set git repository if args['git'] == "" puts "NO GIT REPOSITORY GIVEN!" @@ -599,6 +584,16 @@ HEREDOC puts `cd #{args["sitename"]}; gdev up` puts "" + # running seed + if args['run_seed'] + puts "Waiting for 10 seconds to be sure that docker instances are up and running..." + sleep(10) + puts "" + puts "Running seed (Installing WordPress)..." + puts `cd #{args["sitename"]}; gdev exec scripts/seed.sh` + puts "" + end + puts "Point your browser to https://#{args['sitename'].downcase}.test/wp-admin and log in" # TODO: help for setting up stage and production @@ -711,6 +706,15 @@ HEREDOC project['npm_install']=false end puts "" + # run seed after setup? + puts "Run seed after installation? (Y/N)" + run_seed=gets.chomp + if ['Y','y'].include?(run_seed) + project['run_seed']=true + else + project['run_seed']=false + end + puts "" # set stage cluster domain if defaults['stage'] puts "Flynn stage cloud address ("+defaults['stage']+default_marker+"):"