forked from nephoscale/cloudscript
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdocker_shipyard.cloudscript
More file actions
171 lines (136 loc) · 5.71 KB
/
docker_shipyard.cloudscript
File metadata and controls
171 lines (136 loc) · 5.71 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
# Install latest Docker Shipyard on a CS1-SSD Cloudlet ($.015/hr) running Linux Ubuntu Server 14.04 LTS 64-bit
cloudscript docker
version = _latest
result_template = docker_result_template
globals
docker_hostname = 'docker'
docker_instance_type = 'CS1-SSD' # 1GB RAM, 1 vCore, 25GB SSD, 10Gbps
docker_image_type = 'Ubuntu Server 14.04 LTS'
docker_shipyard_slice_user = 'docker'
server_password = lib::random_password()
console_password = lib::random_password()
webui_password = lib::random_password()
thread docker_setup
tasks = [docker_shipyard_server_setup]
task docker_shipyard_server_setup
#--------------------
# Create docker keys
#--------------------
# Create docker server root password key
/key/password docker_shipyard_server_password_key read_or_create
key_group = _SERVER
password = server_password
# Create docker server console key
/key/password docker_shipyard_server_console_key read_or_create
key_group = _CONSOLE
password = console_password
# Create docker server WEB UI key
/key/password docker_shipyard_server_webui_key read_or_create
key_group = _SERVER
password = webui_password
#------------------------------
# Create docker storage slice,
# bootstrap script and recipe
#------------------------------
# Create storage slice keys
/key/token docker_shipyard_slice_key read_or_create
username = docker_shipyard_slice_user
# Create slice to store script in cloudstorage
/storage/slice docker_shipyard_slice read_or_create
keys = [docker_shipyard_slice_key]
# Create slice container to store script in cloudstorage
/storage/container docker_shipyard_container => [docker_shipyard_slice] read_or_create
slice = docker_shipyard_slice
# Place script data in cloudstorage
/storage/object docker_shipyard_bootstrap_object => [docker_shipyard_slice, docker_shipyard_container] read_or_create
container_name = 'docker_shipyard_container'
file_name = 'bootstrap_docker.sh'
slice = docker_shipyard_slice
content_data = docker_shipyard_bootstrap_data
# Associate the cloudstorage object with the docker script
/orchestration/script docker_shipyard_bootstrap_script => [docker_shipyard_slice, docker_shipyard_container, docker_shipyard_bootstrap_object] read_or_create
data_uri = 'cloudstorage://docker_shipyard_slice/docker_shipyard_container/bootstrap_docker.sh'
script_type = _SHELL
encoding = _STORAGE
# Create the recipe and associate the script
/orchestration/recipe docker_shipyard_bootstrap_recipe read_or_create
scripts = [docker_shipyard_bootstrap_script]
#--------------------------
# Create the docker server
#--------------------------
/server/cloud docker_shipyard_server read_or_create
hostname = '{{ docker_hostname }}'
image = '{{ docker_image_type }}'
service_type = '{{ docker_instance_type }}'
keys = [docker_shipyard_server_password_key, docker_shipyard_server_console_key]
recipes = [docker_shipyard_bootstrap_recipe]
text_template docker_shipyard_bootstrap_data
#!/bin/sh
# check if running as root
[ `whoami` = 'root' ] || {
echo "ERROR: must have root permissions to execute the commands"
exit 1
}
# check that apt-get will work with HTTPS
[ -e /usr/lib/apt/methods/https ] || {
apt-get update
apt-get install apt-transport-https -y
}
# Add key and docker repo
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys 36A1D7869245C8950F966E92D8576A8BA88D21E9
echo "deb https://get.docker.com/ubuntu docker main" > /etc/apt/sources.list.d/docker.list
# check new repo and install docker
apt-get update
apt-get install lxc-docker -y
apt-get install lxc -y
# Prepare docker config
echo 'DOCKER_OPTS="--bip=172.17.42.1/26"' >> /etc/default/docker
service docker stop
ip link delete docker0
service docker start
# deploy shipyard container
sleep 2s
docker run -it -d --name shipyard-rethinkdb-data --entrypoint /bin/bash shipyard/rethinkdb -l
docker run -it -P -d --name shipyard-rethinkdb --volumes-from shipyard-rethinkdb-data shipyard/rethinkdb
docker run -it -p 8080:8080 -d --name shipyard --link shipyard-rethinkdb:rethinkdb shipyard/shipyard
# Download shipyard-cli
docker pull shipyard/shipyard-cli
# Install 'expect'
apt-get install expect-lite -y
# Get IP
IP=$(ifconfig eth0 |grep 'inet addr'| awk '{print $2}' |cut -f2 -d':')
# Create 'expect' script for changing default password
expect_cmd() {
cat <<EOS
spawn docker run -it shipyard/shipyard-cli
expect "shipyard cli"
send "shipyard login\n"
expect "URL:"
send "http://$IP:8080\n"
expect "Username:"
send "admin\n"
expect "Password:"
send "shipyard\n"
expect "shipyard cli"
send "shipyard change-password\n"
expect "Password:"
send "{{ docker_shipyard_server_webui_key.password }}\n"
expect "Confirm:"
send "{{ docker_shipyard_server_webui_key.password }}\n"
expect "shipyard cli"
send "exit\n"
EOS
}
# Change password
expect -c "$(expect_cmd)"
_eof
text_template docker_result_template
Your Docker server is ready at the following IP address:
{{ docker_shipyard_server.ipaddress_public }}
login: root
password: {{ docker_shipyard_server_password_key.password }}
or you can use web interface:
http://{{ docker_shipyard_server.ipaddress_public }}:8080
login: admin
password: {{ docker_shipyard_server_webui_key.password }}
_eof