Skip to content

Commit

Permalink
initial files
Browse files Browse the repository at this point in the history
  • Loading branch information
Stuart Fenton committed Oct 23, 2015
0 parents commit 1432881
Show file tree
Hide file tree
Showing 8 changed files with 218 additions and 0 deletions.
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
The MIT License (MIT)

Copyright (c) 2015 wercker

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# wercker-kubernetes-quay

Example repo that pushes Docker containers to quay.io from wercker using the internal/docker-push step
23 changes: 23 additions & 0 deletions cities-service.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"kind": "Service",
"apiVersion": "v1beta3",
"metadata": {
"name": "cities",
"labels": {
"name": "cities"
}
},
"spec":{
"createExternalLoadBalancer": true,
"ports": [
{
"port": 5000,
"targetPort": "http-server",
"protocol": "TCP"
}
],
"selector":{
"name":"cities"
}
}
}
44 changes: 44 additions & 0 deletions create_cities-controller.json.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/bin/bash

cat > cities-controller.json <<EOF
{
"kind": "ReplicationController",
"apiVersion": "v1beta3",
"metadata": {
"name": "cities",
"labels": {
"name": "cities"
}
},
"spec": {
"replicas": 3,
"selector": {
"name": "cities"
},
"template": {
"metadata": {
"labels": {
"name": "cities",
"deployment": "${WERCKER_GIT_COMMIT}"
}
},
"spec": {
"containers": [
{
"imagePullPolicy": "Always",
"image": "quay.io/wercker/wercker-kubernetes-quay:${WERCKER_GIT_COMMIT}",
"name": "cities",
"ports": [
{
"name": "http-server",
"containerPort": 5000,
"protocol": "TCP"
}
]
}
]
}
}
}
}
EOF
46 changes: 46 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package main

import (
"encoding/json"
"log"
"net/http"
)

type CitiesResponse struct {
Cities []string `json:"cities"`
}

func CityHandler(res http.ResponseWriter, req *http.Request) {

citiesResponse := &CitiesResponse{

Cities: []string{
"San Francisco",
"Amsterdam",
"Berlin",
"New York",
"Tokyo",
"Kyoto",
"Osaka",
"Nagasaki",
"Naha",
"London",
"Paris",
"Seoul",
"Austin",
},
}
data, _ := json.MarshalIndent(citiesResponse, "", " ")
res.Header().Set("Content-Type", "application/json; charset=utf-8")
res.Write(data)
}

func main() {
log.Println("Listening on this host: http://localhost:5000")

http.HandleFunc("/cities.json", CityHandler)
err := http.ListenAndServe(":5000", nil)
if err != nil {
log.Fatal("Unable to listen on :5000: ", err)
}
}
18 changes: 18 additions & 0 deletions main_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"net/http"
"net/http/httptest"
"testing"
)

func TestHandleIndexReturnsWithStatusOK(t *testing.T) {
request, _ := http.NewRequest("GET", "/", nil)
response := httptest.NewRecorder()

CityHandler(response, request)

if response.Code != http.StatusOK {
t.Fatalf("Non-expected status code%v:\n\tbody: %v", "200", response.Code)
}
}
Binary file added wercker
Binary file not shown.
62 changes: 62 additions & 0 deletions wercker.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
build:
box: google/golang
steps:

# Test the project
- script:
name: go test
code: go test ./...

# Statically build the project
- script:
name: go build
code: CGO_ENABLED=0 go build -a -ldflags '-s' -installsuffix cgo -o app .

# Create cities-controller.json for initialization
- script:
name: create cities-controller.json
code: ./create_cities-controller.json.sh

# Copy binary to location that gets passed along to deploy
- script:
name: copy binary
code: cp app cities-service.json cities-controller.json "$WERCKER_OUTPUT_DIR"

deploy:
box: google/golang
steps:
# use the scratch step to build a container from scratch based on the files present
- internal/docker-scratch-push:
username: $QUAY_USERNAME
password: $QUAY_PASSWORD
cmd: ./app
tag: $WERCKER_GIT_COMMIT
ports: "5000"
repository: quay.io/wercker/wercker-kubernetes-quay
registry: https://quay.io

# Run this to create the rc and service
initialize:
- kubectl:
server: $KUBERNETES_MASTER
username: $KUBERNETES_USERNAME
password: $KUBERNETES_PASSWORD
insecure-skip-tls-verify: true
command: create -f cities-controller.json

- kubectl:
server: $KUBERNETES_MASTER
username: $KUBERNETES_USERNAME
password: $KUBERNETES_PASSWORD
insecure-skip-tls-verify: true
command: create -f cities-service.json

# Update the replica controller to $WERCKER_GIT_COMMIT
rolling-update:
- kubectl:
server: $KUBERNETES_MASTER
username: $KUBERNETES_USERNAME
password: $KUBERNETES_PASSWORD
insecure-skip-tls-verify: true
command: rolling-update cities
image: quay.io/wercker/wercker-kubernetes-quay:$WERCKER_GIT_COMMIT

0 comments on commit 1432881

Please sign in to comment.