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

Commit

Permalink
fix(services): manage dependencies manually
Browse files Browse the repository at this point in the history
Since fleet's dependency management cross-cluster is lacking
(see coreos/fleet#338), we resort to starting the services in
a certain order. We also remove Requires=/After= if the dependency
could potentially exist on another server in the cluster.
We're essentially waiting for X-Requires/X-After to be implemented
in fleet.

Also, we make the contrib/ scripts use this Makefile to start
services so we don't repeat logic. Lastly, fleet version checking
is added to the Makefile so that it will error if fleetctl locally
is a different version than the server - many unstable/incomplete
changes are in master.

fixes #810, #805
  • Loading branch information
carmstrong committed Apr 28, 2014
1 parent 0a8e71b commit 787d857
Show file tree
Hide file tree
Showing 9 changed files with 88 additions and 121 deletions.
104 changes: 77 additions & 27 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,54 +2,104 @@
# Deis Makefile
#

ifndef FLEETCTL_TUNNEL
$(error You need to set FLEETCTL_TUNNEL to the IP address of a server in the cluster.)
endif

ifndef DEIS_NUM_INSTANCES
DEIS_NUM_INSTANCES = 1
DEIS_NUM_INSTANCES = 1
endif

# TODO refactor to support non-vagrant installations, since this Makefile
# is now used by the various contrib/ scripts.
define ssh_all
i=1 ; while [ $$i -le $(DEIS_NUM_INSTANCES) ] ; do \
vagrant ssh deis-$$i -c $(1) ; \
i=`expr $$i + 1` ; \
done
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
# we don't manage the router if we're setting up a local cluster
define echo_yellow
@echo "\033[0;33m$(subst ",,$(1))\033[0m"
endef

# due to scheduling problems with fleet 0.2.0, start order of components
# is fragile. hopefully this can be changed soon...
ALL_COMPONENTS=builder cache controller database logger registry router

ifeq ($(DEIS_NUM_INSTANCES),1)
COMPONENTS=builder cache controller database logger registry router
export SKIP_ROUTER=false
START_COMPONENTS=registry logger cache database router
else
COMPONENTS=builder cache controller database logger registry
export SKIP_ROUTER=true
START_COMPONENTS=registry logger cache database
endif

UNIT_FILES = $(foreach C, $(COMPONENTS), $(wildcard $(C)/systemd/*))
ALL_UNITS = $(foreach C, $(ALL_COMPONENTS), $(wildcard $(C)/systemd/*))
START_UNITS = $(foreach C, $(START_COMPONENTS), $(wildcard $(C)/systemd/*))

all: build run

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

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

install:
fleetctl --strict-host-key-checking=false submit $(UNIT_FILES)
check-fleet:
@LOCAL_VERSION=`fleetctl -version`; \
REMOTE_VERSION=`ssh core@$(FLEETCTL_TUNNEL) fleetctl -version`; \
if [ "$$LOCAL_VERSION" != "$$REMOTE_VERSION" ]; then \
echo "Your fleetctl client version should match the server. Local version: $$LOCAL_VERSION, server version: $$REMOTE_VERSION. Uninstall your local version and install the latest build from https://github.com/coreos/fleet/releases"; exit 1; \
fi

clean: uninstall
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rm -f deis-$$c; done')

uninstall: stop
fleetctl --strict-host-key-checking=false destroy $(UNIT_FILES)
full-clean: clean
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker rmi deis-$$c; done')

start:
echo "\033[0;33mStarting services can take some time... grab some coffee!\033[0m"
fleetctl --strict-host-key-checking=false start $(UNIT_FILES)
install: check-fleet
fleetctl --strict-host-key-checking=false submit $(START_UNITS)

stop:
fleetctl --strict-host-key-checking=false stop $(UNIT_FILES)
pull:
$(call ssh_all,'for c in $(ALL_COMPONENTS); do docker pull deis/$$c; done')

restart: stop start

run: install start

clean: uninstall
$(call ssh_all,'for c in $(COMPONENTS); do docker rm -f deis-$$c; done')
start: check-fleet
fleetctl --strict-host-key-checking=false start $(START_UNITS)
$(call echo_yellow,"Use 'make status' to monitor these services")
$(call echo_yellow,"Run 'make start-builder' to continue once all are running")

full-clean: clean
$(call ssh_all,'for c in $(COMPONENTS); do docker rmi deis-$$c; done')
start-builder: check-fleet
fleetctl --strict-host-key-checking=false submit builder/systemd/*
fleetctl --strict-host-key-checking=false start builder/systemd/*
$(call echo_yellow,"Use 'make status' to monitor the service")
$(call echo_yellow,"Run 'make start-controller' to continue once the service is running")

start-controller: check-fleet
fleetctl --strict-host-key-checking=false submit controller/systemd/*
fleetctl --strict-host-key-checking=false start controller/systemd/*
$(call echo_yellow,"Use 'make status' to monitor the service")
@if [ "$$SKIP_ROUTER" == true ]; then \
echo "\033[0;33mYou'll need to configure DNS and start the router manually for multi-node clusters.\033[0m" ; \
echo "\033[0;33mRun 'make start-router' to schedule and start deis-router.\033[0m" ; \
else \
echo "\033[0;33mYour Deis cluster is ready to go once the controller is live! Follow the README to login and use Deis.\033[0m" ; \
fi

start-router: check-fleet
fleetctl --strict-host-key-checking=false submit router/systemd/*
fleetctl --strict-host-key-checking=false start router/systemd/*
$(call echo_yellow,"Use 'make status' to monitor the service and note the IP it has been scheduled to.")
$(call echo_yellow,"Create a wildcard DNS domain which resolves to this host and use that domain when creating clusters/apps in the README.")
$(call echo_yellow,"Your Deis cluster is ready to go! Follow the README to login and use Deis.")

status: check-fleet
fleetctl --strict-host-key-checking=false list-units

stop: check-fleet
fleetctl --strict-host-key-checking=false stop $(ALL_UNITS)

uninstall: check-fleet stop
fleetctl --strict-host-key-checking=false destroy $(ALL_UNITS)
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ Trying out Deis? Continue following these instructions for a local cluster setup
## 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 fleetctl client: Install v0.2.0 from the [fleet GitHub page](https://github.com/coreos/fleet/releases).
* Install the Docker client if you want to run Docker commands locally (optional)

## Additional setup for a multi-node cluster
Expand Down
6 changes: 3 additions & 3 deletions builder/systemd/deis-builder.service
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
[Unit]
Description=deis-builder
Requires=deis-registry.service
After=deis-registry.service

[Service]
TimeoutStartSec=20m
Expand All @@ -13,5 +11,7 @@ ExecStop=/usr/bin/docker rm -f deis-builder
[Install]
WantedBy=multi-user.target

# We only need this so that when we start controller, it's guaranteed to be scheduled
# (If logger and builder are on separate machines, controller can never be scheduled)
[X-Fleet]
X-ConditionMachineOf=deis-controller.service
X-ConditionMachineOf=deis-logger.service
6 changes: 2 additions & 4 deletions contrib/ec2/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ Please wait for it to come up, then run ./initialize-ec2-cluster.sh

## Initialize the cluster
Once the cluster is up, get the hostname of any of the machines from EC2, set
FLEETCTL_TUNNEL, then run [the init script][init-script] to bootstrap the cluster
remotely:
FLEETCTL_TUNNEL, and issue a `make run` from the project root:
```console
$ ssh-add ~/.ssh/id_rsa
$ export FLEETCTL_TUNNEL=ec2-12-345-678-90.us-west-1.compute.amazonaws.com
$ ./initialize-ec2-cluster.sh
$ cd ../.. && make run
The authenticity of host '54.215.248.50:22' can't be established.
RSA key fingerprint is 86:10:74:b9:6a:ee:3b:21:d0:0f:b4:63:cc:10:64:c9.
Are you sure you want to continue connecting (yes/no)? yes
Expand Down Expand Up @@ -92,4 +91,3 @@ email: [email protected]
[template]: https://s3.amazonaws.com/coreos.com/dist/aws/coreos-alpha.template
[cf-params]: cloudformation.json
[pro-script]: provision-ec2-cluster.sh
[init-script]: initialize-ec2-cluster.sh
40 changes: 0 additions & 40 deletions contrib/ec2/initialize-ec2-cluster.sh

This file was deleted.

7 changes: 3 additions & 4 deletions contrib/rackspace/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,11 @@ $ DEIS_NUM_INSTANCES=5 ./provision-rackspace-cluster.sh deis-key
```

### Initialize the cluster
Once the cluster is up, get the IP address for any of the machines in the cluster, set
FLEETCTL_TUNNEL, and run [the init script](initialize-rackspace-cluster.sh) to bootstrap the cluster
remotely:
Once the cluster is up, get the hostname of any of the machines from EC2, set
FLEETCTL_TUNNEL, and issue a `make run` from the project root:
```console
$ export FLEETCTL_TUNNEL=23.253.219.94
$ ./initialize-rackspace-cluster.sh
$ cd ../.. && make run
The authenticity of host '23.253.219.94:22' can't be established.
RSA key fingerprint is ce:3a:c1:3a:ad:11:bd:60:84:8e:60:a8:2f:19:1a:a6.
Are you sure you want to continue connecting (yes/no)? yes
Expand Down
40 changes: 0 additions & 40 deletions contrib/rackspace/initialize-rackspace-cluster.sh

This file was deleted.

2 changes: 1 addition & 1 deletion contrib/rackspace/provision-rackspace-cluster.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ fi

i=1 ; while [[ $i -le $DEIS_NUM_INSTANCES ]] ; do \
echo_yellow "Provisioning deis-$i..."
supernova production boot --image 6bdbd558-e66c-49cc-9ff3-126e7411f602 --flavor $FLAVOR --key-name $1 --user-data ../coreos/user-data --config-drive true deis-$i ; \
supernova production boot --image c431c19c-4c09-48ef-a7c1-f4a43f65a1de --flavor $FLAVOR --key-name $1 --user-data ../coreos/user-data --config-drive true deis-$i ; \
((i = i + 1)) ; \
done

Expand Down
1 change: 1 addition & 0 deletions controller/systemd/deis-controller.service
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,4 @@ WantedBy=multi-user.target

[X-Fleet]
X-ConditionMachineOf=deis-logger.service
X-ConditionMachineOf=deis-builder.service

0 comments on commit 787d857

Please sign in to comment.