wp-docker 0.0.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eff499c069bd5495eb0643be4f76fa8164c39f56
4
- data.tar.gz: 794abbd90b8a0a17777463ffcb4ce9b86be26660
3
+ metadata.gz: 251fed4e3a00b33681ceacf7e1e8d115252671dc
4
+ data.tar.gz: '08944dc38a10df399711d91358e773777d5a7bf1'
5
5
  SHA512:
6
- metadata.gz: 9405c72167887ffe47f00afddd94844a034e1ac0238d53d925e6a706ff108f3f413597d2cfaa8a9ac9e76acf9a6e3a9dde1def35d5fd04c698a685e3de0b664c
7
- data.tar.gz: f10e698257e2e5283607afc27d4c0fa99164145257ffa02fe7b0f1da638186d50bf93e73fa6dd812615885102d7cb8a445fd083a72e19ccecd7b904f61260b99
6
+ metadata.gz: b24012f68ccd1e8aeca2a4f25169248439f3bc98ae5e9449acb2324126b8a16e74a36f1177918c198ff91d51af92e2cf0c011ed64d309c05c8bf4bc09f1bacfe
7
+ data.tar.gz: cedc1bed35dcd00b00ff774c35a3b1156ef631c5f23680a74e4af8a72189bbb093263ecc7cceac5adf35f540e94d1e19edcbfc9ada97204eee1f30a562f34111
data/README.md CHANGED
@@ -1,14 +1,24 @@
1
- # WP-DOCKER
1
+ # WP-Docker
2
2
 
3
- The easiest to for WordPress using Docker containers
3
+ The easiest way to develop WordPress using Docker containers.
4
4
 
5
5
  ## Install
6
6
 
7
+ ```
8
+ # Using RubyGems
9
+ $ sudo gem install wp-docker
10
+ ```
11
+
7
12
  ## Usage
8
13
 
9
- WP-DOCKER provides a command-line interface to create and manage WordPress development environments using Docker:
14
+ WP-Docker provides a command-line interface to create and manage WordPress development environments using Docker:
10
15
 
11
16
  ```
17
+ $ wp-docker
18
+
19
+ ========================================
20
+ | WordPress Docker Environment Manager |
21
+ ========================================
12
22
 
13
23
  Usage wp-docker <command> [<options>]
14
24
 
@@ -26,7 +36,6 @@ Commands:
26
36
  help Show this help
27
37
  ```
28
38
 
29
-
30
39
  ## Contributing
31
40
 
32
41
  * If you have found a bug or if you have a feature request, please report them at this repository issues section.
data/bin/wp-docker CHANGED
@@ -1,14 +1,11 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- ##
4
- # Test command:
5
- # docker-compose down; rm -rf src; rm docker-compose.yml; rm Dockerfile-wp; wp-docker
6
- ##
7
-
8
3
  require "docker_manager"
9
4
  require "config_manager"
10
5
  require "commands/_loader"
11
6
 
7
+ require "version"
8
+
12
9
  require 'fileutils'
13
10
 
14
11
  require "highline/import"
@@ -20,76 +17,61 @@ UI_ENV_SPACES = 50
20
17
  UI_WEB_SPACES = 15
21
18
  UI_DB_SPACES = 15
22
19
 
23
- def main
24
- puts
25
- puts "========================================"
26
- puts "| WordPress Docker Environment Manager |"
27
- puts "========================================"
28
- puts
29
-
30
- case ARGV[0]
31
- when "create"
32
- wp_docker_create
33
- when "cli"
34
- wp_docker_execute_cli
35
- when "open"
36
- wp_docker_open_browser
37
- when "list"
38
- wp_docker_list
39
- when "shell"
40
- wp_docker_shell
41
- when "exec"
42
- wp_docker_exec
43
- when "start"
44
- wp_docker_start
45
- when "stop"
46
- wp_docker_stop
47
- when "remove"
48
- wp_docker_remove
49
- when "logs"
50
- wp_docker_logs
51
- else
52
- wp_docker_help
53
- end
54
-
55
- end
56
-
57
-
58
- def wp_docker_start
59
- docker_manager = DockerManager.new
60
- docker_manager.start ARGV[1]
61
- end
62
-
63
- def wp_docker_stop
64
- docker_manager = DockerManager.new
65
- docker_manager.stop ARGV[1]
66
- end
20
+ def main
21
+ name = "WP-Docker #{CONFIG::VERSION}"
22
+ puts
23
+ puts "=================================="
24
+ puts "| " + fill_spaces(name, 30) + " |"
25
+ puts "=================================="
26
+ puts
27
+
28
+ case ARGV[0]
29
+ when "create"
30
+ wp_docker_create
31
+ when "cli"
32
+ wp_docker_execute_cli
33
+ when "open"
34
+ wp_docker_open_browser
35
+ when "list"
36
+ wp_docker_list
37
+ when "shell"
38
+ wp_docker_shell
39
+ when "exec"
40
+ wp_docker_exec
41
+ when "start"
42
+ wp_docker_start
43
+ when "stop"
44
+ wp_docker_stop
45
+ when "remove"
46
+ wp_docker_remove
47
+ when "logs"
48
+ wp_docker_logs
49
+ else
50
+ wp_docker_help
51
+ end
67
52
 
