Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
refactor(Vagrantfile): merge Vagrantfiles and update to upstream
Browse files Browse the repository at this point in the history
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
  • Loading branch information
carmstrong committed Apr 23, 2014
1 parent 3e753ac commit cd66fd2
Show file tree
Hide file tree
Showing 15 changed files with 243 additions and 289 deletions.
45 changes: 27 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,52 @@
# Deis Makefile
#

ifndef DEIS_NUM_INSTANCES
DEIS_NUM_INSTANCES = 1
endif

define ssh_all
i=1 ; while [ $$i -le $(DEIS_NUM_INSTANCES) ] ; do \
vagrant ssh deis-$$i -c $(1) ; \
i=`expr $$i + 1` ; \
done
endef

# ordered list of deis components
COMPONENTS=builder cache controller database logger registry router
# we don't manage the router if we're setting up a local cluster
ifeq ($(DEIS_NUM_INSTANCES),1)
COMPONENTS=builder cache controller database logger registry router
else
COMPONENTS=builder cache controller database logger registry
endif

all: build run

test_client:
python -m unittest discover client.tests

pull:
vagrant ssh -c 'for c in $(COMPONENTS); do docker pull deis/$$c; done'
$(call ssh_all,'for c in $(COMPONENTS); do docker pull deis/$$c; done')

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

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

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

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

stop:
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do cd $$c/systemd && sudo systemctl stop * && cd ../..; done'

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

logs:
vagrant ssh -c 'journalctl -f -u deis-*'
restart: stop start

run: install start logs
run: install start

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

full-clean: clean
vagrant ssh -c 'cd share && for c in $(COMPONENTS); do docker rmi deis-$$c; done'
$(call ssh_all,'for c in $(COMPONENTS); do docker rmi deis-$$c; done')
112 changes: 79 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,56 +17,85 @@ If you need to use Deis with Chef integration, on Ubuntu 12.04 LTS, or
on DigitalOcean, you should use the
[v0.7.0 release](https://github.com/deis/deis/tree/v0.7.0) of Deis.

# Installation
# Deploying Deis

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.
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.

Trying out Deis? Continue following these instructions for a local cluster setup. This is also a great Deis testing/development environment.

## Install prerequisites
On your workstation:
* Install [Vagrant](http://www.vagrantup.com/downloads.html) and [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
* Install [Go](http://golang.org/doc/install) and configure your GOPATH, if necessary
* Install the fleetctl client: `go get github.com/coreos/fleet && go install github.com/coreos/fleet/fleetctl`
* Install the Docker client if you want to run Docker commands locally (optional)

## Additional setup for a multi-node cluster
If you'd like to spin up more than one VM to test an entire cluster, there are a few additional prerequisites:
* Set `DEIS_NUM_INSTANCES` to the desired size of your cluster: ```$ export DEIS_NUM_INSTANCES=3```
* Edit [contrib/coreos/user-data](contrib/coreos/user-data) and add a unique discovery URL generated from `https://discovery.etcd.io/new`

## Boot CoreOS

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

```console
$ vagrant up
```
vagrant up

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):
```console
$ ssh-add ~/.vagrant.d/insecure_private_key`
```

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.
Export some environment variables so you can connect to the VM using the `docker` and `fleetctl` clients on your workstation.

```
export DOCKER_HOST=tcp://172.17.8.100:4243
export FLEETCTL_TUNNEL=172.17.8.100
```console
$ export DOCKER_HOST=tcp://172.17.8.100:4243
$ export FLEETCTL_TUNNEL=172.17.8.100
```

## Build Deis

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).
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).

```
make pull
make build
```console
$ make pull
$ make build
```

## Run Deis

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!

```console
$ make run
```
make run
```

## Additional steps for a multi-node cluster
* 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.
* 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`.

## Install the Deis Client
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.
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).

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:

```console
$ ln -fs $(pwd)/client/deis.py /usr/local/bin/deis
```
ln -fs $(pwd)/client/deis.py /usr/local/bin/deis
or
```console
$ cd client && python setup.py install
```

## Register a User

Use the Deis Client to register a new user.

```
deis register http://local.deisapp.com:8000
deis keys:add
```console
$ deis register http://local.deisapp.com:8000
$ deis keys:add
```

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

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

```
deis clusters:create dev local.deisapp.com --hosts=local.deisapp.com --auth=~/.vagrant.d/insecure_private_key
```console
$ deis clusters:create dev local.deisapp.com --hosts=local.deisapp.com --auth=~/.vagrant.d/insecure_private_key
```

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

```
deis create
```console
$ deis create
```

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

```
git push deis master
```console
$ git push deis master
```
This will use the Deis builder to package your application as a Docker Image and deploy it on your application's cluster.

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

```
deis config:set DATABASE_URL=postgres://
```console
$ deis config:set DATABASE_URL=postgres://
```

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

## Test
### Run tests
Test your application by running commands inside an ephemeral Docker container.

```
deis run make test
```console
$ deis run make test
```

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

### Testing the cluster
Logging into one of the CoreOS machines and stopping a container service should cause the same component on another CoreOS
host to take over as master

These systemd services run the various containers which compose Deis, and can be stopped on a machine with `sudo systemctl stop servicename`.
* deis-builder.service
* deis-cache.service
* deis-controller.service
* deis-database.service
* deis-discovery.service
* deis-logger.service
* deis-registry.service
* deis-router.service

Similarly, bringing down a VM should enable the services on another VM to take over as master

## Scale
Scale containers horizontally with ease.

```
deis scale web=8
```console
$ deis scale web=8
```

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

```
deis logs
```console
$ deis logs
```

Use `deis run` to execute one-off commands and explore the deployed container. Coming soon: `deis attach` to jump into a live container.
Expand Down
46 changes: 28 additions & 18 deletions Vagrantfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,16 @@

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

DEIS_NUM_INSTANCES = (ENV['DEIS_NUM_INSTANCES'].to_i > 0 && ENV['DEIS_NUM_INSTANCES'].to_i) || 1

if DEIS_NUM_INSTANCES == 1
mem = 4096
cpus = 2
else
mem = 2048
cpus = 1
end

Vagrant.configure("2") do |config|
config.vm.box = "coreos-295.0.0"
config.vm.box_url = "http://storage.core-os.net/coreos/amd64-usr/295.0.0/coreos_production_vagrant.box"
Expand All @@ -12,7 +22,6 @@ Vagrant.configure("2") do |config|
end

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

config.vm.define vm_name = "deis" do |config|
config.vm.hostname = vm_name

ip = "172.17.8.100"
config.vm.network :private_network, ip: ip
(1..DEIS_NUM_INSTANCES).each do |i|
config.vm.define vm_name = "deis-#{i}" do |config|
config.vm.hostname = vm_name

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

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

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

# disable update-engine to prevent reboots
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
config.vm.provision :shell, :inline => "systemctl stop update-engine && systemctl disable update-engine && systemctl mask update-engine", :privileged => true
# disable update-engine to prevent reboots
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
config.vm.provision :shell, :inline => "systemctl stop update-engine && systemctl disable update-engine && systemctl mask update-engine", :privileged => true

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

end
end

end
Loading

0 comments on commit cd66fd2

Please sign in to comment.