Skip to content
This repository has been archived by the owner on Feb 11, 2025. It is now read-only.

Commit

Permalink
Merge pull request #6 from Financial-Times/annotations-proxy
Browse files Browse the repository at this point in the history
Helm Deploy
  • Loading branch information
peteclark-ft authored Aug 17, 2017
2 parents 166cf02 + 0f519ac commit 4ddb019
Show file tree
Hide file tree
Showing 13 changed files with 200 additions and 5 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@

/vendor/*
!/vendor/vendor.json
*.exe
3 changes: 3 additions & 0 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@Library('k8s-pipeline-lib') _

pacEntryPointForJenkinsfile()
21 changes: 21 additions & 0 deletions helm/draft-annotations-api/.helmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Patterns to ignore when building packages.
# This supports shell glob matching, relative path matching, and
# negation (prefixed with !). Only one pattern per line.
.DS_Store
# Common VCS dirs
.git/
.gitignore
.bzr/
.bzrignore
.hg/
.hgignore
.svn/
# Common backup files
*.swp
*.bak
*.tmp
*~
# Various IDEs
.project
.idea/
*.tmproj
4 changes: 4 additions & 0 deletions helm/draft-annotations-api/Chart.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
description: draft-annotations-api Helm chart for Kubernetes
name: draft-annotations-api
version: 0.0.0 # this entry can be left untouched as it is automatically handled by Jenkins pipeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# Values used for the deployed application.
replicaCount: 2
service:
name: draft-annotations-api
16 changes: 16 additions & 0 deletions helm/draft-annotations-api/templates/_helpers.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{{/* vim: set filetype=mustache: */}}
{{/*
Expand the name of the chart.
*/}}
{{- define "name" -}}
{{- default .Chart.Name .Values.nameOverride | trunc 24 | trimSuffix "-" -}}
{{- end -}}

{{/*
Create a default fully qualified app name.
We truncate at 24 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).
*/}}
{{- define "fullname" -}}
{{- $name := default .Chart.Name .Values.nameOverride -}}
{{- printf "%s-%s" .Release.Name $name | trunc 24 | trimSuffix "-" -}}
{{- end -}}
22 changes: 22 additions & 0 deletions helm/draft-annotations-api/templates/admin-ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{.Values.service.name}}-admin-ingress
annotations:
# type of authentication
ingress.kubernetes.io/auth-type: basic
# name of the secret that contains the user/password definitions
ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropiate context why the authentication is required
ingress.kubernetes.io/auth-realm: "Authentication Required"
ingress.kubernetes.io/rewrite-target: /

spec:
rules:
- host: {{.Values.ingress.host}}
http:
paths:
- path: /__{{.Values.service.name}}/
backend:
serviceName: {{.Values.service.name}}
servicePort: 8080
50 changes: 50 additions & 0 deletions helm/draft-annotations-api/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
##this is an example deployment.yaml that should be customized in order to meet the configuration for app k8s deployment

apiVersion: extensions/v1beta1
kind: Deployment
metadata:
name: {{ .Values.service.name }}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
visualize: "true"
app: {{ .Values.service.name }}
spec:
replicas: {{ .Values.replicaCount }}
selector:
matchLabels:
app: {{ .Values.service.name }}
template:
metadata:
labels:
app: {{ .Values.service.name }}
visualize: "true"
spec:
containers:
- name: {{ .Values.service.name }}
image: "{{ .Values.image.repository }}:{{ .Chart.Version }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
env:
- name: ANNOTATIONS_ENDPOINT
valueFrom:
configMapKeyRef:
name: global-config
key: annotations-endpoint
- name: UPP_APIKEY
valueFrom:
configMapKeyRef:
name: global-config
key: upp-api-key
ports:
- containerPort: 8080
livenessProbe:
tcpSocket:
port: 8080
initialDelaySeconds: 10
readinessProbe:
httpGet:
path: "/__gtg"
port: 8080
initialDelaySeconds: 15
periodSeconds: 30
resources:
{{ toYaml .Values.resources | indent 12 }}
22 changes: 22 additions & 0 deletions helm/draft-annotations-api/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
apiVersion: extensions/v1beta1
kind: Ingress
metadata:
name: {{.Values.service.name}}-ingress
annotations:
# type of authentication
ingress.kubernetes.io/auth-type: basic
# name of the secret that contains the user/password definitions
ingress.kubernetes.io/auth-secret: basic-auth
# message to display with an appropiate context why the authentication is required
ingress.kubernetes.io/auth-realm: "Authentication Required"
# to interpret the wildcard in path as a regex
ingress.kubernetes.io/rewrite-target: /drafts/content/
spec:
rules:
- host: {{.Values.ingress.host}}
http:
paths:
- path: /drafts/content/.*/annotations
backend:
serviceName: {{.Values.service.name}}
servicePort: 8080
17 changes: 17 additions & 0 deletions helm/draft-annotations-api/templates/service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@

