Skip to content

Commit 2c49e07

Browse files
Build, test, and CLI environment for OpenShift 3
1 parent e0a5699 commit 2c49e07

21 files changed

+1214
-0
lines changed

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/output
2+
/pkg/version/autogenerated.go
3+
/third_party/pkg

README.md

+63
Original file line numberDiff line numberDiff line change
@@ -1 +1,64 @@
11
OpenShift Origin 3.0
2+
====================
3+
4+
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.
5+
6+
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.
7+
8+
NOTE: This is a very early prototype, and as such is designed for rapid iteration around core concepts.
9+
10+
Getting Started
11+
---------------
12+
13+
You'll need Docker and the Go language compilation tools installed.
14+
15+
1. [Install Docker](https://docs.docker.com/installation/#installation)
16+
2. [Install the Go language toolkit](http://golang.org/doc/install) and set your GOPATH
17+
3. Clone this git repository through the Go tools:
18+
19+
$ go get github.com/openshift/origin
20+
$ cd $GOPATH/src/github.com/openshift/origin
21+
22+
4. Run a build
23+
24+
$ go get github.com/coreos/etcd
25+
$ hack/build-go.sh
26+
27+
5. Start an OpenShift all-in-one server (includes everything you need to try OpenShift)
28+
29+
$ output/go/bin/openshift start
30+
31+
6. In another terminal window, switch to the directory:
32+
33+
$ cd $GOPATH/src/github.com/openshift/origin
34+
$ output/go/bin/openshift kube create services -c examples/test-service.json
35+
36+
Coming soon: Vagrant environments supporting OpenShift - see [Kubernetes README.md](https://github.com/GoogleCloudPlatform/kubernetes/blob/master/README.md) for now.
37+
38+
API
39+
---
40+
41+
The OpenShift APIs are exposed at `http://localhost:8081/osapi/v1beta1/*`.
42+
43+
* `http://localhost:8080/api/v1beta1/services` (stub)
44+
45+
The Kubernetes APIs are exposed at `http://localhost:8080/api/v1beta1/*`:
46+
47+
* `http://localhost:8080/api/v1beta1/pods`
48+
* `http://localhost:8080/api/v1beta1/services`
49+
* `http://localhost:8080/api/v1beta1/replicationControllers`
50+
* `http://localhost:8080/api/v1beta1/operations`
51+
52+
An draft of the proposed API is available [in this repository](https://rawgit.com/csrwng/oo-api-v3/master/oov3.html). Expect significant changes.
53+
54+
55+
Contributing
56+
------------
57+
58+
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).
59+
60+
61+
License
62+
-------
63+
64+
OpenShift is licensed under the Apache Software License 2.0.

cmd/apiserver/apiserver.go

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package main
2+
3+
import (
4+
"log"
5+
"net/http"
6+
"time"
7+
8+
"github.com/GoogleCloudPlatform/kubernetes/pkg/apiserver"
9+
"github.com/openshift/origin/pkg/api"
10+
"github.com/openshift/origin/pkg/service"
11+
)
12+
13+
func main() {
14+
storage := map[string]apiserver.RESTStorage{
15+
"services": service.NewRESTStorage(service.MakeMemoryRegistry()),
16+
}
17+
18+
s := &http.Server{
19+
Addr: "127.0.0.1:8081",
20+
Handler: apiserver.New(storage, api.Codec, "/osapi/v1beta1"),
21+
ReadTimeout: 10 * time.Second,
22+
WriteTimeout: 10 * time.Second,
23+
MaxHeaderBytes: 1 << 20,
24+
}
25+
log.Fatal(s.ListenAndServe())
26+
}

cmd/openshift/openshift.go

+62
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
7+
kubeversion "github.com/GoogleCloudPlatform/kubernetes/pkg/version"
8+
"github.com/openshift/origin/pkg/cmd/client"
9+
"github.com/openshift/origin/pkg/cmd/master"
10+
"github.com/openshift/origin/pkg/version"
11+
"github.com/spf13/cobra"
12+
)
13+
14+
const longDescription = `
15+
OpenShift for Admins
16+
17+
OpenShift helps you build, deploy, and manage your applications. To start an all-in-one server, run:
18+
19+
$ openshift start &
20+
$ openshift kube create service -c examples/test-service.json
21+
22+
OpenShift is built around Docker and the Kubernetes container orchestration service. You must have
23+
Docker installed on this machine to start your server.
24+
25+
Note: This is an alpha release of OpenShift and will change significantly. See
26+
27+
https://github.com/openshift/origin
28+
29+
for the latest information on OpenShift.
30+
31+
`
32+
33+
func main() {
34+
openshiftCmd := &cobra.Command{
35+
Use: "openshift",
36+
Short: "OpenShift helps you build, deploy, and manage your applications",
37+
Long: longDescription,
38+
Run: func(c *cobra.Command, args []string) {
39+
c.Help()
40+
},
41+
}
42+
43+
openshiftCmd.AddCommand(master.NewCommandStartAllInOne("start"))
44+
openshiftCmd.AddCommand(client.NewCommandKubecfg("kube"))
45+
46+
// version information
47+
versionCmd := &cobra.Command{
48+
Use: "version",
49+
Short: "Display version",
50+
Run: func(c *cobra.Command, args []string) {
51+
major, minor, git := version.Get()
52+
fmt.Printf("openshift version %s.%s, build %s\n", major, minor, git)
53+
fmt.Printf("kubernetes %v\n", kubeversion.Get())
54+
},
55+
}
56+
openshiftCmd.AddCommand(versionCmd)
57+
58+
if err := openshiftCmd.Execute(); err != nil {
59+
fmt.Fprintf(os.Stderr, "Error: %s", err)
60+
os.Exit(1)
61+
}
62+
}

doc.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// This is the source repository for OpenShift Origin - the best way to build, manage, and deploy
2+
// applications in the cloud. The OpenShift 3.0 codebase is based around Docker images and containers
3+
// and the Kubernetes container management system.
4+
package origin

examples/test-service.json

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
{
2+
"id": "frontend",
3+
"kind": "Service",
4+
"apiVersion": "v1beta1",
5+
"port": 9998,
6+
"selector": {
7+
"name": "frontend"
8+
}
9+
}

hack/build-go.sh

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#!/bin/bash
2+
3+
# This script sets up a go workspace locally and builds all go components.
4+
5+
set -e
6+
7+
# Update the version.
8+
$(dirname $0)/version-gen.sh
9+
10+
source $(dirname $0)/config-go.sh
11+
12+
cd "${OS_TARGET}"
13+
14+
BINARIES="cmd/openshift"
15+
16+
if [ $# -gt 0 ]; then
17+
BINARIES="$@"
18+
fi
19+
20+
go install $(for b in $BINARIES; do echo "${OS_GO_PACKAGE}"/${b}; done)

hack/config-go.sh

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
#!/bin/bash
2+
3+
# This script sets up a go workspace locally and builds all go components.
4+
# You can 'source' this file if you want to set up GOPATH in your local shell.
5+
6+
if [ "$(which go)" == "" ]; then
7+
echo "Can't find 'go' in PATH, please fix and retry."
8+
echo "See http://golang.org/doc/install for installation instructions."
9+
exit 1
10+
fi
11+
12+
# Travis continuous build uses a head go release that doesn't report
13+
# a version number, so we skip this check on Travis. Its unnecessary
14+
# there anyway.
15+
if [ "${TRAVIS}" != "true" ]; then
16+
GO_VERSION=($(go version))
17+
18+
if [ ${GO_VERSION[2]} \< "go1.2" ]; then
19+
echo "Detected go version: ${GO_VERSION}."
20+
echo "OpenShift requires go version 1.2 or greater."
21+
echo "Please install Go version 1.2 or later"
22+
exit 1
23+
fi
24+
fi
25+
26+
pushd $(dirname "${BASH_SOURCE}")/.. >/dev/null
27+
OS_REPO_ROOT="${PWD}"
28+
OS_TARGET="${OS_REPO_ROOT}/output/go"
29+
popd >/dev/null
30+
31+
mkdir -p "${OS_TARGET}"
32+
33+
OLD_GOPATH="${GOPATH}"
34+
export GOPATH="${OS_TARGET}"
35+
36+
OS_GO_PACKAGE="github.com/openshift/origin"
37+
OS_GO_PACKAGE_DIR="${GOPATH}/src/${OS_GO_PACKAGE}"
38+
39+
ETCD_GO_PACKAGE="github.com/coreos/etcd"
40+
ETCD_GO_PACKAGE_DIR="${GOPATH}/src/${ETCD_GO_PACKAGE}"
41+
if [ ! -d "${OLD_GOPATH}/src/${ETCD_GO_PACKAGE}" ]; then
42+
echo "You must go get ${ETCD_GO_PACKAGE}"
43+
fi
44+
45+
(
46+
PACKAGE_BASE=$(dirname "${OS_GO_PACKAGE_DIR}")
47+
if [ ! -d "${PACKAGE_BASE}" ]; then
48+
mkdir -p "${PACKAGE_BASE}"
49+
fi
50+
rm "${OS_GO_PACKAGE_DIR}" >/dev/null 2>&1 || true
51+
ln -s "${OS_REPO_ROOT}" "${OS_GO_PACKAGE_DIR}"
52+
53+
PACKAGE_BASE=$(dirname "${ETCD_GO_PACKAGE_DIR}")
54+
if [ ! -d "${PACKAGE_BASE}" ]; then
55+
mkdir -p "${PACKAGE_BASE}"
56+
fi
57+
rm "${ETCD_GO_PACKAGE_DIR}" >/dev/null 2>&1 || true
58+
ln -s "${OLD_GOPATH}/src/${ETCD_GO_PACKAGE}" "${ETCD_GO_PACKAGE_DIR}"
59+
60+
61+
if [[ "$OS_KUBE_PATH" != "" ]]; then
62+
echo "Using Kubernetes from source $OS_KUBE_PATH"
63+
OS_GO_KUBE_PACKAGE_DIR="${OS_TARGET}/src/github.com/GoogleCloudPlatform/kubernetes"
64+
KUBE_PACKAGE_BASE=$(dirname "${OS_GO_KUBE_PACKAGE_DIR}")
65+
if [ ! -d "${KUBE_PACKAGE_BASE}" ]; then
66+
mkdir -p "${KUBE_PACKAGE_BASE}"
67+
fi
68+
rm "${OS_GO_KUBE_PACKAGE_DIR}" >/dev/null 2>&1 || true
69+
ln -s "${OS_KUBE_PATH}" "${OS_GO_KUBE_PACKAGE_DIR}"
70+
fi
71+
)
72+
export GOPATH="${OS_TARGET}:${OS_REPO_ROOT}/third_party/src/github.com/GoogleCloudPlatform/kubernetes/third_party:${OS_REPO_ROOT}/third_party"

hack/test-go.sh

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
source $(dirname $0)/config-go.sh
6+
7+
8+
find_test_dirs() {
9+
(
10+
cd src/${OS_GO_PACKAGE}
11+
find . -not \( \
12+
\( \
13+
-wholename './third_party' \
14+
-o -wholename './release' \
15+
-o -wholename './target' \
16+
-o -wholename '*/third_party/*' \
17+
-o -wholename '*/output/*' \
18+
\) -prune \
19+
\) -name '*_test.go' -print0 | xargs -0n1 dirname | sort -u
20+
)
21+
}
22+
23+
# -covermode=atomic becomes default with -race in Go >=1.3
24+
COVER="-cover -covermode=atomic -coverprofile=tmp.out"
25+
26+
cd "${OS_TARGET}"
27+
28+
if [ "$1" != "" ]; then
29+
go test -race -timeout 30s $COVER "$OS_GO_PACKAGE/$1" "${@:2}"
30+
exit 0
31+
fi
32+
33+
for package in $(find_test_dirs); do
34+
go test -race -timeout 30s $COVER "${OS_GO_PACKAGE}/${package}" "${@:2}"
35+
done

hack/version-gen.sh

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#!/bin/bash
2+
3+
$(dirname $0)/../third_party/src/github.com/GoogleCloudPlatform/kubernetes/hack/version-gen.sh
4+
5+
# TODO: when we start making tags, switch to git describe?
6+
desc=$(git rev-list --abbrev-commit --max-count=1 HEAD)
7+
tab=$'\t'
8+
script="6s/.*/${tab}commitFromGit = \`${desc}\`/"
9+
infile="$(dirname $0)/../pkg/version/template.go"
10+
outfile="$(dirname $0)/../pkg/version/autogenerated.go"
11+
sed "${script}" "${infile}" > "${outfile}"

0 commit comments

Comments
 (0)