├── .rancher-pipeline.yml ├── Dockerfile ├── README.md ├── deployment.yaml ├── main.go └── main_test.go /.rancher-pipeline.yml: -------------------------------------------------------------------------------- 1 | stages: 2 | - name: Build 3 | steps: 4 | - runScriptConfig: 5 | image: golang:1.11 6 | shellScript: |- 7 | mkdir -p /go/src/github.com/rancher 8 | ln -s `pwd` /go/src/github.com/rancher/pipeline-example-go 9 | cd /go/src/github.com/rancher/pipeline-example-go 10 | go build -o bin/hello-server 11 | go test -cover 12 | - name: Publish 13 | steps: 14 | - publishImageConfig: 15 | dockerfilePath: ./Dockerfile 16 | buildContext: . 17 | tag: go-server:${CICD_EXECUTION_SEQUENCE} 18 | - name: Deploy 19 | steps: 20 | - applyYamlConfig: 21 | path: ./deployment.yaml -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM golang:1.11 2 | EXPOSE 80 3 | COPY ./bin/hello-server /usr/local/bin/ 4 | ENV GOKUBE v55 5 | CMD ["hello-server"] 6 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # pipeline-example-go 2 | 3 | This is a sample golang project to demonstrate the integration with rancher pipeline. 4 | 5 | ## Building 6 | 7 | `go build -o ./bin/hello-server` 8 | 9 | ## Running 10 | 11 | `./bin/hello-server` 12 | 13 | # License 14 | 15 | Copyright (c) 2014-2018 [Rancher Labs, Inc.](http://rancher.com) 16 | 17 | Licensed under the Apache License, Version 2.0 (the "License"); 18 | you may not use this file except in compliance with the License. 19 | You may obtain a copy of the License at 20 | 21 | [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0) 22 | 23 | Unless required by applicable law or agreed to in writing, software 24 | distributed under the License is distributed on an "AS IS" BASIS, 25 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 26 | See the License for the specific language governing permissions and 27 | limitations under the License. 28 | 29 | -------------------------------------------------------------------------------- /deployment.yaml: -------------------------------------------------------------------------------- 1 | 2 | --- 3 | apiVersion: apps/v1 4 | kind: Deployment 5 | metadata: 6 | name: go-server 7 | #namespace: go 8 | labels: 9 | app: goapi 10 | spec: 11 | replicas: 3 12 | selector: 13 | matchLabels: 14 | app: goapi 15 | template: 16 | metadata: 17 | labels: 18 | app: goapi 19 | spec: 20 | imagePullSecrets: 21 | - name: pipeline-docker-registry 22 | containers: 23 | - name: goapi 24 | image: ${CICD_IMAGE}:${CICD_EXECUTION_SEQUENCE} 25 | ports: 26 | - containerPort: 80 27 | 28 | --- 29 | kind: Service 30 | apiVersion: v1 31 | metadata: 32 | name: go-service 33 | #namespace: go 34 | spec: 35 | selector: 36 | app: goapi 37 | type: ClusterIP 38 | ports: 39 | - protocol: TCP 40 | port: 80 41 | targetPort: 80 42 | 43 | 44 | --- 45 | apiVersion: extensions/v1beta1 46 | kind: Ingress 47 | metadata: 48 | #namespace: go 49 | name: go-ingress 50 | annotations: 51 | allow.http: "false" 52 | spec: 53 | rules: 54 | - host: go.rancher.dev-ops-ninja.com 55 | http: 56 | paths: 57 | - path: / 58 | backend: 59 | serviceName: go-service 60 | servicePort: 80 61 | -------------------------------------------------------------------------------- /main.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "fmt" 5 | "net/http" 6 | "log" 7 | ) 8 | 9 | const webContent = "dev-ops-ninja:v99" 10 | 11 | func main() { 12 | http.HandleFunc("/", helloHandler) 13 | log.Fatal(http.ListenAndServe(":80", nil)) 14 | } 15 | 16 | func helloHandler(w http.ResponseWriter, r *http.Request) { 17 | fmt.Fprint(w, webContent) 18 | } 19 | -------------------------------------------------------------------------------- /main_test.go: -------------------------------------------------------------------------------- 1 | package main 2 | 3 | import ( 4 | "net/http" 5 | "net/http/httptest" 6 | "testing" 7 | ) 8 | 9 | 10 | func TestHelloHandler(t *testing.T) { 11 | r, _ := http.NewRequest("GET", "/", nil) 12 | w := httptest.NewRecorder() 13 | 14 | helloHandler(w,r) 15 | 16 | if status := w.Code; status != http.StatusOK { 17 | t.Fatalf("handler returned wrong status code: got %v want %v", 18 | status, http.StatusOK) 19 | } 20 | if b := w.Body.String(); b!= webContent { 21 | t.Fatalf("body = %s, want no", b) 22 | } 23 | } 24 | --------------------------------------------------------------------------------