http_stub_docker 0.0.6 → 0.0.7

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: 5bfa76e30d19a57a04a55173ea3dc94d1323752d
4
- data.tar.gz: ccc0b10f133d5d701c6f2e53bc7fc5bc5c36787e
3
+ metadata.gz: 8b1404249f82152818d7773190064df58bd63409
4
+ data.tar.gz: 6725e6f4558a4430829dc56967c1eb968cf1600b
5
5
  SHA512:
6
- metadata.gz: bd30a56a11e4affa80610ea7ba04343165c224bb09e8bf5a18bc8df0061f1c0673f9c8e829364fda52f920d41a28461d7798f3c5f5428d222f55fdc2fa17eb15
7
- data.tar.gz: 8b4ba1fdf59bdb00d30cf346161aa8da95877f4e190aeca61592b437a07fd6b0301b4309687fd181d64c423a229381b93ce20a3fcfe5c5f944e1862991abbc71
6
+ metadata.gz: 54163a6a149cd3f500a8e68f0d0a3ee4efa1b396acc46cc02b4e69bb341971e8c4b12c4f80e48b8cad30e116cf7641a95cf36f98557130b8c1bc8def68c89ee2
7
+ data.tar.gz: 440258503904442758090e735702688de3f2c5c5651c2cc691863ced71bf16e54dddb6df88184cfc771c59c80ae17c9f4c14e5e363fa599642ebb1a1b27ad6bc
@@ -0,0 +1,28 @@
1
+ module HttpStubDocker
2
+ module Rake
3
+
4
+ class Arguments
5
+
6
+ DEFAULT_PORT = 5000
7
+
8
+ private_constant :DEFAULT_PORT
9
+
10
+ attr_reader :configurer, :stub_name, :stub_dir, :port, :external_base_uri, :version, :task_prefix
11
+
12
+ def initialize(args)
13
+ @port = DEFAULT_PORT
14
+ args.each { |name, value| self.instance_variable_set("@#{name}", value) }
15
+ @external_base_uri ||= "http://localhost:#{@port}"
16
+ @task_prefix = current_rake_namespace
17
+ end
18
+
19
+ private
20
+
21
+ def current_rake_namespace
22
+ ::Rake.application.current_scope.empty? ? "" : "#{::Rake.application.current_scope.to_a.reverse.join(":")}:"
23
+ end
24
+
25
+ end
26
+
27
+ end
28
+ end
@@ -15,7 +15,7 @@ module HttpStubDocker
15
15
  def define_build_task(args)
16
16
  desc "Builds the image"
17
17
  task(:build) do
18
- system "docker build -t #{args[:stub_name]} ."
18
+ system "docker build -t #{args.stub_name} ."
19
19
  end
20
20
  end
21
21
 
@@ -23,9 +23,9 @@ module HttpStubDocker
23
23
  desc "Starts a container"
24
24
  task(:start) do
25
25
  system "docker run -d " \
26
- "-p #{args[:port]}:80 " \
27
- "-e STUB_EXTERNAL_BASE_URI=#{args[:external_base_uri]} " \
28
- "#{args[:stub_name]}"
26
+ "-p #{args.port}:#{args.port} " \
27
+ "-e STUB_EXTERNAL_BASE_URI=#{args.external_base_uri} " \
28
+ "#{args.stub_name}"
29
29
  end
30
30
  end
31
31
 
@@ -44,7 +44,7 @@ module HttpStubDocker
44
44
  end
45
45
 
46
46
  def container_ids(args)
47
- `docker ps -a --filter ancestor=#{args[:stub_name]} --format "{{.ID}}"`.split
47
+ `docker ps -a --filter ancestor=#{args.stub_name} --format "{{.ID}}"`.split
48
48
  end
49
49
 
50
50
  end
@@ -9,7 +9,7 @@ module HttpStubDocker
9
9
 
10
10
  def initialize(args)
11
11
  define_test_task(args)
12
- define_commit_task
12
+ define_commit_task(args)
13
13
  define_publish_task(args)
14
14
  end
15
15
 
@@ -19,29 +19,29 @@ module HttpStubDocker
19
19
  desc "Verifies container is running"
20
20
  task(:test) do
21
21
  Bundler.require(:test)
22
- Wait.until!(description: "#{args[:stub_name]} is running", timeout_in_seconds: 10) do
23
- response = Net::HTTP.get_response(URI("#{args[:external_base_uri]}/http_stub"))
24
- raise "#{args[:stub_name]} is not running" unless response.code == "200"
22
+ Wait.until!(description: "#{args.stub_name} is running", timeout_in_seconds: 10) do
23
+ response = Net::HTTP.get_response(URI("#{args.external_base_uri}/http_stub"))
24
+ raise "#{args.stub_name} is not running" unless response.code == "200"
25
25
  end
