├── .dockerignore ├── .gitattributes ├── .gitignore ├── .helmignore ├── Dockerfile ├── Jenkinsfile ├── LICENSE ├── Makefile ├── NOTICE ├── OWNERS ├── OWNERS_ALIASES ├── README.md ├── charts ├── croc-hunter-jenkinsx │ ├── .helmignore │ ├── Chart.yaml │ ├── Makefile │ ├── README.md │ ├── templates │ │ ├── NOTES.txt │ │ ├── _helpers.tpl │ │ ├── canary.yaml │ │ ├── deployment.yaml │ │ └── service.yaml │ └── values.yaml └── preview │ ├── Chart.yaml │ ├── Makefile │ ├── requirements.yaml │ └── values.yaml ├── croc-hunter.go ├── curlloop.sh ├── flagger ├── README.md └── croc-hunter-canary.yaml ├── istio ├── README.md ├── gateway.yaml ├── google-api.yaml └── virtualservice.yaml ├── shipper ├── README.md ├── croc-hunter-ingress-global.yaml └── croc-hunter.yaml ├── skaffold.yaml ├── static ├── favicon-16x16.png ├── favicon-32x32.png ├── game.css ├── game.js ├── game2.js ├── sprite.png └── sprite2.png └── watch.sh /.dockerignore: -------------------------------------------------------------------------------- 1 | draft.toml 2 | target/classes 3 | target/generated-sources 4 | target/generated-test-sources 5 | target/maven-archiver 6 | target/maven-status 7 | target/surefire-reports 8 | target/test-classes 9 | target/*.original 10 | charts/ 11 | NOTICE 12 | LICENSE 13 | README.md -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | Makefile linguist-vendored 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .project 2 | .classpath 3 | .idea 4 | .cache 5 | .DS_Store 6 | *.im? 7 | target 8 | work 9 | bin/ -------------------------------------------------------------------------------- /.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | *.png 23 | 24 | # known compile time folders 25 | target/ 26 | node_modules/ 27 | vendor/ -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | ARG GIT_SHA 3 | ARG WORKFLOW_RELEASE 4 | ENV GIT_SHA=$GIT_SHA 5 | ENV WORKFLOW_RELEASE=$WORKFLOW_RELEASE 6 | ENV POWERED_BY=Jenkins-X 7 | EXPOSE 8080 8 | ENTRYPOINT ["/croc-hunter-jenkinsx"] 9 | COPY ./bin/ / 10 | COPY static/ static/ 11 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | pipeline { 2 | agent any 3 | environment { 4 | ORG = 'carlossg' 5 | APP_NAME = 'croc-hunter-jenkinsx' 6 | GIT_PROVIDER = 'github.com' 7 | CHARTMUSEUM_CREDS = credentials('jenkins-x-chartmuseum') 8 | SKAFFOLD_UPDATE_CHECK = 'false' 9 | } 10 | stages { 11 | stage('CI Build and push snapshot') { 12 | when { 13 | branch 'PR-*' 14 | } 15 | environment { 16 | PREVIEW_VERSION = "0.0.0-SNAPSHOT-$BRANCH_NAME-$BUILD_NUMBER" 17 | PREVIEW_NAMESPACE = "$APP_NAME-$BRANCH_NAME".toLowerCase() 18 | HELM_RELEASE = "$PREVIEW_NAMESPACE".toLowerCase() 19 | } 20 | steps { 21 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless') { 22 | checkout scm 23 | sh "make VERSION=\$PREVIEW_VERSION GIT_COMMIT=\$PULL_PULL_SHA linux" 24 | sh 'export VERSION=$PREVIEW_VERSION && skaffold build -f skaffold.yaml.new' 25 | 26 | sh "jx step validate --min-jx-version 1.2.36" 27 | sh "jx step post build --image \$DOCKER_REGISTRY/$ORG/$APP_NAME:$PREVIEW_VERSION" 28 | } 29 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless/charts/preview') { 30 | sh "make preview" 31 | sh "jx preview --app $APP_NAME --dir ../.." 32 | } 33 | } 34 | } 35 | stage('Build Release') { 36 | when { 37 | branch 'master' 38 | } 39 | steps { 40 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless') { 41 | checkout scm 42 | } 43 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless/charts/croc-hunter-jenkinsx') { 44 | // until we switch to the new kubernetes / jenkins credential implementation use git credentials store 45 | sh "git config --global credential.helper store" 46 | sh "jx step validate --min-jx-version 1.1.73" 47 | sh "jx step git credentials" 48 | } 49 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless') { 50 | // so we can retrieve the version in later steps 51 | sh "echo \$(jx-release-version) > VERSION" 52 | } 53 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless/charts/croc-hunter-jenkinsx') { 54 | sh "make tag" 55 | } 56 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless') { 57 | sh "make VERSION=`cat VERSION` GIT_COMMIT=\$PULL_BASE_SHA build" 58 | sh "export VERSION=`cat VERSION` && skaffold build -f skaffold.yaml.new" 59 | sh "jx step validate --min-jx-version 1.2.36" 60 | sh "jx step post build --image $DOCKER_REGISTRY/$ORG/$APP_NAME:\$(cat VERSION)" 61 | } 62 | } 63 | } 64 | stage('Promote to Environments') { 65 | when { 66 | branch 'master' 67 | } 68 | steps { 69 | dir ('/home/jenkins/go/src/github.com/carlossg/croc-hunter-jenkinsx-serverless/charts/croc-hunter-jenkinsx') { 70 | sh 'jx step changelog --version v\$(cat ../../VERSION) --generate-yaml=false' 71 | 72 | // release the helm chart 73 | sh 'make release' 74 | 75 | // promote through all 'Auto' promotion Environments 76 | sh 'jx promote -b --all-auto --timeout 1h --version \$(cat ../../VERSION) --no-wait' 77 | } 78 | } 79 | } 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2016-2018 Lachlan Evenson, Carlos Sanchez 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | SHELL := /bin/bash 2 | GO := GO15VENDOREXPERIMENT=1 go 3 | NAME := croc-hunter-jenkinsx 4 | OS := $(shell uname) 5 | MAIN_GO := croc-hunter.go 6 | ROOT_PACKAGE := $(GIT_PROVIDER)/$(ORG)/$(NAME) 7 | GO_VERSION := $(shell $(GO) version | sed -e 's/^[^0-9.]*\([0-9.]*\).*/\1/') 8 | PACKAGE_DIRS := $(shell $(GO) list ./... | grep -v /vendor/) 9 | PKGS := $(shell go list ./... | grep -v /vendor | grep -v generated) 10 | PKGS := $(subst :,_,$(PKGS)) 11 | BUILDFLAGS := '' 12 | CGO_ENABLED = 0 13 | VENDOR_DIR=vendor 14 | 15 | all: build 16 | 17 | check: fmt build test 18 | 19 | build: skaffold.yaml.new 20 | CGO_ENABLED=$(CGO_ENABLED) $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) 21 | 22 | test: 23 | CGO_ENABLED=$(CGO_ENABLED) $(GO) test $(PACKAGE_DIRS) -test.v 24 | 25 | full: $(PKGS) 26 | 27 | install: 28 | GOBIN=${GOPATH}/bin $(GO) install -ldflags $(BUILDFLAGS) $(MAIN_GO) 29 | 30 | fmt: 31 | @FORMATTED=`$(GO) fmt $(PACKAGE_DIRS)` 32 | @([[ ! -z "$(FORMATTED)" ]] && printf "Fixed unformatted files:\n$(FORMATTED)") || true 33 | 34 | clean: 35 | rm -rf build release 36 | 37 | linux: skaffold.yaml.new 38 | CGO_ENABLED=$(CGO_ENABLED) GOOS=linux GOARCH=amd64 $(GO) build -ldflags $(BUILDFLAGS) -o bin/$(NAME) $(MAIN_GO) 39 | 40 | .PHONY: release clean 41 | 42 | FGT := $(GOPATH)/bin/fgt 43 | $(FGT): 44 | go get github.com/GeertJohan/fgt 45 | 46 | GOLINT := $(GOPATH)/bin/golint 47 | $(GOLINT): 48 | go get github.com/golang/lint/golint 49 | 50 | $(PKGS): $(GOLINT) $(FGT) 51 | @echo "LINTING" 52 | @$(FGT) $(GOLINT) $(GOPATH)/src/$@/*.go 53 | @echo "VETTING" 54 | @go vet -v $@ 55 | @echo "TESTING" 56 | @go test -v $@ 57 | 58 | skaffold.yaml.new: 59 | cp skaffold.yaml skaffold.yaml.new 60 | ifeq ($(OS),Darwin) 61 | sed -i "" -e "s/{{.VERSION}}/x$(VERSION)/" skaffold.yaml.new 62 | sed -i "" -e "s/{{.GIT_COMMIT}}/$(GIT_COMMIT)/" skaffold.yaml.new 63 | else ifeq ($(OS),Linux) 64 | sed -i -e "s/{{.VERSION}}/$(VERSION)/" skaffold.yaml.new 65 | sed -i -e "s/{{.GIT_COMMIT}}/$(GIT_COMMIT)/" skaffold.yaml.new 66 | else 67 | echo "platfrom $(OS) not supported to release from" 68 | exit -1 69 | endif 70 | 71 | 72 | .PHONY: lint 73 | lint: vendor | $(PKGS) $(GOLINT) # ❷ 74 | @cd $(BASE) && ret=0 && for pkg in $(PKGS); do \ 75 | test -z "$$($(GOLINT) $$pkg | tee /dev/stderr)" || ret=1 ; \ 76 | done ; exit $$ret 77 | 78 | watch: 79 | reflex -r "\.go$" -R "vendor.*" make skaffold-run 80 | 81 | skaffold-run: build 82 | skaffold run -p dev 83 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | MIT License: 2 | 3 | Copyright (C) 2011-2015 Heroku, Inc. 4 | 5 | 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: 6 | 7 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 8 | 9 | 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. 10 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | approvers: 2 | - carlossg 3 | reviewers: 4 | - carlossg -------------------------------------------------------------------------------- /OWNERS_ALIASES: -------------------------------------------------------------------------------- 1 | aliases: 2 | - carlossg 3 | best-approvers: 4 | - carlossg 5 | best-reviewers: 6 | - carlossg 7 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Croc Hunter - The game! 2 | 3 | For those that have dreamt to hunt crocs 4 | 5 | # Usage 6 | 7 | Basic go webserver to demonstrate example CI/CD pipeline using Kubernetes 8 | 9 | # Deploy using JenkinsX (Kubernetes, Helm, Monocular, ChartMuseum) 10 | 11 | Just follow the [JenkinsX](http://jenkins-x.io) installation with `--prow=true` 12 | 13 | For example, if using GKE with cert-manager preinstalled for https certificates 14 | 15 | jx install --provider=gke --domain=eu.g.csanchez.org --prow 16 | jx upgrade ingress 17 | 18 | Then fork this repo and [import it](http://jenkins-x.io/developing/import/) 19 | 20 | jx import --url https://github.com/GITHUB_USER/croc-hunter-jenkinsx-serverless --no-draft --pack=go 21 | 22 | Then, any PRs against this repo will be automatically deployed to preview environments. 23 | When they are merged they will be deployed to the `staging` environment. 24 | 25 | To tail all the build logs 26 | 27 | kail -l build.knative.dev/buildName --since=5m 28 | 29 | Or in [GKE StackDriver logs](https://console.cloud.google.com/logs/viewer?authuser=1&advancedFilter=resource.type%3D%22container%22%0Aresource.labels.cluster_name%3D%22samurainarrow%22%0Aresource.labels.container_name%3Dbuild-step-jenkins) 30 | 31 | ``` 32 | resource.type="container" 33 | resource.labels.cluster_name="samurainarrow" 34 | resource.labels.container_name="build-step-jenkins" 35 | ``` 36 | 37 | To [promote from staging to production](http://jenkins-x.io/developing/promote/) just run 38 | 39 | jx promote croc-hunter-jenkinsx --version 0.0.1 --env production 40 | 41 | Then delete the PR environments 42 | 43 | jx delete env 44 | 45 | # Acknowledgements 46 | 47 | Original work by [Lachlan Evenson](https://github.com/lachie83/croc-hunter) 48 | Continuation of the awesome work by everett-toews. 49 | * https://gist.github.com/everett-toews/ed56adcfd525ce65b178d2e5a5eb06aa 50 | 51 | ## Watch Their Demo 52 | 53 | https://www.youtube.com/watch?v=eMOzF_xAm7w 54 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/.helmignore: -------------------------------------------------------------------------------- 1 | # Patterns to ignore when building packages. 2 | # This supports shell glob matching, relative path matching, and 3 | # negation (prefixed with !). Only one pattern per line. 4 | .DS_Store 5 | # Common VCS dirs 6 | .git/ 7 | .gitignore 8 | .bzr/ 9 | .bzrignore 10 | .hg/ 11 | .hgignore 12 | .svn/ 13 | # Common backup files 14 | *.swp 15 | *.bak 16 | *.tmp 17 | *~ 18 | # Various IDEs 19 | .project 20 | .idea/ 21 | *.tmproj 22 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | description: A Helm chart for Kubernetes 3 | icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/d273e09/images/go.png 4 | name: croc-hunter-jenkinsx 5 | version: 0.1.0-SNAPSHOT 6 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/Makefile: -------------------------------------------------------------------------------- 1 | CHART_REPO := http://jenkins-x-chartmuseum:8080 2 | CURRENT=$(pwd) 3 | NAME := croc-hunter-jenkinsx 4 | OS := $(shell uname) 5 | VERSION := $(shell cat ../../VERSION) 6 | 7 | build: clean 8 | rm -rf requirements.lock 9 | helm dependency build 10 | helm lint 11 | 12 | install: clean build 13 | helm install . --name ${NAME} 14 | 15 | upgrade: clean build 16 | helm upgrade ${NAME} . 17 | 18 | delete: 19 | helm delete --purge ${NAME} 20 | 21 | clean: 22 | rm -rf charts 23 | rm -rf ${NAME}*.tgz 24 | 25 | release: clean 26 | helm dependency build 27 | helm lint 28 | helm init --client-only 29 | helm package . 30 | curl --fail -u $(CHARTMUSEUM_CREDS_USR):$(CHARTMUSEUM_CREDS_PSW) --data-binary "@$(NAME)-$(shell sed -n 's/^version: //p' Chart.yaml).tgz" $(CHART_REPO)/api/charts 31 | rm -rf ${NAME}*.tgz% 32 | 33 | tag: 34 | ifeq ($(OS),Darwin) 35 | sed -i "" -e "s/version:.*/version: $(VERSION)/" Chart.yaml 36 | sed -i "" -e "s/tag: .*/tag: $(VERSION)/" values.yaml 37 | else ifeq ($(OS),Linux) 38 | sed -i -e "s/version:.*/version: $(VERSION)/" Chart.yaml 39 | sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/carlossg\/$(NAME)|" values.yaml 40 | sed -i -e "s/tag: .*/tag: $(VERSION)/" values.yaml 41 | else 42 | echo "platfrom $(OS) not supported to tag with" 43 | exit -1 44 | endif 45 | git add --all 46 | git commit -m "release $(VERSION)" --allow-empty # if first release then no verion update is performed 47 | git tag -fa v$(VERSION) -m "Release version $(VERSION)" 48 | git push origin v$(VERSION) -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/README.md: -------------------------------------------------------------------------------- 1 | # golang application -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/templates/NOTES.txt: -------------------------------------------------------------------------------- 1 | 2 | Get the application URL by running these commands: 3 | 4 | kubectl get ingress {{ template "fullname" . }} 5 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/templates/_helpers.tpl: -------------------------------------------------------------------------------- 1 | {{/* vim: set filetype=mustache: */}} 2 | {{/* 3 | Expand the name of the chart. 4 | */}} 5 | {{- define "name" -}} 6 | {{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} 7 | {{- end -}} 8 | 9 | {{/* 10 | Create a default fully qualified app name. 11 | We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec). 12 | */}} 13 | {{- define "fullname" -}} 14 | {{- $name := default .Chart.Name .Values.nameOverride -}} 15 | {{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" -}} 16 | {{- end -}} 17 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/templates/canary.yaml: -------------------------------------------------------------------------------- 1 | {{- if eq .Release.Namespace "jx-production" }} 2 | {{- if .Values.canary.enable }} 3 | apiVersion: flagger.app/v1alpha2 4 | kind: Canary 5 | metadata: 6 | # canary name must match deployment name 7 | name: {{ template "fullname" . }} 8 | spec: 9 | # deployment reference 10 | targetRef: 11 | apiVersion: apps/v1 12 | kind: Deployment 13 | name: {{ template "fullname" . }} 14 | progressDeadlineSeconds: 60 15 | service: 16 | # container port 17 | port: {{.Values.service.internalPort}} 18 | {{- if .Values.canary.service.gateways }} 19 | # Istio gateways (optional) 20 | gateways: 21 | {{ toYaml .Values.canary.service.gateways | indent 4 }} 22 | {{- end }} 23 | {{- if .Values.canary.service.hosts }} 24 | # Istio virtual service host names (optional) 25 | hosts: 26 | {{ toYaml .Values.canary.service.hosts | indent 4 }} 27 | {{- end }} 28 | canaryAnalysis: 29 | # schedule interval (default 60s) 30 | interval: {{ .Values.canary.canaryAnalysis.interval }} 31 | # max number of failed metric checks before rollback 32 | threshold: {{ .Values.canary.canaryAnalysis.threshold }} 33 | # max traffic percentage routed to canary 34 | # percentage (0-100) 35 | maxWeight: {{ .Values.canary.canaryAnalysis.maxWeight }} 36 | # canary increment step 37 | # percentage (0-100) 38 | stepWeight: {{ .Values.canary.canaryAnalysis.stepWeight }} 39 | {{- if .Values.canary.canaryAnalysis.metrics }} 40 | metrics: 41 | {{ toYaml .Values.canary.canaryAnalysis.metrics | indent 4 }} 42 | {{- end }} 43 | {{- end }} 44 | {{- end }} 45 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/templates/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | name: {{ template "fullname" . }} 5 | labels: 6 | draft: {{ default "draft-app" .Values.draft }} 7 | chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" 8 | spec: 9 | replicas: {{ .Values.replicaCount }} 10 | selector: 11 | matchLabels: 12 | draft: {{ default "draft-app" .Values.draft }} 13 | {{- if .Values.appLabel }} 14 | app: {{ .Values.appLabel }} 15 | {{- else }} 16 | app: {{ template "fullname" . }} 17 | {{- end }} 18 | template: 19 | metadata: 20 | labels: 21 | draft: {{ default "draft-app" .Values.draft }} 22 | {{- if .Values.appLabel }} 23 | app: {{ .Values.appLabel }} 24 | {{- else }} 25 | app: {{ template "fullname" . }} 26 | {{- end }} 27 | {{- if .Values.podAnnotations }} 28 | annotations: 29 | {{ toYaml .Values.podAnnotations | indent 8 }} 30 | {{- end }} 31 | spec: 32 | containers: 33 | - name: {{ .Chart.Name }} 34 | image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}" 35 | imagePullPolicy: {{ .Values.image.pullPolicy }} 36 | ports: 37 | - containerPort: {{ .Values.service.internalPort }} 38 | livenessProbe: 39 | httpGet: 40 | path: {{ .Values.probePath }} 41 | port: {{ .Values.service.internalPort }} 42 | initialDelaySeconds: {{ .Values.livenessProbe.initialDelaySeconds }} 43 | periodSeconds: {{ .Values.livenessProbe.periodSeconds }} 44 | successThreshold: {{ .Values.livenessProbe.successThreshold }} 45 | timeoutSeconds: {{ .Values.livenessProbe.timeoutSeconds }} 46 | readinessProbe: 47 | httpGet: 48 | path: {{ .Values.probePath }} 49 | port: {{ .Values.service.internalPort }} 50 | periodSeconds: {{ .Values.readinessProbe.periodSeconds }} 51 | successThreshold: {{ .Values.readinessProbe.successThreshold }} 52 | timeoutSeconds: {{ .Values.readinessProbe.timeoutSeconds }} 53 | resources: 54 | {{ toYaml .Values.resources | indent 12 }} 55 | terminationGracePeriodSeconds: {{ .Values.terminationGracePeriodSeconds }} 56 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/templates/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | {{- if .Values.service.name }} 5 | name: {{ .Values.service.name }} 6 | {{- else }} 7 | name: {{ template "fullname" . }} 8 | {{- end }} 9 | labels: 10 | chart: "{{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }}" 11 | {{- if .Values.service.annotations }} 12 | annotations: 13 | {{ toYaml .Values.service.annotations | indent 4 }} 14 | {{- end }} 15 | spec: 16 | type: {{ .Values.service.type }} 17 | ports: 18 | - port: {{ .Values.service.externalPort }} 19 | targetPort: {{ .Values.service.internalPort }} 20 | protocol: TCP 21 | name: http 22 | {{- if .Values.service.nodePort }} 23 | nodePort: {{ .Values.service.nodePort }} 24 | {{- end }} 25 | selector: 26 | {{- if .Values.appLabel }} 27 | app: {{ .Values.appLabel }} 28 | {{- else }} 29 | app: {{ template "fullname" . }} 30 | {{- end }} 31 | -------------------------------------------------------------------------------- /charts/croc-hunter-jenkinsx/values.yaml: -------------------------------------------------------------------------------- 1 | # Default values for Go projects. 2 | # This is a YAML-formatted file. 3 | # Declare variables to be passed into your templates. 4 | replicaCount: 1 5 | image: 6 | repository: draft 7 | tag: dev 8 | pullPolicy: IfNotPresent 9 | service: 10 | name: croc-hunter-jenkinsx 11 | type: ClusterIP 12 | externalPort: 80 13 | internalPort: 8080 14 | annotations: 15 | fabric8.io/expose: "true" 16 | fabric8.io/ingress.annotations: "kubernetes.io/ingress.class: nginx" 17 | resources: 18 | limits: 19 | cpu: 100m 20 | memory: 256Mi 21 | requests: 22 | cpu: 80m 23 | memory: 128Mi 24 | probePath: / 25 | livenessProbe: 26 | initialDelaySeconds: 60 27 | periodSeconds: 10 28 | successThreshold: 1 29 | timeoutSeconds: 1 30 | readinessProbe: 31 | periodSeconds: 10 32 | successThreshold: 1 33 | timeoutSeconds: 1 34 | terminationGracePeriodSeconds: 10 35 | canary: 36 | enable: true 37 | service: 38 | hosts: 39 | - croc-hunter.istio.us.g.csanchez.org 40 | - croc-hunter.istio.eu.g.csanchez.org 41 | gateways: 42 | - jx-gateway.istio-system.svc.cluster.local 43 | canaryAnalysis: 44 | interval: 60s 45 | threshold: 3 46 | maxWeight: 50 47 | stepWeight: 10 48 | metrics: 49 | - name: istio_requests_total 50 | # minimum req success rate (non 5xx responses) 51 | # percentage (0-100) 52 | threshold: 99 53 | interval: 60s 54 | - name: istio_request_duration_seconds_bucket 55 | # maximum req duration P99 56 | # milliseconds 57 | threshold: 500 58 | interval: 60s 59 | -------------------------------------------------------------------------------- /charts/preview/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | description: A Helm chart for Kubernetes 3 | icon: https://raw.githubusercontent.com/jenkins-x/jenkins-x-platform/master/images/go.png 4 | name: preview 5 | version: 0.1.0-SNAPSHOT 6 | -------------------------------------------------------------------------------- /charts/preview/Makefile: -------------------------------------------------------------------------------- 1 | OS := $(shell uname) 2 | 3 | preview: 4 | ifeq ($(OS),Darwin) 5 | sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml 6 | sed -i "" -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml 7 | sed -i "" -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml 8 | else ifeq ($(OS),Linux) 9 | sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" Chart.yaml 10 | sed -i -e "s/version:.*/version: $(PREVIEW_VERSION)/" ../*/Chart.yaml 11 | sed -i -e "s|repository: .*|repository: $(DOCKER_REGISTRY)\/carlossg\/golang-http|" values.yaml 12 | sed -i -e "s/tag: .*/tag: $(PREVIEW_VERSION)/" values.yaml 13 | else 14 | echo "platfrom $(OS) not supported to release from" 15 | exit -1 16 | endif 17 | echo " version: $(PREVIEW_VERSION)" >> requirements.yaml 18 | jx step helm build 19 | -------------------------------------------------------------------------------- /charts/preview/requirements.yaml: -------------------------------------------------------------------------------- 1 | 2 | dependencies: 3 | - alias: expose 4 | name: exposecontroller 5 | repository: http://chartmuseum.jenkins-x.io 6 | version: 2.3.89 7 | - alias: cleanup 8 | name: exposecontroller 9 | repository: http://chartmuseum.jenkins-x.io 10 | version: 2.3.89 11 | - alias: preview 12 | name: croc-hunter-jenkinsx 13 | repository: file://../croc-hunter-jenkinsx 14 | -------------------------------------------------------------------------------- /charts/preview/values.yaml: -------------------------------------------------------------------------------- 1 | 2 | expose: 3 | Annotations: 4 | helm.sh/hook: post-install,post-upgrade 5 | helm.sh/hook-delete-policy: hook-succeeded 6 | config: 7 | exposer: Ingress 8 | http: true 9 | tlsacme: false 10 | 11 | cleanup: 12 | Args: 13 | - --cleanup 14 | Annotations: 15 | helm.sh/hook: pre-delete 16 | helm.sh/hook-delete-policy: hook-succeeded 17 | 18 | preview: 19 | image: 20 | repository: 21 | tag: 22 | pullPolicy: IfNotPresent -------------------------------------------------------------------------------- /croc-hunter.go: -------------------------------------------------------------------------------- 1 | // The infamous "croc-hunter" game as featured at many a demo 2 | package main 3 | 4 | import ( 5 | "flag" 6 | "fmt" 7 | "io/ioutil" 8 | "log" 9 | "net/http" 10 | "os" 11 | "strconv" 12 | "time" 13 | ) 14 | 15 | var release = os.Getenv("WORKFLOW_RELEASE") 16 | var commit = os.Getenv("GIT_SHA") 17 | var powered = os.Getenv("POWERED_BY") 18 | var region = "" 19 | 20 | func main() { 21 | httpListenAddr := flag.String("port", "8080", "HTTP Listen address.") 22 | 23 | flag.Parse() 24 | 25 | log.Println("Starting server...") 26 | 27 | log.Println("release: " + release) 28 | log.Println("commit: " + commit) 29 | log.Println("powered: " + powered) 30 | 31 | if release == "" { 32 | release = "unknown" 33 | } 34 | if commit == "" { 35 | commit = "not present" 36 | } 37 | if powered == "" { 38 | powered = "deis" 39 | } 40 | // get region 41 | 42 | req, err := http.NewRequest("GET", "http://metadata.google.internal/computeMetadata/v1/instance/attributes/cluster-location", nil) 43 | if err == nil { 44 | req.Header.Set("Metadata-Flavor", "Google") 45 | resp, err := http.DefaultClient.Do(req) 46 | if err != nil { 47 | log.Printf("could not get region: %s", err) 48 | } 49 | if resp.StatusCode < 200 || resp.StatusCode >= 300 { 50 | log.Printf("could not get region: %s", http.StatusText(resp.StatusCode)) 51 | } 52 | body, err := ioutil.ReadAll(resp.Body) 53 | resp.Body.Close() 54 | if err != nil { 55 | log.Printf("could not read region response: %s", err) 56 | } else { 57 | region = string(body) 58 | } 59 | } else { 60 | log.Printf("could not build region request: %s", err) 61 | } 62 | log.Printf("region: %s", region) 63 | 64 | // point / at the handler function 65 | http.HandleFunc("/", handler) 66 | 67 | // serve static content from /static 68 | http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/")))) 69 | 70 | log.Println("Server started. Listening on port " + *httpListenAddr) 71 | log.Fatal(http.ListenAndServe(":"+*httpListenAddr, nil)) 72 | } 73 | 74 | const ( 75 | html = ` 76 | 77 |
78 | 79 |