docker-gem-store 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +8 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +40 -0
- data/Rakefile +2 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/docker-gem-store-0.1.0.gem +0 -0
- data/docker-gem-store.gemspec +26 -0
- data/exe/gem-store +6 -0
- data/lib/docker/gem/store/version.rb +7 -0
- data/lib/docker/gem/store.rb +192 -0
- metadata +85 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: b0db2bf52e4aa7d437d95829410c10e669a2b5df4cd175c28b0125128df45c33
|
|
4
|
+
data.tar.gz: fbf267d1041e0ae739b28ff983887795c8713282cfab5fb39eec8bed040d5cf9
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: e8e3f5fc1db88748d7aa5be2724fea5f4946bf987c1cd0c9aae4c076a76f145996cc98e44b01dea2d474dc4a2c802f8561bbe8aa3d130f7881c5b798c61fbf41
|
|
7
|
+
data.tar.gz: af4c539f7b0ce95cba36982e9b3708f68c7035b53794a6ddf549a3587681f77b2ac144fc4bba46f48c33c6ad4b0b761523139a53200c633e277ddb35173d8111
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2018 sawasaki narumi
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
## Installation
|
|
2
|
+
|
|
3
|
+
If you haven't installed a gem below, you should install it before installing docker-gem-store:
|
|
4
|
+
```ruby
|
|
5
|
+
gem 'specific_install'
|
|
6
|
+
```
|
|
7
|
+
|
|
8
|
+
Run following lien:
|
|
9
|
+
```ruby
|
|
10
|
+
gem specific_install -l 'https://github.com/linkqotto/docker-gem-store'
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
And then execute:
|
|
14
|
+
|
|
15
|
+
$ gem-stoer
|
|
16
|
+
|
|
17
|
+
## Usage
|
|
18
|
+
まず初めにconfigファイルを生成します。
|
|
19
|
+
```
|
|
20
|
+
gem-store --init
|
|
21
|
+
```
|
|
22
|
+
Dockerイメージの作成・更新を行う為のDockerfileの雛形を作成します。
|
|
23
|
+
```
|
|
24
|
+
gem-store --update
|
|
25
|
+
```
|
|
26
|
+
DockerfileやGemfileに更新内容を記述した後、下記コマンドでDockerイメージをビルドします。
|
|
27
|
+
```
|
|
28
|
+
gem-store --build
|
|
29
|
+
```
|
|
30
|
+
ビルドしたイメージにタグを付けます
|
|
31
|
+
```
|
|
32
|
+
gem-store --tagging
|
|
33
|
+
```
|
|
34
|
+
タグを付けた後、お好みでdockerhubにpushします。
|
|
35
|
+
```
|
|
36
|
+
docker push hogehoge/hugahuga:v1
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
## License
|
|
40
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
|
|
3
|
+
require "bundler/setup"
|
|
4
|
+
require "docker/gem/store"
|
|
5
|
+
|
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
|
8
|
+
|
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
|
10
|
+
# require "pry"
|
|
11
|
+
# Pry.start
|
|
12
|
+
|
|
13
|
+
require "irb"
|
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
|
Binary file
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
|
|
2
|
+
lib = File.expand_path("../lib", __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require "docker/gem/store/version"
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "docker-gem-store"
|
|
8
|
+
spec.version = Docker::Gem::Store::VERSION
|
|
9
|
+
spec.authors = ["sawasaki narumi"]
|
|
10
|
+
spec.email = ["selty524@gmail.com"]
|
|
11
|
+
|
|
12
|
+
spec.summary = %q{ Write a short summary, because RubyGems requires one.}
|
|
13
|
+
spec.description = %q{ Write a longer description or delete this line.}
|
|
14
|
+
spec.homepage = "https://google.com"
|
|
15
|
+
spec.license = "MIT"
|
|
16
|
+
|
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
|
18
|
+
f.match(%r{^(test|spec|features)/})
|
|
19
|
+
end
|
|
20
|
+
spec.bindir = "exe"
|
|
21
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
|
22
|
+
spec.require_paths = ["lib"]
|
|
23
|
+
|
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.16"
|
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
26
|
+
end
|
data/exe/gem-store
ADDED
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
require 'optparse'
|
|
2
|
+
require 'open3'
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module Docker
|
|
6
|
+
module Gem
|
|
7
|
+
module Store
|
|
8
|
+
current_dir = Dir.pwd
|
|
9
|
+
CONFIG_FILE_PATH = "#{current_dir}/.config-gem-store.yml"
|
|
10
|
+
DOCKERTAG_PATH = "#{current_dir}/.dockertag"
|
|
11
|
+
DOCKERFILE_PATH = "#{current_dir}/Dockerfile.bundle"
|
|
12
|
+
DEVELOPMENT_DOCKER_COMPOSE_FILE_PATH = "#{current_dir}/docker-compose.development.yml"
|
|
13
|
+
PRODUCTION_DOCKER_COMPOSE_FILE_PATH = "#{current_dir}/docker-compose.production.yml"
|
|
14
|
+
# ソースを含んだイメージをビルドする時用のDockerfile
|
|
15
|
+
TMP_DOCKERFILE_PATH = "#{current_dir}/Dockerfile.tmp"
|
|
16
|
+
|
|
17
|
+
def self.init
|
|
18
|
+
private_class_method :init
|
|
19
|
+
if File.exists?(CONFIG_FILE_PATH)
|
|
20
|
+
exit unless receive_confirmation(".config-gem-storeを上書きしますか?")
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
print 'イメージ名: '
|
|
24
|
+
image = STDIN.gets.chomp
|
|
25
|
+
print 'ユーザー名: '
|
|
26
|
+
user = STDIN.gets.chomp
|
|
27
|
+
print 'リポジトリ名: '
|
|
28
|
+
repository = STDIN.gets.chomp
|
|
29
|
+
File.open(CONFIG_FILE_PATH, 'w') do |f|
|
|
30
|
+
f.puts "image: #{image}"
|
|
31
|
+
f.puts "user: #{user}"
|
|
32
|
+
f.puts "repository: #{repository}"
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
def self.generate_dockerfile
|
|
37
|
+
private_class_method :generate_dockerfile
|
|
38
|
+
if File.exists?(DOCKERFILE_PATH)
|
|
39
|
+
confirmed = receive_confirmation("Dockerfile.bunleを上書きしますか?")
|
|
40
|
+
exit unless confirmed
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
tag = get_dependent_image_name('development')
|
|
44
|
+
|
|
45
|
+
begin
|
|
46
|
+
File.open(DOCKERFILE_PATH, "w") do |file|
|
|
47
|
+
content = <<-EOS
|
|
48
|
+
FROM #{tag}
|
|
49
|
+
#DO NOT MODIFY WORKDIR PATH
|
|
50
|
+
WORKDIR /gems
|
|
51
|
+
COPY Gemfile /gems
|
|
52
|
+
COPY Gemfile.lock /gems
|
|
53
|
+
RUN bundle install
|
|
54
|
+
EOS
|
|
55
|
+
file.puts content
|
|
56
|
+
end
|
|
57
|
+
rescue => e
|
|
58
|
+
raise e
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.build
|
|
63
|
+
private_class_method :build
|
|
64
|
+
dockerfile_path = Dir.glob("#{Dir.pwd}/dockerfiles/Dockerfile.bundle.*")
|
|
65
|
+
raise "No Dockerfile found" unless File.exists?(DOCKERFILE_PATH)
|
|
66
|
+
|
|
67
|
+
config = read_config
|
|
68
|
+
stdout, stderr, _ = Open3.capture3("docker build -t #{config['image']} -f #{DOCKERFILE_PATH} #{Dir.pwd}")
|
|
69
|
+
puts stdout
|
|
70
|
+
puts stderr if stderr
|
|
71
|
+
|
|
72
|
+
# Gemfile.lockのコピー
|
|
73
|
+
stdout, stderr, _ = Open3.capture3("docker run --rm #{config['image']} cat /gems/Gemfile.lock > #{Dir.pwd}/Gemfile.lock")
|
|
74
|
+
puts stderr if stderr
|
|
75
|
+
tagging('development')
|
|
76
|
+
end
|
|
77
|
+
|
|
78
|
+
def self.release
|
|
79
|
+
private_class_method :release
|
|
80
|
+
if File.exists?(PRODUCTION_DOCKER_COMPOSE_FILE_PATH)
|
|
81
|
+
confirmed = receive_confirmation("#{PRODUCTION_DOCKER_COMPOSE_FILE_PATH}を書き換えますか?")
|
|
82
|
+
exit unless confirmed
|
|
83
|
+
end
|
|
84
|
+
from_image = get_dependent_image_name('development')
|
|
85
|
+
create_tmp_dockerfile(Dir.pwd,from_image)
|
|
86
|
+
|
|
87
|
+
puts 'イメージのビルド中'
|
|
88
|
+
config = read_config
|
|
89
|
+
stdout,stderr,_ = Open3.capture3("docker build -t #{config['image']} -f #{TMP_DOCKERFILE_PATH}/ .")
|
|
90
|
+
puts stdout
|
|
91
|
+
puts stderr if stderr
|
|
92
|
+
|
|
93
|
+
tagging('production')
|
|
94
|
+
|
|
95
|
+
create_or_update_production_docker_compose_file
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def self.create_or_update_production_docker_compose_file
|
|
99
|
+
image_name = get_dependent_image_name('production')
|
|
100
|
+
if File.exists?(PRODUCTION_DOCKER_COMPOSE_FILE_PATH)
|
|
101
|
+
content = YAML.load_file(PRODUCTION_DOCKER_COMPOSE_FILE_PATH)
|
|
102
|
+
content['services']['web']['image'] = image_name
|
|
103
|
+
File.open(PRODUCTION_DOCKER_COMPOSE_FILE_PATH,'w') do |file|
|
|
104
|
+
YAML.dump(content,file)
|
|
105
|
+
end
|
|
106
|
+
else
|
|
107
|
+
content = {'version' => '3','services' => {'web' => {'image' =>image_name,'tty' => true}}}
|
|
108
|
+
File.open(PRODUCTION_DOCKER_COMPOSE_FILE_PATH,'w') do |file|
|
|
109
|
+
YAML.dump(content,file)
|
|
110
|
+
end
|
|
111
|
+
end
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def self.create_tmp_dockerfile(src_path,from_image)
|
|
115
|
+
File.open("#{TMP_DOCKERFILE_PATH}",'w') do |file|
|
|
116
|
+
content = <<-EOS
|
|
117
|
+
FROM #{from_image}
|
|
118
|
+
COPY . /app
|
|
119
|
+
EOS
|
|
120
|
+
file.puts content
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
|
|
124
|
+
def self.get_dependent_image_name(env)
|
|
125
|
+
yaml = YAML.load_file(DOCKERTAG_PATH) rescue ''
|
|
126
|
+
yaml[env]
|
|
127
|
+
end
|
|
128
|
+
|
|
129
|
+
def self.tagging(env)
|
|
130
|
+
private_class_method :tagging
|
|
131
|
+
now = Time.now.strftime("%Y%m%d%H%M%S")
|
|
132
|
+
config = read_config
|
|
133
|
+
tag = "#{config['user']}/#{config['repository']}:#{now}"
|
|
134
|
+
save_dockertag("#{env}",tag)
|
|
135
|
+
`docker tag #{config['image']} #{tag}`
|
|
136
|
+
puts tag
|
|
137
|
+
end
|
|
138
|
+
|
|
139
|
+
def self.save_dockertag(env,tag)
|
|
140
|
+
if File.exists?(DOCKERTAG_PATH)
|
|
141
|
+
tags = YAML.load_file(DOCKERTAG_PATH)
|
|
142
|
+
tags[env] = tag
|
|
143
|
+
else
|
|
144
|
+
tags = {}
|
|
145
|
+
tags[env] = tag
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
begin
|
|
149
|
+
File.open(DOCKERTAG_PATH,'w') do |file|
|
|
150
|
+
YAML.dump(tags,file)
|
|
151
|
+
end
|
|
152
|
+
rescue Exception
|
|
153
|
+
puts '.dockertagへの書き込みに失敗しました'
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
|
|
157
|
+
def self.read_config
|
|
158
|
+
private_class_method :read_config
|
|
159
|
+
YAML.load_file(CONFIG_FILE_PATH)
|
|
160
|
+
end
|
|
161
|
+
|
|
162
|
+
def self.receive_confirmation(message)
|
|
163
|
+
private_class_method :receive_confirmation
|
|
164
|
+
begin
|
|
165
|
+
print "#{message}(y/n): "
|
|
166
|
+
input = STDIN.gets.chomp
|
|
167
|
+
end while (!%w(y n Y N yes no Yes No).include? input)
|
|
168
|
+
%w(y yes Yes).include? input
|
|
169
|
+
end
|
|
170
|
+
|
|
171
|
+
def self.run(argv)
|
|
172
|
+
params = argv.getopts("","init","update","build","tagging", "release")
|
|
173
|
+
puts params
|
|
174
|
+
if params["init"]
|
|
175
|
+
self.init
|
|
176
|
+
elsif params["update"]
|
|
177
|
+
self.generate_dockerfile
|
|
178
|
+
elsif params["build"]
|
|
179
|
+
self.build
|
|
180
|
+
elsif params["tagging"]
|
|
181
|
+
self.tagging
|
|
182
|
+
elsif params["release"]
|
|
183
|
+
self.release
|
|
184
|
+
else
|
|
185
|
+
yaml = YAML.load_file(DOCKERTAG_PATH)
|
|
186
|
+
puts yaml
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
end
|
|
190
|
+
end
|
|
191
|
+
end
|
|
192
|
+
|
metadata
ADDED
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: docker-gem-store
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- sawasaki narumi
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: exe
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2018-04-13 00:00:00.000000000 Z
|
|
12
|
+
dependencies:
|
|
13
|
+
- !ruby/object:Gem::Dependency
|
|
14
|
+
name: bundler
|
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
|
16
|
+
requirements:
|
|
17
|
+
- - "~>"
|
|
18
|
+
- !ruby/object:Gem::Version
|
|
19
|
+
version: '1.16'
|
|
20
|
+
type: :development
|
|
21
|
+
prerelease: false
|
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - "~>"
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '1.16'
|
|
27
|
+
- !ruby/object:Gem::Dependency
|
|
28
|
+
name: rake
|
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
|
30
|
+
requirements:
|
|
31
|
+
- - "~>"
|
|
32
|
+
- !ruby/object:Gem::Version
|
|
33
|
+
version: '10.0'
|
|
34
|
+
type: :development
|
|
35
|
+
prerelease: false
|
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
37
|
+
requirements:
|
|
38
|
+
- - "~>"
|
|
39
|
+
- !ruby/object:Gem::Version
|
|
40
|
+
version: '10.0'
|
|
41
|
+
description: " Write a longer description or delete this line."
|
|
42
|
+
email:
|
|
43
|
+
- selty524@gmail.com
|
|
44
|
+
executables:
|
|
45
|
+
- gem-store
|
|
46
|
+
extensions: []
|
|
47
|
+
extra_rdoc_files: []
|
|
48
|
+
files:
|
|
49
|
+
- ".gitignore"
|
|
50
|
+
- Gemfile
|
|
51
|
+
- LICENSE.txt
|
|
52
|
+
- README.md
|
|
53
|
+
- Rakefile
|
|
54
|
+
- bin/console
|
|
55
|
+
- bin/setup
|
|
56
|
+
- docker-gem-store-0.1.0.gem
|
|
57
|
+
- docker-gem-store.gemspec
|
|
58
|
+
- exe/gem-store
|
|
59
|
+
- lib/docker/gem/store.rb
|
|
60
|
+
- lib/docker/gem/store/version.rb
|
|
61
|
+
homepage: https://google.com
|
|
62
|
+
licenses:
|
|
63
|
+
- MIT
|
|
64
|
+
metadata: {}
|
|
65
|
+
post_install_message:
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: '0'
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubyforge_project:
|
|
81
|
+
rubygems_version: 2.7.3
|
|
82
|
+
signing_key:
|
|
83
|
+
specification_version: 4
|
|
84
|
+
summary: Write a short summary, because RubyGems requires one.
|
|
85
|
+
test_files: []
|