kind: Service
apiVersion: v1
metadata:
name: {{.Values.service.name}}
labels:
chart: "{{ .Chart.Name }}-{{ .Chart.Version }}"
app: {{.Values.service.name}}
visualize: "true"
hasHealthcheck: "{{ .Values.service.hasHealthcheck }}"
spec:
ports:
- port: 8080
# name: # The name of this port within the service. Optional if only one port is defined on this service
targetPort: 8080
selector:
app: {{ .Values.service.name }}
14 changes: 14 additions & 0 deletions helm/draft-annotations-api/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Default values for draft-annotations-api.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.
service:
name: "" # The name of the service, should be defined in the specific app-configs folder
hasHealthcheck: "true"
replicaCount: 2
image:
repository: coco/draft-annotations-api
pullPolicy: Always
ingress:
host: "pre-prod-eu-pac.ft.com"


19 changes: 14 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ import (
api "github.com/Financial-Times/api-endpoint"
"github.com/Financial-Times/draft-annotations-api/annotations"
"github.com/Financial-Times/draft-annotations-api/health"
"github.com/Financial-Times/http-handlers-go/httphandlers"
status "github.com/Financial-Times/service-status-go/httphandlers"
"github.com/husobee/vestigo"
"github.com/jawher/mow.cli"
"github.com/rcrowley/go-metrics"
log "github.com/sirupsen/logrus"
)

Expand Down Expand Up @@ -81,22 +83,29 @@ func main() {
}

func serveEndpoints(port string, apiYml *string, handler *annotations.Handler, healthService *health.HealthService) {

r := vestigo.NewRouter()
r.Get("/drafts/content/:uuid/annotations", handler.ServeHTTP)
r.Get("/__health", healthService.HealthCheckHandleFunc())
r.Get(status.GTGPath, status.NewGoodToGoHandler(healthService.GTG))
r.Get(status.BuildInfoPath, status.BuildInfoHandler)
var monitoringRouter http.Handler = r
monitoringRouter = httphandlers.TransactionAwareRequestLoggingHandler(log.StandardLogger(), monitoringRouter)
monitoringRouter = httphandlers.HTTPMetricsHandler(metrics.DefaultRegistry, monitoringRouter)

http.HandleFunc("/__health", healthService.HealthCheckHandleFunc())
http.HandleFunc(status.GTGPath, status.NewGoodToGoHandler(healthService.GTG))
http.HandleFunc(status.BuildInfoPath, status.BuildInfoHandler)

http.Handle("/", monitoringRouter)

if apiYml != nil {
apiEndpoint, err := api.NewAPIEndpointForFile(*apiYml)
if err != nil {
log.WithError(err).WithField("file", *apiYml).Warn("Failed to serve the API Endpoint for this service. Please validate the Swagger YML and the file location.")
log.WithError(err).WithField("file", *apiYml).Warn("Failed to serve the API Endpoint for this service. Please validate the Swagger YML and the file location")
} else {
r.Get(api.DefaultPath, apiEndpoint.ServeHTTP)
}
}

if err := http.ListenAndServe(":"+port, r); err != nil {
if err := http.ListenAndServe(":"+port, nil); err != nil {
log.Fatalf("Unable to start: %v", err)
}
}
12 changes: 12 additions & 0 deletions vendor/vendor.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@
"version": "0.3.0",
"versionExact": "0.3.0"
},
{
"checksumSHA1": "dqF1g4reeLPNN10qTXgDJj3fHm4=",
"path": "github.com/Financial-Times/http-handlers-go/httphandlers",
"revision": "229ac16f1d9ec9bca485d2dafb9ec14dc7e9ba24",
"revisionTime": "2017-08-09T12:10:07Z"
},
{
"checksumSHA1": "fqpohN7Qp2qj7TLMbUxh/cK4oH0=",
"path": "github.com/Financial-Times/service-status-go/buildinfo",
Expand Down Expand Up @@ -82,6 +88,12 @@
"revision": "792786c7400a136282c1664665ae0a8db921c6c2",
"revisionTime": "2016-01-10T10:55:54Z"
},
{
"checksumSHA1": "KAzbLjI9MzW2tjfcAsK75lVRp6I=",
"path": "github.com/rcrowley/go-metrics",
"revision": "1f30fe9094a513ce4c700b9a54458bbb0c96996c",
"revisionTime": "2016-11-28T21:05:44Z"
},
{
"checksumSHA1": "IVurU/0OPiDHP+JrmQ1JyAx7jng=",
"path": "github.com/sirupsen/logrus",
Expand Down

0 comments on commit 4ddb019

Please sign in to comment.