forked from apache/openwhisk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdocker.xml
126 lines (114 loc) · 5.76 KB
/
docker.xml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
<!-- docker helper ant targets -->
<!-- vim: set expandtab ts=4 sw=4 : -->
<project>
<import file="config/config.xml" />
<!-- start a private docker registry on the main docker endpoint,
and map it to the localhost port 5000 -->
<target name="startWhiskDockerRegistry" depends="writePropertyFile" if="${use.docker.registry}">
<var file="whisk.properties" />
<!-- we DO NOT fail on error here.
if the whisk docker registry is already running, the command will fail. so be it.
TODO: be less lazy and check if the docker registry is already running cleanly -->
<if>
<equals arg1="${docker.registry}" arg2="localhost:5000/" />
<then>
<exec executable="docker" failonerror="false">
<arg value="--host" />
<arg value="tcp://${main.docker.endpoint}" />
<arg line="${docker.tls.cmd}" />
<arg line="run -d -p 5000:5000 -e GUNICORN_OPTS=[--preload] --name=whisk_docker_registry --log-driver=none registry:2.1" />
</exec>
<ant target="tunnelDockerRegistry" />
</then>
</if>
</target>
<!-- wait up to a minute for the docker registry to start. Usually takes XX sec -->
<target name="waitWhiskDockerRegistry" depends="writePropertyFile" if="${use.docker.registry}">
<var file="whisk.properties" />
<if>
<equals arg1="${docker.registry}" arg2="localhost:5000/" forcestring="true" casesensitive="false" />
<then>
<exec executable="${python.27}" failonerror="true">
<env key="DOCKER_REGISTRY_HOST" value="${master.host}" />
<arg line="${openwhisk.dir}/tools/health/isAlive -d ${basedir} --wait 60 docker.registry" />
</exec>
</then>
</if>
</target>
<!-- save a docker image on the local host to a tar file-->
<target name="saveDockerImage" depends="writePropertyFile">
<var file="whisk.properties" />
<exec executable="docker" failonerror="true">
<arg line="save -o ${build.dir}/temp_image.tar ${docker.image.to.save} " />
</exec>
</target>
<!-- load a docker image from a tar file on the local host to a tar file-->
<target name="loadDockerImage" depends="writePropertyFile">
<var file="whisk.properties" />
<exec executable="docker" failonerror="true">
<arg value="--host" />
<arg value="tcp://${docker.endpoint}" />
<arg line="load -i ${build.dir}/temp_image.tar" />
</exec>
</target>
<!-- tag an image from docker.endpoint to match its name if pushed to the registry-->
<!-- images should be tagged regardless of deploy target but this slows down local builds by more than 2 minutes; so skip -->
<target name="tagImage" if="${use.docker.registry}">
<var file="whisk.properties" />
<exec executable="/bin/bash" failonerror="true">
<arg line="${openwhisk.dir}/tools/docker/dockerWithRetry.sh ${docker.timeout.short} --host tcp://${docker.endpoint}" />
<arg line="${docker.tls.cmd}" />
<arg line="tag -f ${docker.image.to.push} ${docker.registry}${docker.image.to.push}:${docker.image.tag}" />
</exec>
</target>
<!-- push an image from docker.endpoint to the registry as specified by docker.registry -->
<target name="pushImageToRegistry" depends="tagImage" if="${use.docker.registry}">
<var file="whisk.properties" />
<exec executable="/bin/bash" failonerror="true">
<arg line="${openwhisk.dir}/tools/docker/dockerWithRetry.sh ${docker.timeout.long} --host tcp://${docker.endpoint}" />
<arg line="${docker.tls.cmd}" />
<arg line="push ${docker.registry}${docker.image.to.push}:${docker.image.tag}" />
</exec>
</target>
<!-- pull an image from the whisk registry on the main docker endpoint
to another endpoint -->
<target name="pullImageFromRegistry" if="${use.docker.registry}">
<var file="whisk.properties" />
<exec executable="docker" failonerror="true">
<arg value="--host" />
<arg value="tcp://${docker.endpoint}" />
<arg line="${docker.tls.cmd}" />
<arg line="pull ${docker.registry}${docker.image.to.pull}:${docker.image.tag}" />
</exec>
</target>
<!-- pull an image from the whisk registry on the main docker endpoint
to another endpoint. This version spawns the command in
the background; it's intended as a prefetch optimization -->
<target name="prefetchPull" depends="writePropertyFile">
<var file="whisk.properties" />
<exec executable="docker" spawn="true">
<arg value="--host" />
<arg value="tcp://${docker.endpoint}" />
<arg line="pull ${docker.registry}${docker.image.to.pull}:${docker.image.tag}" />
</exec>
</target>
<!-- establish ssh tunnels from each machine to the registry host,
to allow insecure access to the docker registry via "localhost:5000"
-->
<target name="tunnelDockerRegistry" depends="writePropertyFile">
<var file="whisk.properties" />
<echo message="${deploy.target}" />
<if>
<not>
<equals arg1="local" arg2="${deploy.target}" />
</not>
<then>
<exec executable="/bin/bash">
<env key="WHISK_DOCKER_REGISTRY" value="${whisk.docker.registry}" />
<arg value="tools/build/docker/createRegistryTunnels.sh" />
<arg value="${basedir}/whisk.properties" />
</exec>
</then>
</if>
</target>
</project>