-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathdokku.cloudscript
More file actions
124 lines (98 loc) · 4.32 KB
/
dokku.cloudscript
File metadata and controls
124 lines (98 loc) · 4.32 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
# Install latest Dokku on a CS1-SSD Cloudlet ($.015/hr) running Linux Ubuntu Server 14.04 LTS 64-bit
cloudscript dokku
version = _latest
result_template = dokku_result_template
globals
dokku_hostname = 'dokku'
dokku_instance_type = 'CS1-SSD' # 1GB RAM, 1 vCore, 25GB SSD, 10Gbps
dokku_image_type = 'Ubuntu Server 14.04 LTS'
default_slice_user = 'dokku'
dokku_version = '0.3.13' # latest version of dokku: https://github.com/progrium/dokku
server_password = lib::random_password()
console_password = lib::random_password()
thread dokku_setup
tasks = [dokku_server_setup]
task dokku_server_setup
#-------------------
# Create dokku keys
#-------------------
# Create dokku server root password key
/key/password dokku_server_password_key read_or_create
key_group = _SERVER
password = server_password
# Create dokku server console key
/key/password dokku_server_console_key read_or_create
key_group = _CONSOLE
password = console_password
#-----------------------------
# Create dokku storage slice,
# bootstrap script and recipe
#-----------------------------
# Create storage slice keys
/key/token default_slice_key read_or_create
username = default_slice_user
# Create slice to store script in cloudstorage
/storage/slice default_slice read_or_create
keys = [default_slice_key]
# Create slice container to store script in cloudstorage
/storage/container dokku_container => [default_slice] read_or_create
slice = default_slice
# Place script data in cloudstorage
/storage/object dokku_bootstrap_object => [default_slice, dokku_container] read_or_create
container_name = 'dokku_container'
file_name = 'bootstrap_dokku.sh'
slice = default_slice
content_data = dokku_bootstrap_data
# Associate the cloudstorage object with the dokku script
/orchestration/script dokku_bootstrap_script => [default_slice, dokku_container, dokku_bootstrap_object] read_or_create
data_uri = 'cloudstorage://default_slice/dokku_container/bootstrap_dokku.sh'
script_type = _SHELL
encoding = _STORAGE
# Create the recipe and associate the script
/orchestration/recipe dokku_bootstrap_recipe read_or_create
scripts = [dokku_bootstrap_script]
#-------------------------
# Create the dokku server
#-------------------------
/server/cloud dokku_server read_or_create
hostname = '{{ dokku_hostname }}'
image = '{{ dokku_image_type }}'
service_type = '{{ dokku_instance_type }}'
keys = [dokku_server_password_key, dokku_server_console_key]
recipes = [dokku_bootstrap_recipe]
text_template dokku_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
}
# Download Dokku bootstrap script and install latest version
wget -qO- https://raw.github.com/progrium/dokku/v{{ dokku_version }}/bootstrap.sh | sudo DOKKU_BRANCH=master bash
# 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
# Try to add FQDN name to VHOST file
if [ `hostname` = `hostname -f` ];then
ERROR=$(echo "DNS doesn't work propertly. You should add FQDN server name to ~/dokku/VHOST")
else
ERROR=$(echo "Your server FQDN is `hostname -f`")
echo `hostname -f` > /root/dokku/VHOST
fi
echo $ERROR
_eof
text_template dokku_result_template
Your Dokku server is ready at the following IP address:
{{ dokku_server.ipaddress_public }}
login: root
password: {{ dokku_server_password_key.password }}
You'll have to add a public key associated with a username by doing something like this from your local machine:
$ cat ~/.ssh/id_rsa.pub | ssh dokku.me "sudo sshcommand acl-add dokku $USER"
_eof