Skip to content

Commit

Permalink
Merge pull request #165 from redspread/versioning
Browse files Browse the repository at this point in the history
Versioning
  • Loading branch information
ethernetdan authored Aug 4, 2016
2 parents a434f0b + 9fbadea commit 382198a
Show file tree
Hide file tree
Showing 99 changed files with 12,858 additions and 123 deletions.
34 changes: 19 additions & 15 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ sudo: required
go:
- 1.6

env: LD_LIBRARY_PATH=/usr/local/lib

go_import_path: rsprd.com/spread

services:
Expand All @@ -11,25 +13,27 @@ services:
install:
# install build dependencies
- make deps
- make install-libgit2

before_script:
- make validate

script:
- make test

after_success:
# If release then crosscompile
- if [ -n "$TRAVIS_TAG" ]; then SPREAD_VERSION=$TRAVIS_TAG make crossbuild; else echo "Skipping release build..."; fi

deploy:
provider: releases
api_key:
secure: Jqzgb1hVOHhXAtzr1CaYtz9Ws8VGbyTP5qdWr9Dobg69hCTQDLg8Yuc/pJBIMtajxiQnrNmcI5ZpSdrPd1mxUKQBxr6ra3A8G/Utnfs8ilO0qDR4/pF+G+dVZlIUT/8iAfvpEiCkEckndrB/fVgR1p3o4R7kceHsjduTy+dX0j1v9jN1FA901o2C6tz3OYGn85q7p0wYXOd6l4WhtRK2EShvcPMG7Hs5Vz9Ihb7cznH1Lxpst2zohXz45O0vzfyFLXJp4RftAvg/1IOl9E4OTIanL9SQckRxfFRI57AAogKdJPYrbm8L7/HxRN96lW5e8EtNZXf77Orc/9NvR4YENRUINDhaCxz+IUTtU2TLt4nyCtHCEGyqFJ4ZnK5+sO4Ha7STiPVLNZSfu6rZPo3l77o0JTLo/IK8QtTrQ6H6JyjN3brle/FoOJTxtbjZ/DZKpR4QweO2zG4sQ8sKS8KuQ4LUx9Gm4ucuI8vsWIUsSMg8mKkCCQzf2z84Ih5FxZEwzXrAH+xVrrmUQlsgF3KflT/78LnJMFhOoxO+CPW2sStxndxh2L8duLOt+Jrf4URUnrjwGyWhebPcTI/gj0wuRUFY3VahkmWAD4r/3A/62s1/mc2vYwT9VLRxtKsA16Ur5ujM4nUVfJG/nYVE07+rqrngd9OCvmM8u5WmFpMqKWc=
skip_cleanup: true
file:
- ./build/spread_linux_amd64
- ./build/spread_darwin_amd64
- ./build/spread_windows_amd64.exe
on:
tags: true
# Disable cross compilation until we get static libgit2 cross compilation working
#after_success:
# # If release then crosscompile
# - if [ -n "$TRAVIS_TAG" ]; then SPREAD_VERSION=$TRAVIS_TAG make crossbuild; else echo "Skipping release build..."; fi
#
#deploy:
# provider: releases
# api_key:
# secure: Jqzgb1hVOHhXAtzr1CaYtz9Ws8VGbyTP5qdWr9Dobg69hCTQDLg8Yuc/pJBIMtajxiQnrNmcI5ZpSdrPd1mxUKQBxr6ra3A8G/Utnfs8ilO0qDR4/pF+G+dVZlIUT/8iAfvpEiCkEckndrB/fVgR1p3o4R7kceHsjduTy+dX0j1v9jN1FA901o2C6tz3OYGn85q7p0wYXOd6l4WhtRK2EShvcPMG7Hs5Vz9Ihb7cznH1Lxpst2zohXz45O0vzfyFLXJp4RftAvg/1IOl9E4OTIanL9SQckRxfFRI57AAogKdJPYrbm8L7/HxRN96lW5e8EtNZXf77Orc/9NvR4YENRUINDhaCxz+IUTtU2TLt4nyCtHCEGyqFJ4ZnK5+sO4Ha7STiPVLNZSfu6rZPo3l77o0JTLo/IK8QtTrQ6H6JyjN3brle/FoOJTxtbjZ/DZKpR4QweO2zG4sQ8sKS8KuQ4LUx9Gm4ucuI8vsWIUsSMg8mKkCCQzf2z84Ih5FxZEwzXrAH+xVrrmUQlsgF3KflT/78LnJMFhOoxO+CPW2sStxndxh2L8duLOt+Jrf4URUnrjwGyWhebPcTI/gj0wuRUFY3VahkmWAD4r/3A/62s1/mc2vYwT9VLRxtKsA16Ur5ujM4nUVfJG/nYVE07+rqrngd9OCvmM8u5WmFpMqKWc=
# skip_cleanup: true
# file:
# - ./build/spread_linux_amd64
# - ./build/spread_darwin_amd64
# - ./build/spread_windows_amd64.exe
# on:
# tags: true
6 changes: 5 additions & 1 deletion Godeps/Godeps.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 43 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
BASE := rsprd.com/spread
DIR := $(GOPATH)/src/$(BASE)
CMD_NAME := spread
PROTO_DIR := proto