26
- puts "#{args[:stub_name]} is running"
26
+ puts "#{args.stub_name} is running"
27
27
  end
28
28
  end
29
29
 
30
- def define_commit_task
30
+ def define_commit_task(args)
31
31
  desc "Ensures container runs"
32
- task(commit: %w{ docker:build docker:start }) do
32
+ task(commit: [ "#{args.task_prefix}docker:build", "#{args.task_prefix}docker:start" ]) do
33
33
  begin
34
- ::Rake::Task["docker:test"].invoke
34
+ ::Rake::Task["#{args.task_prefix}docker:test"].invoke
35
35
  ensure
36
- ::Rake::Task["docker:stop"].invoke
36
+ ::Rake::Task["#{args.task_prefix}docker:stop"].invoke
37
37
  end
38
38
  end
39
39
  end
40
40
 
41
41
  def define_publish_task(args)
42
42
  desc "Publishes the container"
43
- task(publish: "docker:build") do
44
- system "#{PUBLISH_SCRIPT} #{args[:stub_name]} #{args[:version]}"
43
+ task(publish: "#{args.task_prefix}docker:build") do
44
+ system "#{PUBLISH_SCRIPT} #{args.stub_name} #{args.version}"
45
45
  end
46
46
  end
47
47
 
@@ -3,6 +3,11 @@ module HttpStubDocker
3
3
 
4
4
  class ResourceTasks < ::Rake::TaskLib
5
5
 
6
+ RESOURCE_DIR = "#{HttpStubDocker::BASE_DIR}/resource".freeze
7
+ DOCKERFILE_TEMPLATE_PATH = "#{RESOURCE_DIR}/Dockerfile.erb".freeze
8
+
9
+ private_constant :RESOURCE_DIR, :DOCKERFILE_TEMPLATE_PATH
10
+
6
11
  def initialize(args)
7
12
  define_clobber_task(args)
8
13
  define_setup_task(args)
@@ -13,18 +18,37 @@ module HttpStubDocker
13
18
  def define_clobber_task(args)
14
19
  desc "Removes created Dockerfile and other resources"
15
20
  task(:clobber) do
16
- resources = Dir.entries("#{HttpStubDocker::BASE_DIR}/resource").find_all { |file| !File.directory?(file) }
17
- rm resources.map { |resource| "#{args[:stub_dir]}/#{resource}" }, force: true
21
+ resources = Dir.entries("#{HttpStubDocker::BASE_DIR}/resource")
22
+ .reject { |file| File.directory?(file) }
23
+ .map { |file| file.end_with?(".erb") ? file[0..-5] : file }
24
+ rm resources.map { |resource| "#{args.stub_dir}/#{resource}" }, force: true
18
25
  end
19
26
  end
20
27
 
21
28
  def define_setup_task(args)
22
29
  desc "Creates Dockerfile and other resources in stub directory"
23
30
  task(:setup) do
24
- cp_r "#{HttpStubDocker::BASE_DIR}/resource/.", args[:stub_dir]
31
+ copy_template_files(args)
32
+ copy_non_template_files(args)
25
33
  end
26
34
  end
27
35
 
36
+ def copy_non_template_files(args)
37
+ files = Dir.entries(RESOURCE_DIR)
38
+ .reject { |file| File.directory?(file) || file.end_with?(".erb") }
39
+ .map { |file| "#{RESOURCE_DIR}/#{file}" }
40
+ files.map { |file| "#{args.stub_dir}/#{File.basename(file)}" }
41
+ .select { |destination_file| File.exist?(destination_file) }
42
+ .each { |destination_file| rm_f(destination_file) }
43
+ cp_r files, args.stub_dir
44
+ end
45
+
46
+ def copy_template_files(args)
47
+ dockerfile_erb = ERB.new(File.read(DOCKERFILE_TEMPLATE_PATH))
48
+ dockerfile_content = dockerfile_erb.result(args.instance_eval { binding })
49
+ File.write("#{args.stub_dir}/Dockerfile", dockerfile_content)
50
+ end
51
+
28
52
  end
29
53
 
30
54
  end
@@ -4,12 +4,12 @@ module HttpStubDocker
4
4
  class ServerDaemonTasks
5
5
 
6
6
  def initialize(args)
