docker-utils 0.1.34 → 0.1.35

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: ca2be09a117367fb3ed4b4d9b1d071f1eb44c186
4
- data.tar.gz: f6832ac00be7b852cdec01a2752a7e9d2b62b8b6
3
+ metadata.gz: 0883a41958efe271528f4332c796ff3730412183
4
+ data.tar.gz: d1606eecb3cfd88a9af89dea35f15fcc35e716a9
5
5
  SHA512:
6
- metadata.gz: 0ec8a28f5049794aebde5f254516749e848d8d431b5df28f61dc913d523fd4fd49f2aa8a9f55274749f732da9d47d6223ae0d8fa9210f964e5340cc9f50e1ffb
7
- data.tar.gz: e9747a85ebd68a2aa5733d4d54b4e3db8d19a4ffaff2e682180bdc6bf242693c5aade676a4b886800b6e2b5b86c8850b55087ac63751fcf3e5cfe5c76859e6e4
6
+ metadata.gz: 1baa416396040c0f4d7e43000d7c58b395ccaab821d8dd88fb6b80b81e8e76ca3eb18c431c8e33344b822f69afcfa724f7ace65e2e618462b34c3a265ff4e88b
7
+ data.tar.gz: 26a4b554aa0c473257bbf5a5e5419a498e6e1a5341e7b4fe6ecd14b9c1f4b710fbd59532a46467959d0503ae1fe603ebbcf2e681071be04ca157768202ada940
@@ -0,0 +1,17 @@
1
+ #!/bin/sh
2
+
3
+ container_name="$1"; shift
4
+
5
+ if [ -n "$1" ]; then
6
+ container_port="$1"; shift
7
+ fi
8
+
9
+ container_ip_addr="$(docker-utils ip -w "${container_name}")"
10
+
11
+ if [ -z "${container_port}" ]; then
12
+ container_port=$(docker-utils exposed -p "${container_name}" | head -n 1)
13
+ fi
14
+
15
+ until docker-utils "port-open?" "${container_name}" "${container_port}"; do
16
+ sleep 0.1
17
+ done
@@ -33,6 +33,8 @@ conns = ports_and_transports.split(' ').map do |port_and_transport|
33
33
  {port: port, transport: transport, ip: ip}
34
34
  end
35
35
 
36
+ conns = conns.sort_by{ |conn| [conn[:port], conn[:transport]] }
37
+
36
38
  conns.each do |conn|
37
39
  case print
38
40
  when :ports
data/share/scripts/ip CHANGED
@@ -1,3 +1,28 @@
1
- #!/bin/bash
1
+ #!/bin/sh
2
2
 
3
- command docker inspect --format '{{.NetworkSettings.IPAddress}}' "$1"
3
+ mode="once"
4
+ if [ "$1" = "-w" ]; then
5
+ mode="wait"; shift
6
+ fi
7
+
8
+ container_name="$1"; shift
9
+
10
+ container_ip_addr=""
11
+
12
+ if [ "${mode}" = "wait" ]; then
13
+ while :; do
14
+ container_ip_addr=$(command docker inspect --format '{{.NetworkSettings.IPAddress}}' "${container_name}" 2>/dev/null)
15
+ if [ -n "${container_ip_addr}" ]; then
16
+ break
17
+ fi
18
+ sleep 0.1
19
+ done
20
+ else
21
+ container_ip_addr=$(command docker inspect --format '{{.NetworkSettings.IPAddress}}' "${container_name}" 2>/dev/null)
22
+ fi
23
+
24
+ if [ -n "${container_ip_addr}" ]; then
25
+ echo "${container_ip_addr}"
26
+ else
27
+ exit 1
28
+ fi
@@ -0,0 +1,6 @@
1
+ #!/bin/sh
2
+
3
+ container_name="$1"; shift
4
+ container_port="$1"; shift
5
+
6
+ nc -w 1 "$(command docker inspect --format '{{.NetworkSettings.IPAddress}}' "${container_name}")" "${container_port}" </dev/null 2>/dev/null
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: docker-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.34
4
+ version: 0.1.35
5
5
  platform: ruby