EXEC_PKG := $(BASE)/cmd/$(CMD_NAME)
PKGS := ./pkg/... ./cli/... ./cmd/...
Expand All @@ -9,6 +11,8 @@ ifndef SPREAD_VERSION
SPREAD_VERSION := v0.0.0
endif

LIBGIT2_VERSION ?= v0.23.4

GOX_OS ?= linux darwin windows
GOX_ARCH ?= amd64

Expand All @@ -17,19 +21,38 @@ GOX ?= gox
GOFMT ?= gofmt "-s"
GOLINT ?= golint
DOCKER ?= docker
PROTOC := protoc

GOFILES := find . -name '*.go' -not -path "./vendor/*"

VERSION_LDFLAG := -X main.Version=$(SPREAD_VERSION)

GOFILES := find . -name '*.go' -not -path "./vendor/*"
LIBGIT2_DIR := $(DIR)/vendor/libgit2
LIBGIT2_BUILD := $(LIBGIT2_DIR)/build
LIBGIT2_PKGCONFIG := $(LIBGIT2_BUILD)/libgit2.pc

LIBGIT2_CGOFLAG := -I$(LIBGIT2_DIR)/include

# Do not use sudo on OS X
ifneq ($(OS),Windows_NT)
UNAME_S := $(shell uname -s)
ifeq ($(UNAME_S),Darwin)
SUDO :=
else
SUDO := sudo
endif
endif

GOBUILD_LDFLAGS ?= $(VERSION_LDFLAG)
GOBUILD_FLAGS ?= -i -v
GOTEST_FLAGS ?= -v
GOX_FLAGS ?= -output="build/{{.Dir}}_{{.OS}}_{{.Arch}}" -os="${GOX_OS}" -arch="${GOX_ARCH}"
CGO_ENV ?= CGO_CFLAGS="$(LIBGIT2_CGOFLAG)"

STATIC_LDFLAGS ?= -extldflags "-static" --s -w

GITLAB_CONTEXT ?= ./build/gitlab
LIBGIT2_URL ?= https://github.com/libgit2/libgit2/archive/$(LIBGIT2_VERSION).tar.gz

# image data
ORG ?= redspreadapps
Expand Down Expand Up @@ -59,14 +82,19 @@ integration: build
mkdir -p ./build
./test/mattermost-demo.sh