68
- def wp_docker_remove
69
- docker_manager = DockerManager.new
70
- docker_manager.remove ARGV[1]
71
53
  end
72
54
 
73
55
  def fill_spaces(text, chars)
74
- fills = chars - text.to_s.length
75
- return str = text + (" " * fills)
56
+ fills = chars - text.to_s.length
57
+ return str = text + (" " * fills)
76
58
  end
77
59
 
78
60
  def docker_start port
79
- puts "Start docker compose"
80
- system "docker-compose up --build -d"
81
- puts
82
- puts "Opening browser: http://localhost:#{port}"
83
- print "wait ."
84
- sleep 5
85
- print "."
86
- sleep 5
87
- print "."
88
- sleep 5
89
- print "."
90
- sleep 5
91
- print "."
92
- system "open http://localhost:#{port}"
61
+ puts "Start docker compose"
62
+ system "docker-compose up --build -d"
63
+ puts
64
+ puts "Opening browser: http://localhost:#{port}"
65
+ print "wait ."
66
+ sleep 5
67
+ print "."
68
+ sleep 5
69
+ print "."
70
+ sleep 5
71
+ print "."
72
+ sleep 5
73
+ print "."
74
+ system "open http://localhost:#{port}"
93
75
 
94
76
  end
95
77
 
@@ -5,4 +5,7 @@ require_relative "./shell"
5
5
  require_relative "./cli"
6
6
  require_relative "./exec"
7
7
  require_relative "./browser"
8
- require_relative "./logs"
8
+ require_relative "./logs"
9
+ require_relative "./start"
10
+ require_relative "./stop"
11
+ require_relative "./remove"
data/lib/commands/cli.rb CHANGED
@@ -1,9 +1,15 @@
1
1
  def wp_docker_execute_cli
2
2
  config_manager = ConfigManager.new
3
+ unless config_manager.is_docker_compose_folder
4
+ puts "docker-compose.yml does not exists in current folder."
5
+ puts
6
+ exit
7
+ end
3
8
  name = config_manager.get_wp_container_name
4
9
  args = ARGV
5
10
  args.slice!(0)
6
11
 
7
12
  command="docker exec -it " + name + " wp --allow-root " + args.join(" ")
8
13
  system(command)
14
+ puts
9
15
  end
data/lib/commands/help.rb CHANGED
@@ -7,11 +7,11 @@ Commands:
7
7
  list Show available environments
8
8
  cli <command> Execute wp-cli in current wp-docker environment
9
9
  open Open browser
10
- shell Open shell in web container
10
+ shell [<environment>] Open shell in web container
11
11
  exec <command> Execute command in current wp-docker environment
12
- start <environment> Start wp-docker environment
13
- stop <environment> Stop wp-docker environment
14
- remove <environment> Remove wp-docker environment
12
+ start [<environment>] Start wp-docker environment (default: current)
13
+ stop [<environment>] Stop wp-docker environment (default: current)
14
+ remove [<environment>] Remove wp-docker environment (default: current)
15
15
  logs [-t] Show apache web logs
16
16
  help Show this help
17
17
 
@@ -0,0 +1,15 @@
1
+ def wp_docker_remove
2
+ config_manager = ConfigManager.new
3
+
4
+ if ARGV.count == 2
5
+ env = ARGV[1]
6
+ else
7
+ env = config_manager.get_wp_environment_name
8
+ end
9
+
10
+ if env != nil
11
+ docker_manager = DockerManager.new
12
+ docker_manager.remove env
13
+ end
14
+
15
+ end
@@ -1,7 +1,16 @@
1
1
  def wp_docker_shell
2
- config_manager = ConfigManager.new
3
- name = config_manager.get_wp_container_name
4
- command="docker exec -it " + name + " /bin/bash"
5
- puts command
2
+ config_manager = ConfigManager.new
3
+
4
+ if ARGV.count == 2
5
+ container = "wpd_web_" + ARGV[1]
6
+ else
7
+ container = config_manager.get_wp_container_name
8
+ end
9
+
10
+ if container != nil
11
+ command = "docker exec -it " + container + " /bin/bash"
12
+ puts " - Executing: " + command
13
+ puts
6
14
  system(command)
15
+ end
7
16
  end
