diff --git a/.drone.yml b/.drone.yml new file mode 100644 index 0000000..a35f13d --- /dev/null +++ b/.drone.yml @@ -0,0 +1,74 @@ +workspace: + base: /go + path: src/github.com/src-d/code-annotation + +branches: [master, staging, release/*] + +pipeline: + + clone: + image: plugins/git + debug: true + + + # build on pull requests + + build: + image: golang:1.8-alpine3.6 + environment: + - REACT_APP_SERVER_URL="//code-annotation.sourced.tech" + commands: + - apk --update upgrade + - apk add --no-cache make git curl ca-certificates bash build-base libxml2-dev protobuf nodejs=6.10.3-r1 nodejs-npm + - npm install -g yarn + - make build + - make packages + debug: true + when: + event: [pull_request] + + + # deployment to staging environment + + build_stg: + image: golang:1.8-alpine3.6 + environment: + - REACT_APP_SERVER_URL="//code-annotation-staging.srcd.run" + commands: + - apk --update upgrade + - apk add --no-cache make git curl ca-certificates bash build-base libxml2-dev protobuf nodejs=6.10.3-r1 nodejs-npm + - npm install -g yarn + - make build + - make packages + debug: true + when: + branch: [staging] + event: [push] + + docker_stg: + group: docker + image: plugins/docker + registry: docker.io + repo: srcd/code-annotation + secrets: [ docker_username, docker_password ] + # workaround for bug https://github.com/kubernetes/helm/issues/1707 + tag: 'commit-${DRONE_COMMIT_SHA:0:7}' + dockerfile: Dockerfile + debug: true + when: + branch: [staging] + event: [push] + + helm_deploy_stg: + image: quay.io/ipedrazas/drone-helm + skip_tls_verify: true + chart: ./helm-charts/code-annotation + release: code-annotation + prefix: STG + secrets: [ STG_API_SERVER, STG_KUBERNETES_TOKEN ] + values: ingress.globalStaticIpName=code-annotation-staging,ingress.hostname=code-annotation-staging.srcd.run,image.tag=commit-${DRONE_COMMIT_SHA:0:7} + tiller_ns: kube-system + wait: true + when: + branch: [staging] + event: [push] diff --git a/helm-charts/code-annotation/.helmignore b/helm-charts/code-annotation/.helmignore new file mode 100644 index 0000000..f0c1319 --- /dev/null +++ b/helm-charts/code-annotation/.helmignore @@ -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 diff --git a/helm-charts/code-annotation/Chart.yaml b/helm-charts/code-annotation/Chart.yaml new file mode 100644 index 0000000..f3fdcb9 --- /dev/null +++ b/helm-charts/code-annotation/Chart.yaml @@ -0,0 +1,4 @@ +apiVersion: v1 +description: A Helm chart for Kubernetes +name: code-annotation +version: 0.0.1 diff --git a/helm-charts/code-annotation/README.md b/helm-charts/code-annotation/README.md new file mode 100644 index 0000000..f41a1f5 --- /dev/null +++ b/helm-charts/code-annotation/README.md @@ -0,0 +1,53 @@ +# Code Annotation Tool + +This chart deploys source{d} [code annotation tool](https://github.com/src-d/code-annotation) + +## Pre-requisites + +* Kubernetes 1.4+ with Beta APIs enabled + +## Installing the chart + +All parameters under `settings` in [values.yaml](values.yaml) must be provided. + +``` +helm install -n --set \ +secrets.jwt_signing_key=,\ +secrets.github_client=,\ +secrets.github_secret=,\ +ingress.hostname=,\ +ingress.globalStaticIpName=,\ +image.tag= +``` + +These are the mandatory parameters that need to be provided or installation will fail. +Other parameters can be provided too but, if not, a default value will be used. + +It's also possible to set name of separately deployed secrets using parameter `secretName`. + +Full command for deployment: + +``` +helm install -n --set \ +secretName=,\ +ingress.hostname=,\ +ingress.globalStaticIpName=,\ +image.tag= +``` + +# Configuration + +Please refer to [values.yaml](values.yaml) for the full run-down on defaults. + +To override any of those default values, +specify each parameter using the `--set key=value[,key=value]` argument to `helm install`. + +Alternatively, a YAML file that specifies the values for the parameters can be provided +while installing the chart. +For example, + +```bash +$ helm install --name -f values.yaml +``` + +> **Tip**: You can use the default [values.yaml](values.yaml) diff --git a/helm-charts/code-annotation/templates/_helpers.tpl b/helm-charts/code-annotation/templates/_helpers.tpl new file mode 100644 index 0000000..f0d83d2 --- /dev/null +++ b/helm-charts/code-annotation/templates/_helpers.tpl @@ -0,0 +1,16 @@ +{{/* vim: set filetype=mustache: */}} +{{/* +Expand the name of the chart. +*/}} +{{- define "name" -}} +{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" -}} +{{- end -}} + +{{/* +Create a default fully qualified app name. +We truncate at 63 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 63 | trimSuffix "-" -}} +{{- end -}} diff --git a/helm-charts/code-annotation/templates/deployment.yaml b/helm-charts/code-annotation/templates/deployment.yaml new file mode 100644 index 0000000..239374d --- /dev/null +++ b/helm-charts/code-annotation/templates/deployment.yaml @@ -0,0 +1,57 @@ +{{- $secretName := default (include "fullname" .) .Values.secretName -}} + +apiVersion: extensions/v1beta1 +kind: Deployment +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + replicas: {{ .Values.replicaCount }} + template: + metadata: + labels: + app: {{ template "name" . }} + release: {{ .Release.Name }} + spec: + containers: + - name: {{ .Chart.Name }} + image: "{{ .Values.image.repository }}:{{ required "Image tag is required" .Values.image.tag }}" + imagePullPolicy: {{ .Values.image.pullPolicy }} + env: + - name: UI_DOMAIN + value: "//{{ .Values.ingress.hostname }}" + - name: OAUTH_CLIENT_ID + valueFrom: + secretKeyRef: + name: {{ $secretName }} + key: github_client + - name: OAUTH_CLIENT_SECRET + valueFrom: + secretKeyRef: + name: {{ $secretName }} + key: github_secret + - name: JWT_SIGNING_KEY + valueFrom: + secretKeyRef: + name: {{ $secretName }} + key: jwt_signing_key + ports: + - containerPort: {{ .Values.service.codeAnnotation.internalPort }} + livenessProbe: + httpGet: + path: / + port: {{ .Values.service.codeAnnotation.internalPort }} + readinessProbe: + httpGet: + path: / + port: {{ .Values.service.codeAnnotation.internalPort }} + resources: +{{ toYaml .Values.resources | indent 12 }} + {{- if .Values.nodeSelector }} + nodeSelector: +{{ toYaml .Values.nodeSelector | indent 8 }} + {{- end }} diff --git a/helm-charts/code-annotation/templates/ingress.yaml b/helm-charts/code-annotation/templates/ingress.yaml new file mode 100644 index 0000000..63f2d35 --- /dev/null +++ b/helm-charts/code-annotation/templates/ingress.yaml @@ -0,0 +1,33 @@ +{{- $serviceName := include "fullname" . -}} +{{- $servicePort := .Values.service.codeAnnotation.externalPort -}} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + stable.k8s.psg.io/kcm.class: {{ .Values.ingress.kcmClass }} + annotations: + {{- range $key, $value := .Values.ingress.annotations }} + {{ $key }}: {{ $value | quote }} + {{- end }} + kubernetes.io/ingress.global-static-ip-name: {{ required "Missing .Values.ingress.globalStaticIpName" .Values.ingress.globalStaticIpName }} +spec: + rules: + - host: {{ required "Hostname is missing" .Values.ingress.hostname }} + http: + paths: + - path: /* + backend: + serviceName: {{ $serviceName }} + servicePort: {{ $servicePort }} + + {{- if .Values.ingress.tls }} + tls: + - secretName: "{{ template "fullname" . }}-tls" + hosts: + - {{ .Values.ingress.hostname }} + {{- end }} diff --git a/helm-charts/code-annotation/templates/secrets.yaml b/helm-charts/code-annotation/templates/secrets.yaml new file mode 100644 index 0000000..bed9988 --- /dev/null +++ b/helm-charts/code-annotation/templates/secrets.yaml @@ -0,0 +1,18 @@ +# create secrets only if there is no name for existing secrets +{{- required "Secrets or secretName are missing" (or .Values.secretName .Values.secrets) }} +{{- if not .Values.secretName }} +apiVersion: v1 +kind: Secret +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "fullname" . }} + chart: "{{ .Chart.Name }}-{{ .Chart.Version }}" + release: "{{ .Release.Name }}" + heritage: "{{ .Release.Service }}" +type: Opaque +data: + github_client: "{{ required "Github client ID is missing" .Values.secrets.github_client | b64enc }}" + github_secret: "{{ required "Github secret is missing" .Values.secrets.github_secret | b64enc }}" + jwt_signing_key: "{{ required "JWT signing key secret is missing" .Values.secrets.jwt_signing_key | b64enc }}" +{{- end }} diff --git a/helm-charts/code-annotation/templates/service.yaml b/helm-charts/code-annotation/templates/service.yaml new file mode 100644 index 0000000..87ddafe --- /dev/null +++ b/helm-charts/code-annotation/templates/service.yaml @@ -0,0 +1,19 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "fullname" . }} + labels: + app: {{ template "name" . }} + chart: {{ .Chart.Name }}-{{ .Chart.Version | replace "+" "_" }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +spec: + type: {{ .Values.service.type }} + ports: + - port: {{ .Values.service.codeAnnotation.externalPort }} + targetPort: {{ .Values.service.codeAnnotation.internalPort }} + protocol: TCP + name: {{ .Values.service.codeAnnotation.name }} + selector: + app: {{ template "name" . }} + release: {{ .Release.Name }} diff --git a/helm-charts/code-annotation/values.yaml b/helm-charts/code-annotation/values.yaml new file mode 100644 index 0000000..a20f49a --- /dev/null +++ b/helm-charts/code-annotation/values.yaml @@ -0,0 +1,46 @@ +# Default values for landing. +# This is a YAML-formatted file. +# Declare variables to be passed into your templates. +replicaCount: 1 + +# If provided, these will be used by the deployment +# nodeSelector: XXXXXXX + +image: + repository: docker.io/srcd/code-annotation + # tag must be received as a parameter + pullPolicy: IfNotPresent +service: + type: NodePort + codeAnnotation: + externalPort: 8080 + internalPort: 8080 + name: code-annotation +ingress: + kcmClass: default + annotations: + kubernetes.io/ingress.class: gce + tls: true + # below values are required + # hostname: "code-annotation-staging.srcd.run" + # globalStaticIpName: "code-annotation-ip" + +# Provide with 'helm install', and do NOT change it when doing 'helm upgrade' +# github_client: +# github_secret: +# jwt_signing_key: +# It's also possible to use deployed secrets by using argument: +# secretName: "existing name" + +resources: {} + # We usually recommend not to specify default resources and to leave this as a conscious + # choice for the user. This also increases chances charts run on environments with little + # resources, such as Minikube. If you do want to specify resources, uncomment the following + # lines, adjust them as necessary, and remove the curly braces after 'resources:'. + # limits: + # cpu: 100m + # memory: 128Mi + #requests: + # cpu: 100m + # memory: 128Mi + #