This repository has been archived by the owner on Aug 29, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 80
/
example.sh
executable file
·128 lines (93 loc) · 3.3 KB
/
example.sh
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
127
128
#!/bin/bash
function header() {
echo
echo
echo $1
echo --------------------------
}
port=${PORT:-43273}
base=http://localhost:$port
keydata=${KEYDATA:-"ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEA6NF8iallvQVp22WDkTkyrtvp9eWW6A8YVr+kz4TjGYe7gHzIw+niNltGEFHzD8+v1I2YJ6oXevct1YeS0o9HZyN1Q9qgCgzUFtdOKLv6IedplqoPkcmF0aYet2PkEDo3MlTBckFXPITAMzF8dJSIFo9D8HfdOV0IAdx4O7PtixWKn5y2hMNG0zQPyUecp4pzC6kivAIhyfHilFR61RGL+GPXQ2MWZWFYbAGjyiYJnAmCP3NOTd0jMZEnDkbUvxhMmBYSdETk1rRgm+R4LOzFUGaHqHDLKLX+FIPKcF96hrucXzcWyLbIbEgE98OHlnVYCzRdK8jlqm8tehUc9c9WhQ=="}
localpath=$(which systemctl)
islocal=$?
seq=${SEQ:-$(date +%s)00}
gear=$seq
gear1=$gear
header "Create a container and expose a single port"
curl "$base/container/$gear" -X PUT -d '{"Image":"openshift/busybox-http-app", "Ports":[{"Internal":8080}],"Started":true}'
echo
seq=$[seq+1]
header "List the ports from the container"
curl "$base/container/$gear/ports"
echo
seq=$[seq+1]
header "Follow the logs of the container for 30 seconds"
curl "$base/container/$gear/log"
echo
header "Print status of the container over the API"
curl "$base/container/$gear/status"
echo
seq=$[seq+1]
if [ $islocal -eq 0 ]; then
header "See the status of the container"
systemctl status ctr-$gear
fi
seq=$[seq+1]
gear=$[gear+1]
gear2=$gear
header "Create a second container"
curl "$base/container/$gear" -H "Content-Type: application/json" -d '{"Image":"openshift/busybox-http-app"}' -X PUT
echo
seq=$[seq+1]
header "Stop the second container"
curl "$base/container/$gear/stopped" -X PUT
echo
seq=$[seq+1]
header "Start the second container"
curl "$base/container/$gear/started" -X PUT
echo
if [ $islocal -eq 0 ]; then
header "See the gear slice"
systemctl status gear.slice
fi
seq=$[seq+1]
header "Set an environment resource"
curl "$base/environment/1000" -X PUT -H "Content-Type: application/json" -d '{"env":[{"name":"foo","value":"bar"}]}'
echo
seq=$[seq+1]
header "Patch that environment resource"
curl "$base/environment/1000" -X PATCH -H "Content-Type: application/json" -d '{"env":[{"name":"baz","value":"boo"}]}'
echo
seq=$[seq+1]
header "Fetch environment resource"
curl "$base/environment/1000"
echo
seq=$[seq+1]
header "Add keys to both gears"
curl "$base/keys" -X PUT -H "Content-Type: application/json" -d "{\"keys\":[{\"type\":\"authorized_keys\",\"value\":\"$keydata\"}],\"containers\":[{\"id\":\"$gear1\"},{\"id\":\"$gear2\"}]}"
echo
seq=$[seq+1]
header "Build an image"
curl "$base/build-image" -X POST -H "Content-Type: application/json" -d '{"BaseImage":"openshift/centos-ruby","Source":"http://github.com/openshift/sinatra-example.git","Tag":"mybuild-1"}'
seq=$[seq+1]
repo=${REPO:-$(date +%s)00}
header "Create an empty repository"
curl "$base/repository/$repo" -X PUT
echo
if [ $islocal -eq 0 ]; then
header "See the job logs for the repo"
journalctl --unit job-$repo --no-pager
echo
fi
seq=$[seq+1]
repo=$[repo+1]
header "Create a cloned repository"
curl "$base/repository/$repo" -H "Content-Type: application/json" -d '{"CloneUrl":"http://github.com/smarterclayton/docker-cartridge-examples"}' -X PUT
echo
if [ $islocal -eq 0 ]; then
header "See the job logs for the repo"
journalctl --unit job-$repo --no-pager
fi
echo
echo 'You can delete the artifacts generated by this script by stopping the daemon, running "gear purge",'
echo 'and then deleting /var/lib/containers/*'