@@ -0,0 +1,15 @@
1
+ def wp_docker_start
2
+ config_manager = ConfigManager.new
3
+
4
+ if ARGV.count == 2
5
+ env = ARGV[1]
6
+ else
7
+ env = config_manager.get_wp_environment_name
8
+ end
9
+
10
+ if env != nil
11
+ docker_manager = DockerManager.new
12
+ docker_manager.start env
13
+ end
14
+
15
+ end
@@ -0,0 +1,15 @@
1
+ def wp_docker_stop
2
+ config_manager = ConfigManager.new
3
+
4
+ if ARGV.count == 2
5
+ env = ARGV[1]
6
+ else
7
+ env = config_manager.get_wp_environment_name
8
+ end
9
+
10
+ if env != nil
11
+ docker_manager = DockerManager.new
12
+ docker_manager.stop env
13
+ end
14
+
15
+ end
@@ -7,6 +7,14 @@ class ConfigManager
7
7
  return name
8
8
  end
9
9
 
10
+ def get_wp_environment_name
11
+ file_lines = get_file_lines
12
+
13
+ container_line = file_lines.grep(/container_name: wpd_web/)
14
+ name = container_line[0].scan(/(wpd_[a-z]+)_(.+\d+)/)
15
+ return name[0][1]
16
+ end
17
+
10
18
  def get_wp_container_port
11
19
  file_lines = get_file_lines
12
20
 
@@ -15,18 +23,28 @@ class ConfigManager
15
23
  return ret[0][0]
16
24
  end
17
25
 
26
+ def is_docker_compose_directory
27
+
28
+ end
29
+
18
30
  def get_file_lines
19
- if !File.file?("docker-compose.yml")
20
- puts "docker-compose.yml does not exists"
31
+ unless self.is_docker_compose_folder
32
+ puts "docker-compose.yml does not exists in current directory. Choose one of the available environments."
33
+ puts
34
+ wp_docker_list
21
35
  exit
22
36
  end
23
37
 
24
38
  file_lines = File.readlines("docker-compose.yml")
25
- if !file_lines.grep(/## wp-docker ##/).any?
39
+ unless file_lines.grep(/## wp-docker ##/).any?
26
40
  puts "Invalid docker-compose.yml"
27
41
  exit
28
42
  end
29
43
 
30
- return file_lines
31
- end
44
+ file_lines
45
+ end
46
+
47
+ def is_docker_compose_folder
48
+ File.file?("docker-compose.yml")
49
+ end
32
50
  end
@@ -13,10 +13,19 @@ class DockerManager
13
13
  match = Array.new
14
14
  match_envs.each do |env|
15
15
 
16
- web_port = match_web.select { |item| item[1] == env[0] }
17
- db_port = match_db.select { |item| item[1] == env[0] }
16
+ web_port_match = match_web.select { |item| item[1] == env[0] }
17
+ db_port_match = match_db.select { |item| item[1] == env[0] }
18
18
 
19
- match.push({"env" => env[0], "web_port" => web_port[0][0], "db_port" => db_port[0][0]})
19
+ web_port = "<stopped>"
20
+ if web_port_match.count != 0
21
+ web_port = web_port_match[0][0]
22
+ end
23
+
24
+ db_port = "<stopped>"
25
+ if db_port_match.count != 0
26
+ db_port = db_port_match[0][0]
27
+ end
28
+ match.push({"env" => env[0], "web_port" => web_port, "db_port" => db_port})
20
29
  end
21
30
 
22
31
  return match
data/lib/version.rb ADDED
@@ -0,0 +1,3 @@
1
+ module CONFIG
2
+ VERSION = "0.1.2"
3
+ end
data/wp-docker.gemspec CHANGED
@@ -1,9 +1,11 @@
1
1
  lib = File.expand_path("../lib", __FILE__)
2
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
+ require "version"
5
+
4
6
  Gem::Specification.new do |spec|
5
7
  spec.name = "wp-docker"
6
- spec.version = "0.0.1"
8
+ spec.version = CONFIG::VERSION
7
9
  spec.authors = ["Jesus Serrano"]
8
10
  spec.email = ["wp-docker@onepointzero.org"]
9
11
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wp-docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jesus Serrano
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-08-21 00:00:00.000000000 Z
11
+ date: 2019-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -72,9 +72,13 @@ files:
72
72
  - lib/commands/help.rb
73
73
  - lib/commands/list.rb
74
74
  - lib/commands/logs.rb
75
+ - lib/commands/remove.rb
75
76
  - lib/commands/shell.rb
77
+ - lib/commands/start.rb
78
+ - lib/commands/stop.rb
76
79
  - lib/config_manager.rb
77
80
  - lib/docker_manager.rb
81
+ - lib/version.rb
78
82
  - templates/Dockerfile-wp
79
83
  - templates/docker-compose.yml.tpl
80
84
  - templates/gitignore.tpl