6
6
  authors:
7
7
  - Levi Aul
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-24 00:00:00.000000000 Z
11
+ date: 2014-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby-uuid
@@ -35,16 +35,16 @@ files:
35
35
  - "./Rakefile"
36
36
  - "./bin/docker-utils"
37
37
  - "./docker-utils.gemspec"
38
+ - "./share/scripts/block-until-port-open"
38
39
  - "./share/scripts/container-links-for"
39
- - "./share/scripts/define-ambassador-service"
40
- - "./share/scripts/define-service"
41
- - "./share/scripts/exposed"
40
+ - "./share/scripts/exposed-ports"
42
41
  - "./share/scripts/gc"
43
42
  - "./share/scripts/get"
44
43
  - "./share/scripts/get-host-uuid"
45
44
  - "./share/scripts/instances"
46
45
  - "./share/scripts/ip"
47
46
  - "./share/scripts/make-ref"
47
+ - "./share/scripts/port-open?"
48
48
  - "./share/scripts/tags"
49
49
  - "./share/scripts/toolchain"
50
50
  - "./share/scripts/up?"
@@ -1,53 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo -n "defining ambassador service '$1'... "
4
-
5
- service_name=$1; shift
6
-
7
- remote_host=$1; shift
8
- remote_port=$1; shift
9
-
10
- cat >"/etc/init/${service_name}.conf" <<EOF
11
- stop on stopping docker
12
-
13
- env HOME=/root
14
-
15
- respawn
16
- respawn limit 5 20
17
-
18
- pre-start script
19
- . /etc/environment.local
20
-
21
- touch "/var/log/upstart/${service_name}.log"
22
- chown root:syslog "/var/log/upstart/${service_name}.log"
23
-
24
- mkdir -p /run/docker/upstart-service-containers
25
- run_id=\$(docker-utils make-ref 5)
26
- echo "${service_name}" > '/run/docker/upstart-service-containers/${service_name}'
27
- end script
28
-
29
- post-stop script
30
- container_name="\$(cat '/run/docker/upstart-service-containers/${service_name}')"
31
- docker stop "\${container_name}" || :
32
- docker rm "\${container_name}" || :
33
- rm '/run/docker/upstart-service-containers/${service_name}'
34
- end script
35
-
36
- script
37
- . /etc/environment.local
38
-
39
- container_name="\$(cat '/run/docker/upstart-service-containers/${service_name}')"
40
-
41
- echo "starting container: \${container_name} (from bexio/amb:latest)..."
42
-
43
- running_container_id=\$(docker run -d \
44
- --name="\${container_name}" \
45
- "bexio/amb:latest" \
46
- '${remote_host}' '${remote_port}'
47
- )
48
-
49
- exec docker attach --sig-proxy=true "\${running_container_id}"
50
- end script
51
- EOF
52
-
53
- echo "defined."
@@ -1,137 +0,0 @@
1
- #!/bin/bash
2
-
3
- echo -n "defining container service '$1'... "
4
-
5
- image_repo=$1
6
- shift
7
-
8
- image_tag=$(echo "${image_repo}" | tr ':' ' ' | awk '{print $2;}')
9
- image_repo=$(echo "${image_repo}" | tr ':' ' ' | awk '{print $1;}')
10
- image_tag=${image_tag:-latest}
11
-
12
- image_name=$(echo "${image_repo}" | tr '/' ' ' | awk '{print $NF;}')
13
-
14
- data_container_name="${image_name}-data"
15
-
16
- dependencies=""
17
- volumes=""
18
- published_ports=""
19
- misc_args=""
20
- command_args=()
21
-
22
- while [ "$#" -gt 0 ]; do
23
- case "$1" in
24
- --tag)
25
- shift; tag_name="$1"; shift
26
- image_tag="${tag_name}"
27
- ;;
28
- --dependency)
29
- shift; dep_name="$1"; shift
30
- dependencies="${dependencies} ${dep_name}"
31
- ;;
32
- --volume)
33
- shift; volume_arg="$1"; shift
34
- volumes="${volumes} ${volume_arg}"
35
- ;;
36
- --publish-all-ports)
37
- shift
38
- publishing_all_ports=1
39
- ;;
40
- --before-start)
41
- shift; before_start_script="$1"; shift
42
- ;;
43
- --cmd-arg)
44
- shift; command_args+=($1); shift
45
- ;;
46
- *)
47
- misc_arg="$1"; shift
48
- misc_args="${misc_args} ${misc_arg}"
49
- ;;
50
- esac
51
- done
52
-
53
- stopping_stanza="stopping docker"
54
- for dep_name in ${dependencies}; do
55
- stopping_stanza="${stopping_stanza} or stopping ${dep_name}"
56
- done
57
-
58
-
59
- data_container_volume_args=""
60
- for volume_mapping in ${volumes}; do
61
- data_container_volume_args="${data_container_volume_args} --volume=\"${volume_mapping}\""
62
- done
63
-
64
- service_name="${image_name}"
65
-
66
- cat >"/etc/rsyslog.d/92-${service_name}.conf" <<EOF
67
- input(type="imfile" File="/var/log/upstart/${service_name}.log" Tag="${service_name}" StateFile="${service_name}")
68
- EOF
69
-
70
- restart rsyslog
71
-
72
- cat >"/etc/init/${service_name}.conf" <<EOF
73
- #stop on (${stopping_stanza})
74
- stop on stopping docker
75
-
76
- env HOME=/root
77
-
78
- respawn
79
- respawn limit 5 20
80
-
81
- pre-start script
82
- . /etc/environment.local
83
-
84
- touch "/var/log/upstart/${service_name}.log"
85
- chown root:syslog "/var/log/upstart/${service_name}.log"
86
-
87
- echo "creating data container (${data_container_name}) if it doesn't exist..."
88
- docker run --name="${data_container_name}" ${data_container_volume_args} "${image_repo}:${image_tag}" /bin/true 2>/dev/null || :
89
-
90
- ${before_start_script}
91
-
92
- mkdir -p /run/docker/upstart-service-containers
93
- run_id=\$(docker-utils make-ref 5)
94
- echo "${service_name}" > '/run/docker/upstart-service-containers/${service_name}'
95
- end script
96
-
97
- post-stop script
98
- container_name="\$(cat '/run/docker/upstart-service-containers/${service_name}')"
99
- docker stop "\${container_name}" || :
100
- docker rm "\${container_name}" || :
101
- rm '/run/docker/upstart-service-containers/${service_name}'
102
- end script
103
-
104
- script
105
- . /etc/environment.local
106
-
107
- container_name="\$(cat '/run/docker/upstart-service-containers/${service_name}')"
108
-
109
- echo "discovering links for container \${container_name}:"
110
- link_args="\$(docker-utils container-links-for -w ${dependencies})"
111
-
112
- echo "starting container: \${container_name} (from ${image_repo}:${image_tag})..."
113
-
114
- if [ -n "${publishing_all_ports}" ]; then
115
- published_port_args=""
116
- published_ports="\$(docker inspect --format='{{.Config.ExposedPorts}}' "${image_repo}:${image_tag}" | sed -e 's/[^0-9]/ /g')"
117
- for port in \${published_ports}; do
118
- published_port_args="\${published_port_args} --publish=\"\${port}:\${port}\""
119
- done
120
- fi
121
-
122
- running_container_id=\$(docker run -d \
123
- --name="\${container_name}" \
124
- --volumes-from="${data_container_name}" \
125
- -e "BEXNG_TARGET_SYSTEM=\${DOMAIN}" \
126
- \${published_port_args} \
127
- \${link_args} \
128
- ${misc_args} \
129
- "${image_repo}:${image_tag}" \
130
- ${command_args[@]} \
131
- )
132
-
133
- exec docker attach --sig-proxy=true "\${running_container_id}"
134
- end script
135
- EOF
136
-
137
- echo "defined."