7
- HttpStub::Server::Daemon.log_dir = ::File.expand_path("#{args[:stub_dir]}/tmp/log", __FILE__)
8
- HttpStub::Server::Daemon.pid_dir = ::File.expand_path("#{args[:stub_dir]}/tmp/pids", __FILE__)
7
+ HttpStub::Server::Daemon.log_dir = ::File.expand_path("#{args.stub_dir}/tmp/log", __FILE__)
8
+ HttpStub::Server::Daemon.pid_dir = ::File.expand_path("#{args.stub_dir}/tmp/pids", __FILE__)
9
9
 
10
- configurer = args[:configurer]
10
+ configurer = args.configurer
11
11
  configurer.stub_server.host = "localhost"
12
- configurer.stub_server.port = 80
12
+ configurer.stub_server.port = args.port
13
13
  HttpStub::Rake::ServerDaemonTasks.new(name: :stub_server, configurer: configurer)
14
14
  end
15
15
 
@@ -3,22 +3,19 @@ module HttpStubDocker
3
3
 
4
4
  class TaskGenerator < ::Rake::TaskLib
5
5
 
6
- DEFAULT_PORT = 5000
7
6
  DOCKER_TASK_CLASSES = [
8
7
  HttpStubDocker::Rake::ResourceTasks,
9
8
  HttpStubDocker::Rake::ContainerTasks,
10
9
  HttpStubDocker::Rake::PipelineTasks
11
10
  ].freeze
12
11
 
13
- private_constant :DEFAULT_PORT, :DOCKER_TASK_CLASSES
12
+ private_constant :DOCKER_TASK_CLASSES
14
13
 
15
14
  def initialize(args)
16
- resolved_args = args
17
- resolved_args[:port] ||= DEFAULT_PORT
18
- resolved_args[:external_base_uri] ||= "http://localhost:#{resolved_args[:port]}"
19
- HttpStubDocker::Rake::ServerDaemonTasks.new(resolved_args)
15
+ arguments = HttpStubDocker::Rake::Arguments.new(args)
16
+ HttpStubDocker::Rake::ServerDaemonTasks.new(arguments)
20
17
  namespace :docker do
21
- DOCKER_TASK_CLASSES.each { |task_class| task_class.new(resolved_args) }
18
+ DOCKER_TASK_CLASSES.each { |task_class| task_class.new(arguments) }
22
19
  end
23
20
  end
24
21
 
@@ -6,6 +6,7 @@ module HttpStubDocker
6
6
 
7
7
  end
8
8
 
9
+ require_relative 'http_stub_docker/rake/arguments'
9
10
  require_relative 'http_stub_docker/rake/server_daemon_tasks'
10
11
  require_relative 'http_stub_docker/rake/resource_tasks'
11
12
  require_relative 'http_stub_docker/rake/container_tasks'
@@ -7,6 +7,6 @@
7
7
  .gitignore
8
8
  .travis.yml
9
9
  bin
10
- Dockerfile
10
+ Dockerfile.erb
11
11
  log
12
12
  tmp
@@ -16,7 +16,7 @@ WORKDIR /root/app
16
16
  RUN bundle install --without development
17
17
 
18
18
  # Expose server port
19
- EXPOSE 80
19
+ EXPOSE <%= port %>
20
20
 
21
21
  # Start server & tail logs in order to sustain foreground process
22
22
  CMD trap exit TERM; bundle exec rake stub_server:start && tail -f tmp/log/stub_server_console.log
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: http_stub_docker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - dueckes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-31 00:00:00.000000000 Z
11
+ date: 2016-09-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0.42'
47
+ version: '0.43'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0.42'
54
+ version: '0.43'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: wait_until
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -88,13 +88,14 @@ extra_rdoc_files: []
88
88
  files:
89
89
  - "./bin/push_docker_image_to_ecr.sh"
90
90
  - "./lib/http_stub_docker.rb"
91
+ - "./lib/http_stub_docker/rake/arguments.rb"
91
92
  - "./lib/http_stub_docker/rake/container_tasks.rb"
92
93
  - "./lib/http_stub_docker/rake/pipeline_tasks.rb"
93
94
  - "./lib/http_stub_docker/rake/resource_tasks.rb"
94
95
  - "./lib/http_stub_docker/rake/server_daemon_tasks.rb"
95
96
  - "./lib/http_stub_docker/rake/task_generator.rb"
96
97
  - "./resource/.dockerignore"
97
- - "./resource/Dockerfile"
98
+ - "./resource/Dockerfile.erb"
98
99
  homepage: http://github.com/MYOB-Technology/http_stub_docker
99
100
  licenses:
100
101
  - MIT