proto: pkg/spreadproto/*.pb.go
pkg/spreadproto/*.pb.go:$(PROTO_DIR)/*.proto
mkdir -p $$(dirname $@)
$(PROTOC) --go_out=plugins=grpc:$$(dirname $@) -I=$(PROTO_DIR) $^

.PHONY: validate
validate: lint checkgofmt vet

.PHONY: build
build: build/spread

build/spread:
$(GO) build $(GOBUILD_FLAGS) -ldflags "$(GOBUILD_LDFLAGS)" -o $@ $(EXEC_PKG)
$(CGO_ENV) $(GO) build $(GOBUILD_FLAGS) -ldflags "$(GOBUILD_LDFLAGS)" -o $@ $(EXEC_PKG)

build/spread-linux-static:
GOOS=linux $(GO) build -o $@ $(GOBUILD_FLAGS) -ldflags "$(GOBUILD_LDFLAGS) $(STATIC_LDFLAGS)" $(EXEC_PKG)
Expand All @@ -83,6 +111,19 @@ build-gitlab: build/spread-linux-static
cp ./build/spread-linux-static $(GITLAB_CONTEXT)
$(DOCKER) build $(DOCKER_OPTS) -t $(GITLAB_IMAGE_NAME) $(GITLAB_CONTEXT)

install-libgit2: build-libgit2
cd $(LIBGIT2_BUILD) && $(SUDO) make install

build-libgit2: $(LIBGIT2_PKGCONFIG)
$(LIBGIT2_PKGCONFIG): vendor/libgit2
./hack/build-libgit2.sh

vendor/libgit2: vendor/libgit2.tar.gz
mkdir -p $@
tar -zxf $< -C $@ --strip-components=1
vendor/libgit2.tar.gz:
curl -L -o $@ $(LIBGIT2_URL)

.PHONY: vet
vet:
$(GO) vet $(PKGS)
Expand Down
93 changes: 53 additions & 40 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

<p align="center"><a href="https://redspread.com">Website</a> | <a href="http://redspread.readme.io">Docs</a> | <a href="http://slackin.redspread.com/">Slack</a> | <a href="mailto:[email protected]">Email</a> | <a href="http://twitter.com/redspread">Twitter</a> | <a href="http://facebook.com/GetRedspread">Facebook</a></p>

#Spread: Docker to Kubernetes in one command
#Spread: Git for Kubernetes

`spread` is a command line tool that makes it easy to version Kubernetes objects (see: [Kit](https://github.com/redspread/kit)), set up a local Kubernetes cluster (see: [localkube](https://github.com/redspread/localkube)), and deploy to Kubernetes clusters in one command. The project's goals are to:
`spread` is a command line tool that makes it easy to version Kubernetes clusters, deploy to Kubernetes clusters in one command, and set up a local Kubernetes cluster (see: [localkube](https://github.com/redspread/localkube)). The project's goals are to:

* Enable rapid iteration with Kubernetes
* Guarantee reproducible Kubernetes deployments
* Be the fastest, simplest way to deploy Docker to production
* Work well for a single developer or an entire team (no more broken bash scripts!)
* Enable collaborative deployment workflows that work well for one person or an entire team

See how we deployed Mattermost (<a href="https://github.com/redspread/kube-mattermost">and you can too!</a>):
See how we versioned the cluster running our (<a href="https://redspread.com">website</a>) (and you can too!):

<p align="center"><img src="http://i.imgur.com/Vohnd3e.gif" alt="logo" width= "800"/></p>
<p align="center"><img src="https://redspread.com/img/terminal.gif" alt="logo" width= "800"/></p>

Spread is under open, active development. New features will be added regularly over the next few months - explore our [roadmap](./roadmap.md) to see what will be built next and send us pull requests for any features you’d like to see added.

Expand All @@ -27,73 +27,84 @@ See our [philosophy](./philosophy.md) for more on our mission and values.

##Installation

Install with `go get`:
Install with `go get` (-d is for download only):

`go get rsprd.com/spread/cmd/spread`
`go get -d rsprd.com/spread/cmd/spread`

Go into the correct directory:

`cd $GOPATH/src/rsprd.com/spread`

If libgit2 is not installed:

`make install-libgit2`

Then:

`make build/spread`

If an error about libraries missing comes up, set up your library path like:

`export LD_LIBRARY_PATH=/usr/local/lib:$ LD_LIBRARY_PATH`

Or, if you prefer using Homebrew (OS X only):

`$ brew tap redspread/spread`
`$ brew install spread`
`$ brew install spread-versioning`

##Quickstart
##Git for Kubernetes

Check out our <a href="https://redspread.readme.io/docs/getting-started">Getting Started Guide</a>.
Spread versions your software environment (i.e. a Kubernetes cluster) like Git versions source code. Because Spread is built on top of libgit2, it takes advantage of Git's interface and functionality. This means after you deploy a Kubernetes object to a cluster, you can version the object by staging, commiting, and pushing it to a Spread repository.

##Localkube
To get started, initialize Spread and set up a local Spread repository:

Spread makes it easy to set up and iterate with [localkube](https://github.com/redspread/localkube), a local Kubernetes cluster streamlined for rapid development.
`spread init`

**Requirements:**
* [Docker](https://docs.docker.com/engine/installation/)
* [docker-machine](https://docs.docker.com/machine/install-machine/)
* [VirtualBox](https://www.virtualbox.org/wiki/Downloads)
Here is our suggested workflow for versioning with Spread:

(Note: For Mac and Windows users, the fastest way to install everything above is [Docker Toolbox](https://www.docker.com/products/docker-toolbox).)
1. Create or edit your Kubernetes objects
2. Deploy your objects to a local or remote Kubernetes cluster (make sure you've [set up your directory](https://github.com/redspread/spread/tree/versioning#faq) correctly): `spread deploy .`
3. Stage an object: `spread add <objectType>/<objectName>`
4. Repeat until all objects have been staged
5. Commit your objects with a message: `spread commit -m "commit message"`
6. Set up your remote repository: `spread remote (add <name> <url> | remove <name> | set-url <name> <url>)`
7. Push your objects to your remote repository: `spread push <remote> <refSpec>`
8. Go ahead and try out the other commands - anything not documented can be accessed using `spread git ...`

**Get started:**
If you find any bugs or have any feature requests for Spread versioning, please file an issue!

1. Create a machine called dev: `docker-machine create --driver virtualbox dev`
2. Start your docker-machine: `docker-machine start dev`
3. Connect to the docker daemon: `eval "$(docker-machine env dev)"`
4. Spin up a local cluster using [localkube](http://github.com/redspread/localkube): `spread cluster start`
5. To stop the cluster: `spread cluster stop`
For more details on Spread commands, [see our docs](https://redspread.readme.io/docs/spread-commands).

**Suggested workflow:**
- `docker build` the image that you want to work with [1]
- Create Kubernetes objects that use the image build above
- Run `spread deploy .` to deploy to cluster [2]
- Iterate on your application, updating image and objects running `spread deploy .` each time you want to deploy changes
- To preview changes, grab the IP of your docker daemon with `docker-machine env <NAME>`and the returned `NodePort`, then put `IP:NodePort` in your browser
- When finished, run `spread cluster stop` to stop localkube
##Spread Deploy Quickstart

[1] `spread` will soon integrate building ([#59](https://github.com/redspread/spread/issues/59))
[2] Since `localkube` shares a Docker daemon with your host, there is no need to push images :)
Check out our <a href="https://redspread.readme.io/docs/getting-started">Getting Started Guide</a>.

##Localkube --> Minikube

[See more](https://github.com/redspread/localkube) for our suggestions when developing code with `localkube`.
Spread made it easy to set up and iterate with [Localkube](https://github.com/redspread/localkube), a local Kubernetes cluster streamlined for rapid development. We have donated Localkube code to [Minikube](https://github.com/kubernetes/minikube), the official Kubernetes local development solution. It's easy to set up a local cluster with Minikube: https://github.com/kubernetes/minikube.

##What's been done so far

* Spread versioning
* `spread deploy [-s] PATH [kubectl context]`: Deploys a Docker project to a Kubernetes cluster. It completes the following order of operations:
* Reads context of directory and builds Kubernetes deployment hierarchy.
* Updates all Kubernetes objects on a Kubernetes cluster.
* Returns a public IP address, if type Load Balancer is specified.
* Established an implicit hierarchy of Kubernetes objects
* Multi-container deployment
* Support for Linux and Windows
* [localkube](https://github.com/redspread/localkube): easy-to-setup local Kubernetes cluster for rapid development
* [Initial tutorial](https://redspread.readme.io/v0.1.6/docs/spread-templating-and-tutorials) for templating and parameterization

##What's being worked on now

* Version control for Kubernetes objects
* Template authoring
* Secret management with Spread versioning
* Inner-app linking
* [Redspread](redspread.com) (hosted Spread repository)

See more of our <a href="https://github.com/redspread/spread/blob/master/roadmap.md">roadmap</a> here!

##Future Goals
* Peer-to-peer syncing between local and remote Kubernetes clusters
* Develop workflow for application and deployment versioning
* Introduce paramaterization for container configuration
* Automatically spin up local and remote Kubernetes clusters with minimal user input

##FAQ

Expand All @@ -118,6 +129,8 @@ rs
service.yaml
secret.yaml
```

**Why version objects instead of just files?** The object is the deterministic representation of state in Kubernetes. A useful analogy is "Kubernetes objects" are to "Docker images" like "Kubernetes object files" are to "Dockerfiles". By versioning the object itself, we can guarantee a 1:1 mapping with the Kubernetes cluster. This allows us to do things like diff two clusters and introduces future potential for linking between objects and repositories.

##Contributing

Expand Down
Loading

0 comments on commit 382198a

Please sign in to comment.