docker-builder 0.1.5 → 0.1.6

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: 3c7402bf36321129a23e0de870efa54e445c3876
4
- data.tar.gz: cfeaa7e2a406d013dc88513079ab5d39775b29ba
3
+ metadata.gz: e832d508142c8ff9a62334fd697d243ab26b6cd7
4
+ data.tar.gz: 8fd2471f7fcde3212c2fb9eddb9ae4fcc4b8dacf
5
5
  SHA512:
6
- metadata.gz: dd608f385811340691f81e0366751bcf9a832507caa68a9549d94eb12366c6d5321d6204b65146b22c959565d8c1a81ca957b423c79d4e0caf24d6bea91e72d1
7
- data.tar.gz: f17bb38bed31308d94a9536063260a7a6b370a327f8c8d100ebb63c01ebfb5794687b49b548e4c0349e5a60b6b1b4a17571845b758580f1d981554749484d835
6
+ metadata.gz: 4a39d9ad9ace6555b515290836f47358abbe85c1e4f6713ad4508e022d5994bf9ef3b6b4fd508ba06c1028e87fce6fd05ebc2b58ce75701e2e6e4949522e7c98
7
+ data.tar.gz: 2673f18151df9441e6fbca6d3a8a68fe363916fc60bae5d21c06ba389614722edb315304af96741166de4b19d39b2e91becf6c73eb4a6e39a2762fd4f0acb4af
@@ -0,0 +1,84 @@
1
+ # my vars
2
+ KAFKA_HOSTNAME = '10.1.0.12'
3
+
4
+ #
5
+ common({
6
+ 'prefix' => "ex-",
7
+ 'image_prefix' => 'ex-',
8
+ 'dir_data' => '/disk3/data/ex-kafka-zookeeper/',
9
+
10
+ })
11
+
12
+ servers({
13
+ 'zookeeper'=>{
14
+ 'build' => {
15
+ 'build_type' => 'none',
16
+ "image_name" => "", # not used
17
+
18
+
19
+ "base_image" => {
20
+ #"name" => "wurstmeister/zookeeper",
21
+ #"repository" => "wurstmeister/zookeeper",
22
+
23
+ #"name" => "jplock/zookeeper",
24
+ #"repository" => "jplock/zookeeper",
25
+
26
+ "name" => "zookeeper",
27
+ "repository" => "zookeeper",
28
+ "tag" => "3.4.9"
29
+
30
+ },
31
+ },
32
+ 'docker'=> {
33
+ #"command"=> "",
34
+ 'ports' => [
35
+ [2181,2181],
36
+ ],
37
+ 'volumes' => [
38
+ ],
39
+ 'links' => [
40
+
41
+ ]
42
+ },
43
+ 'attributes' => {
44
+ }
45
+
46
+ },
47
+ 'kafka'=>{
48
+ 'build' => {
49
+ 'build_type' => 'Dockerfile',
50
+ "image_name" => "kafka",
51
+
52
+ "base_image" => {} # not used
53
+ },
54
+ 'docker'=> {
55
+ #"command"=> "",
56
+ 'ports' => [
57
+ [9092,9092],
58
+ ],
59
+ 'volumes' => [
60
+ ["docker.sock", '/var/run/docker.sock']
61
+ ],
62
+ 'links' => [
63
+ ['zookeeper', 'zookeeper']
64
+ ],
65
+ 'run_env' =>[
66
+ ['KAFKA_ADVERTISED_HOST_NAME', KAFKA_HOSTNAME],
67
+ ['KAFKA_ADVERTISED_PORT', 9092],
68
+ ['KAFKA_CREATE_TOPICS', "test:1:1"],
69
+ ['KAFKA_ZOOKEEPER_CONNECT', 'zookeeper:2181']
70
+ ]
71
+ },
72
+ 'attributes' => {
73
+ }
74
+ },
75
+
76
+
77
+ })
78
+
79
+
80
+
81
+
82
+ base({
83
+
84
+ })
@@ -0,0 +1,21 @@
1
+ FROM anapsix/alpine-java
2
+
3
+ MAINTAINER MaxIvak
4
+
5
+ RUN apk add --update unzip wget curl docker jq coreutils
6
+
7
+ ENV KAFKA_VERSION="0.10.0.1" SCALA_VERSION="2.11"
8
+
9
+ ADD files/download-kafka.sh /tmp/download-kafka.sh
10
+ RUN /tmp/download-kafka.sh && tar xfz /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt && rm /tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz
11
+
12
+ VOLUME ["/kafka"]
13
+
14
+ ENV KAFKA_HOME /opt/kafka_${SCALA_VERSION}-${KAFKA_VERSION}
15
+
16
+ ADD files/start-kafka.sh /usr/bin/start-kafka.sh
17
+ ADD files/broker-list.sh /usr/bin/broker-list.sh
18
+ ADD files/create-topics.sh /usr/bin/create-topics.sh
19
+
20
+ # Use "exec" form so that it runs as PID 1 (useful for graceful shutdown)
21
+ CMD ["start-kafka.sh"]
@@ -0,0 +1,78 @@
1
+ [![Docker Pulls](https://img.shields.io/docker/pulls/wurstmeister/kafka.svg)](https://hub.docker.com/r/wurstmeister/kafka/)
2
+ [![Docker Stars](https://img.shields.io/docker/stars/wurstmeister/kafka.svg)](https://hub.docker.com/r/wurstmeister/kafka/)
3
+ [![](https://badge.imagelayers.io/wurstmeister/kafka:latest.svg)](https://imagelayers.io/?images=wurstmeister/kafka:latest)
4
+
5
+ kafka-docker
6
+ ============
7
+
8
+ Dockerfile for [Apache Kafka](http://kafka.apache.org/)
9
+
10
+ The image is available directly from https://registry.hub.docker.com/
11
+
12
+ ##Pre-Requisites
13
+
14
+ - install docker-compose [https://docs.docker.com/compose/install/](https://docs.docker.com/compose/install/)
15
+ - modify the ```KAFKA_ADVERTISED_HOST_NAME``` in ```docker-compose.yml``` to match your docker host IP (Note: Do not use localhost or 127.0.0.1 as the host ip if you want to run multiple brokers.)
16
+ - if you want to customise any Kafka parameters, simply add them as environment variables in ```docker-compose.yml```, e.g. in order to increase the ```message.max.bytes``` parameter set the environment to ```KAFKA_MESSAGE_MAX_BYTES: 2000000```. To turn off automatic topic creation set ```KAFKA_AUTO_CREATE_TOPICS_ENABLE: 'false'```
17
+
18
+ ##Usage
19
+
20
+ Start a cluster:
21
+
22
+ - ```docker-compose up -d ```
23
+
24
+ Add more brokers:
25
+
26
+ - ```docker-compose scale kafka=3```
27
+
28
+ Destroy a cluster:
29
+
30
+ - ```docker-compose stop```
31
+
32
+ ##Note
33
+
34
+ The default ```docker-compose.yml``` should be seen as a starting point. By default each broker will get a new port number and broker id on restart. Depending on your use case this might not be desirable. If you need to use specific ports and broker ids, modify the docker-compose configuration accordingly, e.g. [docker-compose-single-broker.yml](https://github.com/wurstmeister/kafka-docker/blob/master/docker-compose-single-broker.yml):
35
+
36
+ - ```docker-compose -f docker-compose-single-broker.yml up```
37
+
38
+ ##Broker IDs
39
+
40
+ If you don't specify a broker id in your docker-compose file, it will automatically be generated (see [https://issues.apache.org/jira/browse/KAFKA-1070](https://issues.apache.org/jira/browse/KAFKA-1070). This allows scaling up and down. In this case it is recommended to use the ```--no-recreate``` option of docker-compose to ensure that containers are not re-created and thus keep their names and ids.
41
+
42
+
43
+ ##Automatically create topics
44
+
45
+ If you want to have kafka-docker automatically create topics in Kafka during
46
+ creation, a ```KAFKA_CREATE_TOPICS``` environment variable can be
47
+ added in ```docker-compose.yml```.
48
+
49
+ Here is an example snippet from ```docker-compose.yml```:
50
+
51
+ environment:
52
+ KAFKA_CREATE_TOPICS: "Topic1:1:3,Topic2:1:1"
53
+
54
+ ```Topic 1``` will have 1 partition and 3 replicas, ```Topic 2``` will have 1 partition and 1 replica.
55
+
56
+ ##Advertised hostname
57
+
58
+ You can configure the advertised hostname in different ways
59
+
60
+ 1. explicitly, using ```KAFKA_ADVERTISED_HOST_NAME```
61
+ 2. via a command, using ```HOSTNAME_COMMAND```, e.g. ```HOSTNAME_COMMAND: "route -n | awk '/UG[ \t]/{print $$2}'"```
62
+
63
+ When using commands, make sure you review the "Variable Substitution" section in [https://docs.docker.com/compose/compose-file/](https://docs.docker.com/compose/compose-file/)
64
+
65
+ If ```KAFKA_ADVERTISED_HOST_NAME``` is specified, it takes presendence over ```HOSTNAME_COMMAND```
66
+
67
+ For AWS deployment, you can use the Metadata service to get the container host's IP:
68
+ ```
69
+ HOSTNAME_COMMAND=wget -t3 -T2 -qO- http://169.254.169.254/latest/meta-data/local-ipv4
70
+ ```
71
+ Reference: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html
72
+
73
+ ##Tutorial
74
+
75
+ [http://wurstmeister.github.io/kafka-docker/](http://wurstmeister.github.io/kafka-docker/)
76
+
77
+
78
+
@@ -0,0 +1,202 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "{}"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright {yyyy} {name of copyright owner}
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
202
+
@@ -0,0 +1,5 @@
1
+ #!/bin/bash
2
+
3
+ CONTAINERS=$(docker ps | grep 9092 | awk '{print $1}')
4
+ BROKERS=$(for CONTAINER in $CONTAINERS; do docker port $CONTAINER 9092 | sed -e "s/0.0.0.0:/$HOST_IP:/g"; done)
5
+ echo $BROKERS | sed -e 's/ /,/g'
@@ -0,0 +1,32 @@
1
+ #!/bin/bash
2
+
3
+
4
+ if [[ -z "$START_TIMEOUT" ]]; then
5
+ START_TIMEOUT=600
6
+ fi
7
+
8
+ start_timeout_exceeded=false
9
+ count=0
10
+ step=10
11
+ while netstat -lnt | awk '$4 ~ /:'$KAFKA_PORT'$/ {exit 1}'; do
12
+ echo "waiting for kafka to be ready"
13
+ sleep $step;
14
+ count=$(expr $count + $step)
15
+ if [ $count -gt $START_TIMEOUT ]; then
16
+ start_timeout_exceeded=true
17
+ break
18
+ fi
19
+ done
20
+
21
+ if $start_timeout_exceeded; then
22
+ echo "Not able to auto-create topic (waited for $START_TIMEOUT sec)"
23
+ exit 1
24
+ fi
25
+
26
+ if [[ -n $KAFKA_CREATE_TOPICS ]]; then
27
+ IFS=','; for topicToCreate in $KAFKA_CREATE_TOPICS; do
28
+ echo "creating topics: $topicToCreate"
29
+ IFS=':' read -a topicConfig <<< "$topicToCreate"
30
+ JMX_PORT='' $KAFKA_HOME/bin/kafka-topics.sh --create --zookeeper $KAFKA_ZOOKEEPER_CONNECT --replication-factor ${topicConfig[2]} --partition ${topicConfig[1]} --topic "${topicConfig[0]}"
31
+ done
32
+ fi
@@ -0,0 +1,5 @@
1
+ #!/bin/sh
2
+
3
+ mirror=$(curl --stderr /dev/null https://www.apache.org/dyn/closer.cgi\?as_json\=1 | jq -r '.preferred')
4
+ url="${mirror}kafka/${KAFKA_VERSION}/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz"
5
+ wget -q "${url}" -O "/tmp/kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz"
@@ -0,0 +1,2 @@
1
+ #!/bin/bash
2
+ docker run --rm -v /var/run/docker.sock:/var/run/docker.sock -e HOST_IP=$1 -e ZK=$2 -i -t wurstmeister/kafka /bin/bash
@@ -0,0 +1,67 @@
1
+ #!/bin/bash
2
+
3
+ if [[ -z "$KAFKA_PORT" ]]; then
4
+ export KAFKA_PORT=9092
5
+ fi
6
+ if [[ -z "$KAFKA_ADVERTISED_PORT" ]]; then
7
+ export KAFKA_ADVERTISED_PORT=$(docker port `hostname` $KAFKA_PORT | sed -r "s/.*:(.*)/\1/g")
8
+ fi
9
+ if [[ -z "$KAFKA_BROKER_ID" ]]; then
10
+ # By default auto allocate broker ID
11
+ export KAFKA_BROKER_ID=-1
12
+ fi
13
+ if [[ -z "$KAFKA_LOG_DIRS" ]]; then
14
+ export KAFKA_LOG_DIRS="/kafka/kafka-logs-$HOSTNAME"
15
+ fi
16
+ if [[ -z "$KAFKA_ZOOKEEPER_CONNECT" ]]; then
17
+ export KAFKA_ZOOKEEPER_CONNECT=$(env | grep ZK.*PORT_2181_TCP= | sed -e 's|.*tcp://||' | paste -sd ,)
18
+ fi
19
+
20
+ if [[ -n "$KAFKA_HEAP_OPTS" ]]; then
21
+ sed -r -i "s/(export KAFKA_HEAP_OPTS)=\"(.*)\"/\1=\"$KAFKA_HEAP_OPTS\"/g" $KAFKA_HOME/bin/kafka-server-start.sh
22
+ unset KAFKA_HEAP_OPTS
23
+ fi
24
+
25
+ if [[ -z "$KAFKA_ADVERTISED_HOST_NAME" && -n "$HOSTNAME_COMMAND" ]]; then
26
+ export KAFKA_ADVERTISED_HOST_NAME=$(eval $HOSTNAME_COMMAND)
27
+ fi
28
+
29
+ for VAR in `env`
30
+ do
31
+ if [[ $VAR =~ ^KAFKA_ && ! $VAR =~ ^KAFKA_HOME ]]; then
32
+ kafka_name=`echo "$VAR" | sed -r "s/KAFKA_(.*)=.*/\1/g" | tr '[:upper:]' '[:lower:]' | tr _ .`
33
+ env_var=`echo "$VAR" | sed -r "s/(.*)=.*/\1/g"`
34
+ if egrep -q "(^|^#)$kafka_name=" $KAFKA_HOME/config/server.properties; then
35
+ sed -r -i "s@(^|^#)($kafka_name)=(.*)@\2=${!env_var}@g" $KAFKA_HOME/config/server.properties #note that no config values may contain an '@' char
36
+ else
37
+ echo "$kafka_name=${!env_var}" >> $KAFKA_HOME/config/server.properties
38
+ fi
39
+ fi
40
+ done
41
+
42
+ if [[ -n "$CUSTOM_INIT_SCRIPT" ]] ; then
43
+ eval $CUSTOM_INIT_SCRIPT
44
+ fi
45
+
46
+
47
+ KAFKA_PID=0
48
+
49
+ # see https://medium.com/@gchudnov/trapping-signals-in-docker-containers-7a57fdda7d86#.bh35ir4u5
50
+ term_handler() {
51
+ echo 'Stopping Kafka....'
52
+ if [ $KAFKA_PID -ne 0 ]; then
53
+ kill -s TERM "$KAFKA_PID"
54
+ wait "$KAFKA_PID"
55
+ fi
56
+ echo 'Kafka stopped.'
57
+ exit
58
+ }
59
+
60
+
61
+ # Capture kill requests to stop properly
62
+ trap "term_handler" SIGHUP SIGINT SIGTERM
63
+ create-topics.sh &
64
+ $KAFKA_HOME/bin/kafka-server-start.sh $KAFKA_HOME/config/server.properties &
65
+ KAFKA_PID=$!
66
+
67
+ wait
@@ -51,8 +51,15 @@ class CLI < Thor
51
51
  begin
52
52
  Config.load(options)
53
53
 
54
+ #puts "config servers: #{Config.inspect}"
55
+ #puts "config: #{Config.options.inspect}"
56
+ #exit
57
+
54
58
  Config.servers.each do |name, opts|
55
- server_settings = Manager.load_settings(name, opts)
59
+ server_settings = Settings.load_settings_for_server(name, opts)
60
+
61
+ #puts "s: #{server_settings.inspect}"
62
+ #exit
56
63
 
57
64
  Manager.destroy_image(name, server_settings)
58
65
  Manager.build_image(name, server_settings)
@@ -125,13 +132,13 @@ class CLI < Thor
125
132
 
126
133
  begin
127
134
  Config.load(options)
128
-
129
- puts "root: #{Config.root_path}"
130
-
131
- #puts "servers: #{Config.servers.inspect}"
135
+ puts "config: #{Config.inspect}"
132
136
 
133
137
  Config.servers.each do |name, opts|
134
- server_settings = Manager.load_settings(name, opts)
138
+ server_settings = Settings.load_settings_for_server(name, opts)
139
+
140
+ puts "s: #{server_settings.inspect}"
141
+ exit
135
142
 
136
143
  Manager.destroy_image(name, server_settings)
137
144
  end
@@ -191,7 +198,7 @@ class CLI < Thor
191
198
  Config.load(options)
192
199
 
193
200
  Config.servers.each do |name, opts|
194
- server_settings = Manager.load_settings(name, opts)
201
+ server_settings = Settings.load_settings_for_server(name, opts)
195
202
 
196
203
  Manager.destroy_container(name, server_settings)
197
204
  Manager.run_container(name, server_settings)
@@ -251,7 +258,7 @@ class CLI < Thor
251
258
  Config.load(options)
252
259
 
253
260
  Config.servers.each do |name, opts|
254
- server_settings = Manager.load_settings(name, opts)
261
+ server_settings = Settings.load_settings_for_server(name, opts)
255
262
 
256
263
  Manager.destroy_container(name, server_settings)
257
264
  end
@@ -16,7 +16,7 @@ module DockerBuilder
16
16
  class << self
17
17
  #include Utilities::Helpers
18
18
 
19
- attr_reader :server, :root_path, :config_file, :tmp_path, :options
19
+ attr_reader :servers, :root_path, :config_file, :tmp_path, :options
20
20
 
21
21
 
22
22
  # Define on self, since it's a class method
@@ -92,7 +92,8 @@ module DockerBuilder
92
92
  def load_servers(opts)
93
93
  # Identify all servers
94
94
  if opts[:server]
95
- options[:servers] = {opts[:server]=>{}}
95
+ server_name = opts[:server]
96
+ options[:servers] = {server_name=>options[:servers][server_name] }
96
97
  else
97
98
  # get from config
98
99
  #options[:servers] = options[:servers]
@@ -1,15 +1,6 @@
1
1
  module DockerBuilder
2
2
  class Manager
3
3
 
4
-
5
- def self.load_settings(server_name, opts={})
6
- settings = Settings.load_settings_for_server(server_name, opts)
7
-
8
- settings.set 'name', server_name
9
-
10
- settings
11
- end
12
-
13
4
  def self.save_chef_config(settings)
14
5
  require 'json'
15
6
  filename = settings.filename_chef_config
@@ -30,19 +21,23 @@ class Manager
30
21
 
31
22
  #settings = load_settings(server_name)
32
23
 
33
- if settings['build']['build_type']=='dockerfile'
24
+ t = settings['build']['build_type']
25
+ if t=='' || t=='none'
26
+ #
27
+ puts "no build needed..."
28
+
29
+ elsif t.downcase=='dockerfile'
34
30
  return build_image_with_dockerfile(settings)
35
- elsif settings['build']['build_type']=='chef'
31
+ elsif t=='chef'
36
32
  return build_image_with_chef(settings)
37
33
  end
38
34
  end
39
35
 
40
36
  def self.build_image_with_dockerfile(settings)
41
- puts "build image with Dockerfile. Image: #{settings.image_name}"
42
-
43
- name = settings['name']
37
+ puts "build image with Dockerfile"
44
38
 
45
- cmd %Q(cd #{name} && docker build -t #{settings.image_name} . )
39
+ #cmd %Q(cd #{name} && docker build -t #{settings.image_name} . )
40
+ cmd %Q(docker build -t #{settings.image_name} #{settings.dir_server_root} )
46
41
 
47
42
  end
48
43
 
@@ -128,6 +123,9 @@ class Manager
128
123
 
129
124
  script_type = (settings['install']['node']['script_type'] rescue nil)
130
125
 
126
+ puts "script type: #{script_type}"
127
+
128
+
131
129
  if script_type && script_type=='chef_recipe'
132
130
  # run container and provision with chef
133
131
  _run_container_chef(settings)
@@ -69,9 +69,22 @@ class ServerSettings
69
69
  def image_name
70
70
  s = attributes['name']
71
71
 
72
+ if !need_build?
73
+ bi = attributes['build']['base_image']
74
+ return "#{bi['name']}:#{bi['tag']}"
75
+ end
76
+
72
77
  "#{attributes['common']['image_prefix']}#{s}"
73
78
  end
74
79
 
80
+ def need_build?
81
+ build_type = attributes['build']['build_type']
82
+ return false if build_type=='' || build_type=='none'
83
+
84
+
85
+ true
86
+ end
87
+
75
88
  def container_name(name=nil)
76
89
  name ||= attributes['name']
77
90
  s = name
@@ -239,6 +252,13 @@ class Settings
239
252
  def self.load_settings_for_server(name, opts={})
240
253
  settings = ServerSettings.new
241
254
 
255
+ settings.set 'name', name
256
+
257
+ # set from main Config
258
+ Config.servers[name].each do |k,v|
259
+ settings.attributes[k]=v
260
+ end
261
+
242
262
 
243
263
  #puts "current=#{File.dirname(__FILE__)}"
244
264
  #puts "ff=#{file_base_settings}"
@@ -1,3 +1,3 @@
1
1
  module DockerBuilder
2
- VERSION = "0.1.5"
2
+ VERSION = "0.1.6"
3
3
  end
@@ -0,0 +1,5 @@
1
+ ### add cookbooks
2
+ #cookbook_path cookbook_path+[
3
+ # '/work/chef-repo/cookbooks-common',
4
+ # '/work/chef-repo/cookbooks',
5
+ #]
data/readme.md CHANGED
@@ -141,6 +141,14 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
141
141
  * CHEF_COOKBOOKS - list of paths to chef cookbooks
142
142
 
143
143
 
144
+ # Build Docker image
145
+
146
+ Build types:
147
+ * 'none' - no build required
148
+ * 'Dockerfile' - using Dockerfile and docker build command
149
+ * 'chef' - using Chef provisioning
150
+
151
+
144
152
  # Chef provisioning
145
153
 
146
154
  * add additional paths for cookbooks
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-builder
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.5
4
+ version: 0.1.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Max Ivak
@@ -83,6 +83,15 @@ files:
83
83
  - examples/example-apps-php/servers/apps-php/cookbooks/apps-php/templates/nginx-sites/app.conf.erb.1
84
84
  - examples/example-apps-php/servers/apps-php/cookbooks/apps-php/templates/nginx-sites/default.conf.erb
85
85
  - examples/example-apps-php/servers/apps-php/readme.md
86
+ - examples/example-kafka-zookeeper/config.rb
87
+ - examples/example-kafka-zookeeper/servers/kafka/Dockerfile
88
+ - examples/example-kafka-zookeeper/servers/kafka/README.md
89
+ - examples/example-kafka-zookeeper/servers/kafka/files/LICENSE
90
+ - examples/example-kafka-zookeeper/servers/kafka/files/broker-list.sh
91
+ - examples/example-kafka-zookeeper/servers/kafka/files/create-topics.sh
92
+ - examples/example-kafka-zookeeper/servers/kafka/files/download-kafka.sh
93
+ - examples/example-kafka-zookeeper/servers/kafka/files/start-kafka-shell.sh
94
+ - examples/example-kafka-zookeeper/servers/kafka/files/start-kafka.sh
86
95
  - examples/example-nginx/config.rb
87
96
  - examples/example-nginx/servers/nginx/.chef/knife.rb
88
97
  - examples/example-nginx/servers/nginx/config.rb
@@ -109,6 +118,7 @@ files:
109
118
  - lib/docker_builder/manager.rb
110
119
  - lib/docker_builder/server_settings.rb
111
120
  - lib/docker_builder/version.rb
121
+ - lib/templates/example-chef/.chef/knife.rb
112
122
  - lib/templates/example-chef/config.rb.erb
113
123
  - lib/templates/example-chef/servers/server1/.chef/knife.rb
114
124
  - lib/templates/example-chef/servers/server1/config.rb.erb