Skip to content

Commit cd66fd2

Browse files
committed
refactor(Vagrantfile): merge Vagrantfiles and update to upstream
This commit merges the Makefiles and Vagrantfiles, and supports both a 1-node and n-node local cluster with the same files. Also, the user-data and override-plugin have been updated to be more closely in line with upstream. Also updates README with additional instructions. closes #760, #747
1 parent 3e753ac commit cd66fd2

15 files changed

Lines changed: 243 additions & 289 deletions

Makefile

Lines changed: 27 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,43 +2,52 @@
22
# Deis Makefile
33
#
44

5+
ifndef DEIS_NUM_INSTANCES
6+
DEIS_NUM_INSTANCES = 1
7+
endif
8+
9+
define ssh_all
10+
i=1 ; while [ $$i -le $(DEIS_NUM_INSTANCES) ] ; do \
11+
vagrant ssh deis-$$i -c $(1) ; \
12+
i=`expr $$i + 1` ; \
13+
done
14+
endef
15+
516
# ordered list of deis components
6-
COMPONENTS=builder cache controller database logger registry router
17+
# we don't manage the router if we're setting up a local cluster
18+
ifeq ($(DEIS_NUM_INSTANCES),1)
19+
COMPONENTS=builder cache controller database logger registry router
20+
else
21+
COMPONENTS=builder cache controller database logger registry
22+
endif
723

824
all: build run
925

10-
test_client:
11-
python -m unittest discover client.tests
12-
1326
pull:
14-
vagrant ssh -c 'for c in $(COMPONENTS); do docker pull deis/$$c; done'
27+
$(call ssh_all,'for c in $(COMPONENTS); do docker pull deis/$$c; done')
1528

1629
build:
17-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done'
30+
$(call ssh_all,'cd share && for c in $(COMPONENTS); do cd $$c && docker build -t deis/$$c . && cd ..; done')
1831

