Skip to content
This repository has been archived by the owner on Aug 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #8 from pantheon-systems/vet
Browse files Browse the repository at this point in the history
cleans up some code per vet rules, adds the common makefile subtree, removes kube deploy.
  • Loading branch information
spheromak committed Jul 19, 2016
2 parents ddd03b6 + 229a581 commit 33f4f54
Show file tree
Hide file tree
Showing 28 changed files with 753 additions and 225 deletions.
8 changes: 2 additions & 6 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
FROM alpine
FROM scratch
ADD ca-certificates.crt /etc/ssl/certs/


COPY baryon /
COPY deploy/baryon.sh /baryon.sh
RUN chmod 755 /baryon.sh /baryon

EXPOSE 8888
ENTRYPOINT exec /baryon.sh
ENTRYPOINT ["/baryon", "-p 8888"]
106 changes: 25 additions & 81 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,85 +1,29 @@
GO15VENDOREXPERIMENT=1
APP=baryon
FETCH_CA_CERT=true

all: deps test build
include scripts/make/common.mk
include scripts/make/common-go.mk
include scripts/make/common-docker.mk

list:
@make -rqp | awk -F':' '/^[a-zA-Z0-9][^$$#\/\t=]*:([^=]|$$)/ {split($$1,A,/ /);for(i in A)print A[i]}' | sort | uniq

deps: gvt_install
gvt rebuild

test:
go test

cov:
go get github.com/pierrre/gotestcover
go get github.com/mattn/goveralls
gotestcover -coverprofile=coverage.out $$(go list ./... | grep -v /vendor/)

coveralls: cov
goveralls -repotoken $$COVERALLS_TOKEN -service=circleci -coverprofile=coverage.out

cov_html: cov
go tool cover -html=coverage.out

build:
go build

build_linux:
GOOS=linux go build

deploy:
kubectl rolling-update $(APP) --poll-interval="500ms" --image=gcr.io/$(GOOGLE_PROJECT)/$(APP)

force_pod_restart:
kubectl get pod -l"app=baryon" --no-headers | awk '{print $$1}' | xargs kubectl delete pod

cert:
curl https://raw.githubusercontent.com/bagder/ca-bundle/master/ca-bundle.crt -o ca-certificates.crt

circle_deps:
bash deploy/gce/gcloud-setup.sh
bash deploy/install-go.sh

update_secrets:
kubectl replace -f deploy/gce/baryon-ssl.yml
kubectl replace -f deploy/gce/baryon-secrets.yml

update_rc:
kubectl get rc/baryon && kubectl replace -f deploy/gce/baryon-rc.yml || kubectl create -f deploy/gce/baryon-rc.yml

release_deps:
go get github.com/aktau/github-release
go get -u github.com/pantheon-systems/autotag

release: release_deps
release: TAG=$(shell autotag -n)
release: _deps-release ## run a release (usually from CI)
release: VERSION=$(shell autotag -n)
release:
@echo "Building release for $(TAG)"
autotag
GOOS=linux go build -o baryon-linux
GOOS=darwin go build -o baryon-darwin
GOOS=windows go build
github-release release -u pantheon-systems -r baryon -t $(TAG) --draft
github-release upload -u pantheon-systems -r baryon -n Linux -f baryon-linux -t $(TAG)
github-release upload -u pantheon-systems -r baryon -n OSX -f baryon-darwin -t $(TAG)
github-release upload -u pantheon-systems -r baryon -n Windows -f baryon.exe -t $(TAG)


refresh_deps: gvt_install
bash deploy/refresh.sh

gvt_install:
go get -u github.com/FiloSottile/gvt

# gce task builds the docker container, and pushes it to gce container repo.
# no reason this can't be quay.io
# We pull down root certs, cause the docker image doesn't have them.
gce: docker
gcloud docker push gcr.io/$(GOOGLE_PROJECT)/$(APP)

docker: cert build_linux
docker build -t gcr.io/$(GOOGLE_PROJECT)/$(APP) .

.PHONY: all
@echo "Building release for $(VERSION)"
CIRCLE_BUILD_NUM=$(VERSION) make push-circle
autotag
GOOS=linux go build -o baryon-linux
GOOS=darwin go build -o baryon-darwin
GOOS=windows go build
github-release release -u pantheon-systems -r baryon -t $(VERSION) --draft
github-release upload -u pantheon-systems -r baryon -n Linux -f baryon-linux -t $(VERSION)
github-release upload -u pantheon-systems -r baryon -n OSX -f baryon-darwin -t $(VERSION)
github-release upload -u pantheon-systems -r baryon -n Windows -f baryon.exe -t $(VERSION)

