Skip to content

Commit

Permalink
Build, test, and CLI environment for OpenShift 3
Browse files Browse the repository at this point in the history
  • Loading branch information
smarterclayton committed Aug 8, 2014
1 parent e0a5699 commit 2c49e07
Show file tree
Hide file tree
Showing 21 changed files with 1,214 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/output
/pkg/version/autogenerated.go
/third_party/pkg
63 changes: 63 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,64 @@
OpenShift Origin 3.0
====================

This is the source repository for the next version of OpenShift - the third architectural revision. It is based around [Docker](https://www.docker.io) containers and images and the [Kubernetes](https://github.com/GoogleCloudPlatform/kubernetes) container management solution. OpenShift adds developer centric and organization centric workflows on top of Kubernetes, and much of the core functionality of OpenShift is designed as plugins to the core Kubernetes concepts.

Please see the [OpenShift 3 Project Enhancement Proposal (PEP)](https://github.com/openshift/openshift-pep/blob/master/openshift-pep-013-openshift-3.md) for a deeper discussion of the features you see here.

NOTE: This is a very early prototype, and as such is designed for rapid iteration around core concepts.

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

You'll need Docker and the Go language compilation tools installed.

1. [Install Docker](https://docs.docker.com/installation/#installation)
2. [Install the Go language toolkit](http://golang.org/doc/install) and set your GOPATH
3. Clone this git repository through the Go tools:

$ go get github.com/openshift/origin
$ cd $GOPATH/src/github.com/openshift/origin

4. Run a build

$ go get github.com/coreos/etcd
$ hack/build-go.sh

5. Start an OpenShift all-in-one server (includes everything you need to try OpenShift)

$ output/go/bin/openshift start

6. In another terminal window, switch to the directory:

$ cd $GOPATH/src/github.com/openshift/origin
$ output/go/bin/openshift kube create services -c examples/test-service.json

Coming soon: Vagrant environments supporting OpenShift - see [Kubernetes README.md](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/README.md) for now.

API
---

The OpenShift APIs are exposed at `http://localhost:8081/osapi/v1beta1/*`.

* `http://localhost:8080/api/v1beta1/services` (stub)

The Kubernetes APIs are exposed at `http://localhost:8080/api/v1beta1/*`:

* `http://localhost:8080/api/v1beta1/pods`
* `http://localhost:8080/api/v1beta1/services`
* `http://localhost:8080/api/v1beta1/replicationControllers`
* `http://localhost:8080/api/v1beta1/operations`

An draft of the proposed API is available [in this repository](https://rawgit.com/csrwng/oo-api-v3/master/oov3.html). Expect significant changes.


Contributing
------------

Contributions are welcome - a more formal process is coming soon. In the meantime, open issues as necessary, ask questions on the OpenShift IRC channel (#openshift-dev on freenode), or get involved in the [Kubernetes project](https://github.com/GoogleCloudPlatform/kubernetes).


License
-------

OpenShift is licensed under the Apache Software License 2.0.
26 changes: 26 additions & 0 deletions cmd/apiserver/apiserver.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package main

import (
"log"
"net/http"
"time"

"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
"github.com/openshift/origin/pkg/api"
"github.com/openshift/origin/pkg/service"
)

func main() {
storage := map[string]apiserver.RESTStorage{
"services": service.NewRESTStorage(service.MakeMemoryRegistry()),
}

s := &http.Server{
Addr: "127.0.0.1:8081",
Handler: apiserver.New(storage, api.Codec, "/osapi/v1beta1"),
ReadTimeout: 10 * time.Second,
WriteTimeout: 10 * time.Second,
MaxHeaderBytes: 1 << 20,
}
log.Fatal(s.ListenAndServe())
}
62 changes: 62 additions & 0 deletions cmd/openshift/openshift.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package main

import (
"fmt"
"os"

kubeversion "github.com/GoogleCloudPlatform/kubernetes/pkg/version"
"github.com/openshift/origin/pkg/cmd/client"
"github.com/openshift/origin/pkg/cmd/master"
"github.com/openshift/origin/pkg/version"
"github.com/spf13/cobra"
)

const longDescription = `
OpenShift for Admins
OpenShift helps you build, deploy, and manage your applications. To start an all-in-one server, run:
$ openshift start &
$ openshift kube create service -c examples/test-service.json
OpenShift is built around Docker and the Kubernetes container orchestration service. You must have
Docker installed on this machine to start your server.
Note: This is an alpha release of OpenShift and will change significantly. See
https://github.com/openshift/origin
for the latest information on OpenShift.
`

func main() {
openshiftCmd := &cobra.Command{
Use: "openshift",
Short: "OpenShift helps you build, deploy, and manage your applications",
Long: longDescription,
Run: func(c *cobra.Command, args []string) {
c.Help()
},
}

openshiftCmd.AddCommand(master.NewCommandStartAllInOne("start"))
openshiftCmd.AddCommand(client.NewCommandKubecfg("kube"))

// version information
versionCmd := &cobra.Command{
Use: "version",
Short: "Display version",
Run: func(c *cobra.Command, args []string) {
major, minor, git := version.Get()
fmt.Printf("openshift version %s.%s, build %s\n", major, minor, git)
fmt.Printf("kubernetes %v\n", kubeversion.Get())
},
}
openshiftCmd.AddCommand(versionCmd)

if err := openshiftCmd.Execute(); err != nil {
fmt.Fprintf(os.Stderr, "Error: %s", err)
os.Exit(1)
}
}
4 changes: 4 additions & 0 deletions doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
// This is the source repository for OpenShift Origin - the best way to build, manage, and deploy
// applications in the cloud. The OpenShift 3.0 codebase is based around Docker images and containers
// and the Kubernetes container management system.
package origin
9 changes: 9 additions & 0 deletions examples/test-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"id": "frontend",
"kind": "Service",
"apiVersion": "v1beta1",
"port": 9998,
"selector": {
"name": "frontend"
}
}
20 changes: 20 additions & 0 deletions hack/build-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#!/bin/bash

# This script sets up a go workspace locally and builds all go components.

set -e

# Update the version.
$(dirname $0)/version-gen.sh

source $(dirname $0)/config-go.sh

cd "${OS_TARGET}"

BINARIES="cmd/openshift"

if [ $# -gt 0 ]; then
BINARIES="$@"
fi

go install $(for b in $BINARIES; do echo "${OS_GO_PACKAGE}"/${b}; done)
72 changes: 72 additions & 0 deletions hack/config-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

# This script sets up a go workspace locally and builds all go components.
# You can 'source' this file if you want to set up GOPATH in your local shell.

if [ "$(which go)" == "" ]; then
echo "Can't find 'go' in PATH, please fix and retry."
echo "See http://golang.org/doc/install for installation instructions."
exit 1
fi

# Travis continuous build uses a head go release that doesn't report
# a version number, so we skip this check on Travis. Its unnecessary
# there anyway.
if [ "${TRAVIS}" != "true" ]; then
GO_VERSION=($(go version))

if [ ${GO_VERSION[2]} \< "go1.2" ]; then
echo "Detected go version: ${GO_VERSION}."
echo "OpenShift requires go version 1.2 or greater."
echo "Please install Go version 1.2 or later"
exit 1
fi
fi

pushd $(dirname "${BASH_SOURCE}")/.. >/dev/null
OS_REPO_ROOT="${PWD}"
OS_TARGET="${OS_REPO_ROOT}/output/go"
popd >/dev/null

mkdir -p "${OS_TARGET}"

OLD_GOPATH="${GOPATH}"
export GOPATH="${OS_TARGET}"

OS_GO_PACKAGE="github.com/openshift/origin"
OS_GO_PACKAGE_DIR="${GOPATH}/src/${OS_GO_PACKAGE}"

ETCD_GO_PACKAGE="github.com/coreos/etcd"
ETCD_GO_PACKAGE_DIR="${GOPATH}/src/${ETCD_GO_PACKAGE}"
if [ ! -d "${OLD_GOPATH}/src/${ETCD_GO_PACKAGE}" ]; then
echo "You must go get ${ETCD_GO_PACKAGE}"
fi

(
PACKAGE_BASE=$(dirname "${OS_GO_PACKAGE_DIR}")
if [ ! -d "${PACKAGE_BASE}" ]; then
mkdir -p "${PACKAGE_BASE}"
fi
rm "${OS_GO_PACKAGE_DIR}" >/dev/null 2>&1 || true
ln -s "${OS_REPO_ROOT}" "${OS_GO_PACKAGE_DIR}"

PACKAGE_BASE=$(dirname "${ETCD_GO_PACKAGE_DIR}")
if [ ! -d "${PACKAGE_BASE}" ]; then
mkdir -p "${PACKAGE_BASE}"
fi
rm "${ETCD_GO_PACKAGE_DIR}" >/dev/null 2>&1 || true
ln -s "${OLD_GOPATH}/src/${ETCD_GO_PACKAGE}" "${ETCD_GO_PACKAGE_DIR}"


if [[ "$OS_KUBE_PATH" != "" ]]; then
echo "Using Kubernetes from source $OS_KUBE_PATH"
OS_GO_KUBE_PACKAGE_DIR="${OS_TARGET}/src/github.com/GoogleCloudPlatform/kubernetes"
KUBE_PACKAGE_BASE=$(dirname "${OS_GO_KUBE_PACKAGE_DIR}")
if [ ! -d "${KUBE_PACKAGE_BASE}" ]; then
mkdir -p "${KUBE_PACKAGE_BASE}"
fi
rm "${OS_GO_KUBE_PACKAGE_DIR}" >/dev/null 2>&1 || true
ln -s "${OS_KUBE_PATH}" "${OS_GO_KUBE_PACKAGE_DIR}"
fi
)
export GOPATH="${OS_TARGET}:${OS_REPO_ROOT}/third_party/src/github.com/GoogleCloudPlatform/kubernetes/third_party:${OS_REPO_ROOT}/third_party"
35 changes: 35 additions & 0 deletions hack/test-go.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/bash

set -e

source $(dirname $0)/config-go.sh


find_test_dirs() {
(
cd src/${OS_GO_PACKAGE}
find . -not \( \
\( \
-wholename './third_party' \
-o -wholename './release' \
-o -wholename './target' \
-o -wholename '*/third_party/*' \
-o -wholename '*/output/*' \
\) -prune \
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u
)
}

# -covermode=atomic becomes default with -race in Go >=1.3
COVER="-cover -covermode=atomic -coverprofile=tmp.out"

cd "${OS_TARGET}"

if [ "$1" != "" ]; then
go test -race -timeout 30s $COVER "$OS_GO_PACKAGE/$1" "${@:2}"
exit 0
fi

for package in $(find_test_dirs); do
go test -race -timeout 30s $COVER "${OS_GO_PACKAGE}/${package}" "${@:2}"
done
11 changes: 11 additions & 0 deletions hack/version-gen.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash

$(dirname $0)/../third_party/src/github.com/GoogleCloudPlatform/kubernetes/hack/version-gen.sh

# TODO: when we start making tags, switch to git describe?
desc=$(git rev-list --abbrev-commit --max-count=1 HEAD)
tab=$'\t'
script="6s/.*/${tab}commitFromGit = \`${desc}\`/"
infile="$(dirname $0)/../pkg/version/template.go"
outfile="$(dirname $0)/../pkg/version/autogenerated.go"
sed "${script}" "${infile}" > "${outfile}"
Loading

0 comments on commit 2c49e07

Please sign in to comment.