1932
install:
20-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c && sudo systemctl enable $$(pwd)/systemd/* && cd ..; done'
33+
for c in $(COMPONENTS); do fleetctl --strict-host-key-checking=false submit $$c/systemd/*; done
2134

2235
uninstall: stop
23-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c && sudo systemctl disable $$(pwd)/systemd/* && cd ..; done'
36+
for c in $(COMPONENTS); do fleetctl --strict-host-key-checking=false destroy $$c/systemd/*; done
2437

2538
start:
2639
echo "\033[0;33mStarting services can take some time... grab some coffee!\033[0m"
27-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c/systemd && sudo systemctl start * && cd ../..; done'
40+
for c in $(COMPONENTS); do fleetctl --strict-host-key-checking=false start $$c/systemd/*; done
2841

2942
stop:
30-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c/systemd && sudo systemctl stop * && cd ../..; done'
31-
32-
restart:
33-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c/systemd && sudo systemctl restart * && cd ../..; done'
43+
for c in $(COMPONENTS); do fleetctl --strict-host-key-checking=false stop $$c/systemd/*; done
3444

35-
logs:
36-
vagrant ssh -c 'journalctl -f -u deis-*'
45+
restart: stop start
3746

38-
run: install start logs
47+
run: install start
3948

4049
clean: uninstall
41-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do docker rm -f deis-$$c; done'
50+
$(call ssh_all,'for c in $(COMPONENTS); do docker rm -f deis-$$c; done')
4251

4352
full-clean: clean
44-
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do docker rmi deis-$$c; done'
53+
$(call ssh_all,'for c in $(COMPONENTS); do docker rmi deis-$$c; done')

README.md

Lines changed: 79 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,56 +17,85 @@ If you need to use Deis with Chef integration, on Ubuntu 12.04 LTS, or
1717
on DigitalOcean, you should use the
1818
[v0.7.0 release](https://github.com/deis/deis/tree/v0.7.0) of Deis.
1919

20-
# Installation
20+
# Deploying Deis
2121

22-
Deis is a set of Docker containers that can be deployed anywhere including public cloud, private cloud, bare metal or your workstation. You will need [Docker](https://www.docker.io/) and [Vagrant](http://www.vagrantup.com/) to get started.
22+
Deis is a set of Docker containers that can be deployed anywhere including public cloud, private cloud, bare metal or your workstation. Decide where you'd like to deploy Deis, then follow the deployment-specific documentation for [Rackspace](contrib/rackspace/README.md) or [EC2](contrib/ec2/README.md). Documentation for OpenStack and bare-metal provisioning are forthcoming.
23+
24+
Trying out Deis? Continue following these instructions for a local cluster setup. This is also a great Deis testing/development environment.
25+
26+
## Install prerequisites
27+
On your workstation:
28+
* Install [Vagrant](http://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
29+
* Install [Go](http://golang.org/doc/install) and configure your GOPATH, if necessary
30+
* Install the fleetctl client: `go get github.com/coreos/fleet && go install github.com/coreos/fleet/fleetctl`
31+
* Install the Docker client if you want to run Docker commands locally (optional)
32+
33+
## Additional setup for a multi-node cluster
34+
If you'd like to spin up more than one VM to test an entire cluster, there are a few additional prerequisites:
35+
* Set `DEIS_NUM_INSTANCES` to the desired size of your cluster: ```$ export DEIS_NUM_INSTANCES=3```
36+
* Edit [contrib/coreos/user-data](contrib/coreos/user-data) and add a unique discovery URL generated from `https://discovery.etcd.io/new`
2337

2438
## Boot CoreOS
2539

26-
First, start a CoreOS virtual machine on VirtualBox. From a command prompt, `cd` to the root of the Deis project code and type:
40+
First, start the CoreOS cluster on VirtualBox. From a command prompt, `cd` to the root of the Deis project code and type:
2741

42+
```console
43+
$ vagrant up
2844
```
29-
vagrant up
45+
46+
This instructs Vagrant to spin up each VM. To be able to connect to the VMs, you must add your Vagrant-generated SSH key to the ssh-agent (fleetctl tunnel requires the agent to have this key):
47+
```console
48+
$ ssh-add ~/.vagrant.d/insecure_private_key`
3049
```
3150

32-
Export some environment variables so you can connect to the VM using the `docker` and [`fleetctl`](https://github.com/coreos/fleet#building) clients on your workstation.
51+
Export some environment variables so you can connect to the VM using the `docker` and `fleetctl` clients on your workstation.
3352

34-
```
35-
export DOCKER_HOST=tcp://172.17.8.100:4243
36-
export FLEETCTL_TUNNEL=172.17.8.100
53+
```console
54+
$ export DOCKER_HOST=tcp://172.17.8.100:4243
55+
$ export FLEETCTL_TUNNEL=172.17.8.100
3756
```
3857

3958
## Build Deis
4059

41-
Use `make pull` to download cached layers from the public Docker Index. Then use `make build` to assemble all of the Deis components from Dockerfiles. Grab some coffee while it builds the images on the CoreOS VM (it can take a while).
60+
Use `make pull` to download cached layers from the public Docker Index. Then use `make build` to assemble all of the Deis components from Dockerfiles. Grab some coffee while it builds the images on each VM (it can take a while).
4261

43-
```
44-
make pull
45-
make build
62+
```console
63+
$ make pull
64+
$ make build
4665
```
4766

4867
## Run Deis
4968

5069
Use `make run` to start all Deis containers and attach to their log output. This can take some time - the registry service will pull and prepare a Docker image. Grab some more coffee!
5170

71+
```console
72+
$ make run
5273
```
53-
make run
54-
```
74+
75+
## Additional steps for a multi-node cluster
76+
* Configure local DNS. For a one-node cluster we do this for you: `local.deisapp.com` resolves to the IP of the first VM, 172.17.8.100. Since we cannot know where the `deis-router` container will be running in your cluster, you'll need to setup DNS and resolve a wildcard entry to use for your apps.
77+
* Because of the DNS quandary, we don't start the deis-router component for you. You'll need to start this manually once DNS is setup: `systemctl start deis-router`.
5578

5679
## Install the Deis Client
57-
Either use `pip install deis` to install the latest [Deis Client](https://pypi.python.org/pypi/deis/), download [pre-compiled binaries](https://github.com/deis/deis/tree/master/client#get-started), or symlink `client/deis.py` to use your local development version.
80+
If you're using the latest Deis release, use `pip install deis` to install the latest [Deis Client](https://pypi.python.org/pypi/deis/) or download [pre-compiled binaries](https://github.com/deis/deis/tree/master/client#get-started).
5881

82+
If you're working off master, precompiled binaries are likely out of date. You should either symlink the python file directly or build a local copy of the client:
83+
84+
```console
85+
$ ln -fs $(pwd)/client/deis.py /usr/local/bin/deis
5986
```
60-
ln -fs $(pwd)/client/deis.py /usr/local/bin/deis
87+
or
88+
```console
89+
$ cd client && python setup.py install
6190
```
6291

6392
## Register a User
6493

6594
Use the Deis Client to register a new user.
6695

67-
```
68-
deis register http://local.deisapp.com:8000
69-
deis keys:add
96+
```console
97+
$ deis register http://local.deisapp.com:8000
98+
$ deis keys:add
7099
```
71100

72101
Use `deis keys:add` to add your SSH public key for `git push` access.
@@ -75,8 +104,8 @@ Use `deis keys:add` to add your SSH public key for `git push` access.
75104

76105
Initalize a `dev` cluster with a list of CoreOS hosts and your CoreOS private key.
77106

78-
```
79-
deis clusters:create dev local.deisapp.com --hosts=local.deisapp.com --auth=~/.vagrant.d/insecure_private_key
107+
```console
108+
$ deis clusters:create dev local.deisapp.com --hosts=local.deisapp.com --auth=~/.vagrant.d/insecure_private_key
80109
```
81110

82111
The `dev` cluster will be used as the default cluster for future `deis` commands.
@@ -86,8 +115,8 @@ The `dev` cluster will be used as the default cluster for future `deis` commands
86115
## Create an Application
87116
Create an application on the default `dev` cluster.
88117

89-
```
90-
deis create
118+
```console
119+
$ deis create
91120
```
92121

93122
Use `deis create --cluster=prod` to place the app on a different cluster. Don't like our name-generator? Use `deis create myappname`.
@@ -98,41 +127,58 @@ Push builds of your application from your local git repository or from a Docker
98127
#### From a Git Repository
99128
When you created the application, a git remote for Deis was added automatically.
100129

101-
```
102-
git push deis master
130+
```console
131+
$ git push deis master
103132
```
104133
This will use the Deis builder to package your application as a Docker Image and deploy it on your application's cluster.
105134

106135
## Configure
107136
Configure your application with environment variables. Each config change also creates a new release.
108137

109-
```
110-
deis config:set DATABASE_URL=postgres://
138+
```console
139+
$ deis config:set DATABASE_URL=postgres://
111140
```
112141

113142
Coming soon: Use the integrated ETCD namespace for service discovery between applications on the same cluster.
114143

115144
## Test
145+
### Run tests
116146
Test your application by running commands inside an ephemeral Docker container.
117147

118-
```
119-
deis run make test
148+
```console
149+
$ deis run make test
120150
```
121151

122152
To integrate with your CI system, check the return code.
123153

154+
### Testing the cluster
155+
Logging into one of the CoreOS machines and stopping a container service should cause the same component on another CoreOS
156+
host to take over as master
157+
158+
These systemd services run the various containers which compose Deis, and can be stopped on a machine with `sudo systemctl stop servicename`.
159+
* deis-builder.service
160+
* deis-cache.service
161+
* deis-controller.service
162+
* deis-database.service
163+
* deis-discovery.service
164+
* deis-logger.service
165+
* deis-registry.service
166+
* deis-router.service
167+
168+
Similarly, bringing down a VM should enable the services on another VM to take over as master
169+
124170
## Scale
125171
Scale containers horizontally with ease.
126172

127-
```
128-
deis scale web=8
173+
```console
174+
$ deis scale web=8
129175
```
130176

131177
## Debug
132178
Access to aggregated logs makes it easy to troubleshoot problems with your application.
133179

134-
```
135-
deis logs
180+
```console
181+
$ deis logs
136182
```
137183

138184
Use `deis run` to execute one-off commands and explore the deployed container. Coming soon: `deis attach` to jump into a live container.

Vagrantfile

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,16 @@
33

44
require_relative 'contrib/coreos/override-plugin.rb'
55

6+
DEIS_NUM_INSTANCES = (ENV['DEIS_NUM_INSTANCES'].to_i > 0 && ENV['DEIS_NUM_INSTANCES'].to_i) || 1
7+
8+
if DEIS_NUM_INSTANCES == 1
9+
mem = 4096
10+
cpus = 2
11+
else
12+
mem = 2048
13+
cpus = 1
14+
end
15+
616
Vagrant.configure("2") do |config|
717
config.vm.box = "coreos-295.0.0"
818
config.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/295.0.0/coreos_production_vagrant.box"
@@ -12,7 +22,6 @@ Vagrant.configure("2") do |config|
1222
end
1323

1424
config.vm.provider :virtualbox do |vb, override|
15-
vb.customize ["modifyvm", :id, "--memory", "4096"]
1625
# Fix docker not being able to resolve private registry in VirtualBox
1726
vb.customize ["modifyvm", :id, "--natdnshostresolver1", "on"]
1827
vb.customize ["modifyvm", :id, "--natdnsproxy1", "on"]
@@ -23,29 +32,30 @@ Vagrant.configure("2") do |config|
2332
config.vbguest.auto_update = false
2433
end
2534

26-
config.vm.define vm_name = "deis" do |config|
27-
config.vm.hostname = vm_name
28-
29-
ip = "172.17.8.100"
30-
config.vm.network :private_network, ip: ip
35+
(1..DEIS_NUM_INSTANCES).each do |i|
36+
config.vm.define vm_name = "deis-#{i}" do |config|
37+
config.vm.hostname = vm_name
3138

32-
# Uncomment below to enable NFS for sharing the host machine into the coreos-vagrant VM.
33-
config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
39+
config.vm.provider :virtualbox do |vb|
40+
vb.memory = mem
41+
vb.cpus = cpus
42+
end
3443

35-
# workaround missing /etc/hosts
36-
config.vm.provision :shell, :inline => "echo #{ip} #{vm_name} > /etc/hosts", :privileged => true
44+
ip = "172.17.8.#{i+99}"
45+
config.vm.network :private_network, ip: ip
3746

38-
# workaround missing /etc/environment
39-
config.vm.provision :shell, :inline => "touch /etc/environment", :privileged => true
47+
# Enable NFS for sharing the host machine into the coreos-vagrant VM.
48+
config.vm.synced_folder ".", "/home/core/share", id: "core", :nfs => true, :mount_options => ['nolock,vers=3,udp']
4049

41-
# disable update-engine to prevent reboots
42-
config.vm.provision :shell, :inline => "systemctl stop update-engine-reboot-manager && systemctl disable update-engine-reboot-manager && systemctl mask update-engine-reboot-manager", :privileged => true
43-
config.vm.provision :shell, :inline => "systemctl stop update-engine && systemctl disable update-engine && systemctl mask update-engine", :privileged => true
50+
# disable update-engine to prevent reboots
51+
config.vm.provision :shell, :inline => "systemctl stop update-engine-reboot-manager && systemctl disable update-engine-reboot-manager && systemctl mask update-engine-reboot-manager", :privileged => true
52+
config.vm.provision :shell, :inline => "systemctl stop update-engine && systemctl disable update-engine && systemctl mask update-engine", :privileged => true
4453

45-
# user-data bootstrapping
46-
config.vm.provision :file, :source => "contrib/coreos/user-data", :destination => "/tmp/user-data"
47-
config.vm.provision :shell, :inline => "mkdir -p /var/lib/coreos-vagrant && mv /tmp/user-data /var/lib/coreos-vagrant", :privileged => true
54+
# user-data bootstrapping
55+
config.vm.provision :file, :source => "contrib/coreos/user-data", :destination => "/tmp/vagrantfile-user-data"
56+
config.vm.provision :shell, :inline => "mv /tmp/vagrantfile-user-data /var/lib/coreos-vagrant/", :privileged => true
4857

58+
end
4959
end
5060

5161
end

0 commit comments

Comments
 (0)