_deps-release: # install tools needed for release, conditionally
ifneq ("$(wildcard Dockerfile))","")
go get github.com/aktau/github-release
endif
ifeq ($(shell which autotag)),)
curl -L https://github.com/pantheon-systems/autotag/releases/download/v0.0.4/autotag.linux.x86_64 -o ~/bin/autotag
chmod 755 ~/bin/autotag
endif
45 changes: 30 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[![Circle CI](https://circleci.com/gh/pantheon-systems/baryon/tree/master.svg?style=svg&circle-token=92ed13ff052f213b007977e8ef356831b9c63e0d)](https://circleci.com/gh/pantheon-systems/baryon/tree/master)
[![Coverage Status](https://coveralls.io/repos/github/pantheon-systems/baryon/badge.svg?branch=master)](https://coveralls.io/github/pantheon-systems/baryon?branch=master)
[![Circle CI](https://circleci.com/gh/pantheon-systems/baryon/tree/master.svg?style=svg&circle-token=92ed13ff052f213b007977e8ef356831b9c63e0d)](https://circleci.com/gh/pantheon-systems/baryon/tree/master) [![Coverage Status](https://coveralls.io/repos/github/pantheon-systems/baryon/badge.svg?branch=master)](https://coveralls.io/github/pantheon-systems/baryon?branch=master)

Baryon
-----
------

Chef cookbook compositor (aka universe endpoint)

This is an implementation of the Chef Universe server API that layers and combines multiple universe sources like the Chef Supermarket and GitHub organizations.
Expand All @@ -12,23 +12,30 @@ By default Baryon makes use of GitHub releases (tags) as the primary source for
A GitHub web-hook endpoint for processing cookbook version data (typically automatic tagging during continuous integration) as well as polling GitHub repositories on a sync interval is provided.

Features:
* Exclusive Merge of sources (Github org before supermarket universe)
* GitHub hook Universe updates
* understands tags beyond /^v\d.\d.\d/
* Efficient usage of GitHub API
* TLS support
* Stable

## Getting Started

- Exclusive Merge of sources (Github org before supermarket universe)
- GitHub hook Universe updates
- understands tags beyond /^v\d.\d.\d/
- Efficient usage of GitHub API
- TLS support
- Stable

Getting Started
---------------

Download a release for your architecture, and run it.

## How to use
The most simple setup is to just `./baryon -p 80 -o mygithuborg -t mytoken -s hooksecret` this starts a server that will listen on port 80, and index 'mygithuborg' using your GitHub token and waiting for GitHub hook payloads with 'hooksecret' as GitHub's auth request to baryon.
How to use
----------

The most simple setup is to just `./baryon -p 80 -o mygithuborg -t mytoken -s hooksecret` this starts a server that will listen on port 80, and index 'mygithuborg' using your GitHub token and waiting for GitHub hook payloads with 'hooksecret' as GitHub's auth request to baryon.

### Github Repo Permissions

The token you use for baryon needs to have access to private repositories if you expect it to index private cookbooks. It only needs to read from repositories however.

### Command Switches

```
./baryon --help
Usage:
Expand All @@ -51,17 +58,25 @@ Help Options:
-h, --help Show this help message
```

## Build from source
Build from source
-----------------

This project is using the Go 1.5 vendor experiment to manage dependencies. Fetch the repo source per normal with go get:

```Shell
go get github.com/pantheon-systems/baryon
```

#### Vendored Deps

Then run `make` in the source directory. Make will 'go get' gvt, which is used to manage vendoring dependencies into the `./vendor` directory, and build from source

```Shell
cd $GOPATH/src/github.com/pantheon-systems/baryon && make
```

## Contributing
Contributing
------------

See the [CONTRIBUTING.md](CONTRIBUTING.md) documentation
========================================================
32 changes: 16 additions & 16 deletions circle.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,32 @@
---
machine:
environment:
CLOUDSDK_COMPUTE_ZONE: us-central1-b
CLOUDSDK_CORE_DISABLE_PROMPTS: 1
CLOUDSDK_PYTHON_SITEPACKAGES: 0
GO15VENDOREXPERIMENT: 1
PATH: /home/ubuntu/google-cloud-sdk/bin:/home/ubuntu/go1.5/bin:$PATH
GOROOT: /home/ubuntu/go1.5

GOVERSION: 1.6.2
GOPATH: /home/ubuntu/go_workspace
GOROOT: /home/ubuntu/go
PATH: /home/ubuntu/go/bin:$GOPATH/bin:/home/ubuntu/bin:$PATH
python:
version: 2.7.3
services:
- docker

dependencies:
cache_directories:
- ~/google-cloud-sdk
- ~/go1.5
- ../go-workspace
- ../go
- vendor
- ~/bin

pre:
- make circle_deps
override:
- make deps-circle
- make deps
- make deps-coverage

test:
override:
- make test
post:
## set COVERALLS_TOKEN environment variable on circleci.com
- make coveralls
- make test-coveralls

general:
artifacts:
Expand All @@ -34,7 +36,5 @@ deployment:
prod:
branch:
- master
- deploy
commands:
- make gce
- make deploy
- make release
52 changes: 52 additions & 0 deletions common-go.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
build:: ## build project for current arch
go build

build-linux:: _fetch-cert ## build project for linux
GOOS=linux CGO_ENABLED=0 go build -ldflags="-s -w"

# if there is a docker file then set the docker variable so things can trigger off it
build-docker:: ## build the docker container if the dockerfile exists
ifeq ("$(wildcard $(CURDIR)/Dockerfile)","")
$(error "Docker task called, but no DOCKER variable set. Eitehr Dockerfile is missing or you didn't include common.")
else
docker build -t $(IMAGE) .
endif

build-circle:: build-linux ## build project for linux. If you need docker you will have to invoke that with an extension

deps:: _gvt-install ## install dependencies for project assumes you have go binary installed
find ./vendor/* -maxdepth 0 -type d -exec rm -rf "{}" \;
gvt rebuild

test:: ## run go tests
go test -race -v $$(go list ./... | grep -v /vendor/)

test-circle:: test test-coveralls ## invoke test tasks for CI

deps-circle:: ## install Golang and pull dependencies in CI
bash scripts/make/sh/install-go.sh

deps-coverage::
go get github.com/pierrre/gotestcover
go get github.com/mattn/goveralls

deps-status:: ## check status of deps with gostatus
ifeq (, $(shell which gostatus))
go get -u github.com/shurcooL/gostatus
endif
go list -f '{{join .Deps "\n"}}' . | gostatus -stdin -v

test-coveralls:: deps-coverage ## run coverage and report to coveralls
gotestcover -v -race -coverprofile=coverage.out $$(go list ./... | grep -v /vendor/)
goveralls -repotoken $$COVERALLS_TOKEN -service=circleci -coverprofile=coverage.out

test-coverage-html:: deps-coverage ## output html coverage file
go tool cover -html=coverage.html

_gvt-install::
go get -u github.com/FiloSottile/gvt

_fetch-cert::
ifdef $(FETCH_CA_CERT)
curl https://curl.haxx.se/ca/cacert.pem -o ca-certificates.crt
endif
51 changes: 51 additions & 0 deletions common-kube.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
REGISTRY ?= quay.io/getpantheon

# determinse the docker tag to build
ifeq ($(CIRCLE_BUILD_NUM),)
BUILD_NUM := dev
else
BUILD_NUM := $(CIRCLE_BUILD_NUM)
QUAY := docker login -p "$$QUAY_PASSWD" -u "$$QUAY_USER" -e "unused@unused" quay.io
endif

# If we have no circle branch, use development kube env
# If we are on master branch, use production kube env
# If we are NOT on master use testing kube env
ifeq ($(CIRCLE_BRANCH),) # Dev
KUBE_ENV := development
else ifeq ($(CIRCLE_BRANCH), master) # prod
KUBE_ENV := production
else # testing
KUBE_ENV := testing
endif

# These can be overridden
IMAGE ?= $(REGISTRY)/$(APP):$(BUILD_NUM)
SERVCE ?= $(APP)

# debatable weather this should be in common or not, but I see it needed enough in dev.
# TODO(jesse): possibly guard this to prevent accidentally nuking production.
force-pod-restart:: ## nuke the pod
kubectl --namespace=$(KUBE_ENV) get pod -l"app=$(APP)" --no-headers | awk '{print $$1}' | xargs kubectl delete pod

push:: ## push the container to the registry
docker push $(IMAGE)

setup-quay:: ## setup docker login for quay.io
ifndef $(QUAY_PASSWD)
$(error "Need to set QUAY_PASSWD environment variable")
endif
ifndef $(QUAY_USER)
$(error "Need to set QUAY_USER environment variable")
endif
$(QUAY)

# we call make here to ensure new states are detected
push-circle:: ## build and push the container from circle
make build-docker
psuh-circle:: setup-quay
make push

# extend or define circle deps to install gcloud
deps-circle::
@bash scripts/make/sh/install-gcloud.sh
12 changes: 12 additions & 0 deletions common.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# common make tasks and variables that should be imported into all projects
#
#-------------------------------------------------------------------------------

help: ## print list of tasks and descriptions
@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | sort | awk 'BEGIN {FS = ":.*?##"}; { split($$0,a,":"); printf "\033[36m%-30s\033[0m %s \n", a[2], $$2}'
.DEFAULT_GOAL := help

update-makefiles: ## update the make subtree, assumes the subtree is in scripts/make
git subtree pull --prefix scripts/make common_makefiles master --squash

.PHONY: all
Loading

0 comments on commit 33f4f54

Please sign in to comment.