From ba10eb5e0bfd2eb8455b05e022d9b8343e489299 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 12:28:16 +0800 Subject: [PATCH 01/17] Add helm charts --- infra/charts/management-service/Chart.yaml | 5 + infra/charts/management-service/README.md | 99 +++++++++++++ .../management-service/README.md.gotmpl | 57 ++++++++ .../management-service/templates/_helpers.tpl | 96 ++++++++++++ .../templates/deployment.yaml | 130 +++++++++++++++++ .../management-service/templates/ingress.yaml | 33 +++++ .../management-service/templates/secrets.yaml | 12 ++ .../templates/service-swagger.yaml | 22 +++ .../templates/service-xp.yaml | 22 +++ .../templates/serviceaccount.yaml | 12 ++ infra/charts/management-service/values.yaml | 137 ++++++++++++++++++ infra/charts/treatment-service/Chart.yaml | 5 + infra/charts/treatment-service/README.md | 97 +++++++++++++ .../charts/treatment-service/README.md.gotmpl | 57 ++++++++ .../treatment-service/templates/_helpers.tpl | 54 +++++++ .../templates/deployment.yaml | 136 +++++++++++++++++ .../treatment-service/templates/hpa.yaml | 32 ++++ .../treatment-service/templates/ingress.yaml | 33 +++++ .../treatment-service/templates/secrets.yaml | 8 + .../templates/service-swagger.yaml | 24 +++ .../templates/service-xp.yaml | 22 +++ infra/charts/treatment-service/values.yaml | 98 +++++++++++++ 22 files changed, 1191 insertions(+) create mode 100644 infra/charts/management-service/Chart.yaml create mode 100644 infra/charts/management-service/README.md create mode 100644 infra/charts/management-service/README.md.gotmpl create mode 100644 infra/charts/management-service/templates/_helpers.tpl create mode 100644 infra/charts/management-service/templates/deployment.yaml create mode 100644 infra/charts/management-service/templates/ingress.yaml create mode 100644 infra/charts/management-service/templates/secrets.yaml create mode 100644 infra/charts/management-service/templates/service-swagger.yaml create mode 100644 infra/charts/management-service/templates/service-xp.yaml create mode 100644 infra/charts/management-service/templates/serviceaccount.yaml create mode 100644 infra/charts/management-service/values.yaml create mode 100644 infra/charts/treatment-service/Chart.yaml create mode 100644 infra/charts/treatment-service/README.md create mode 100644 infra/charts/treatment-service/README.md.gotmpl create mode 100644 infra/charts/treatment-service/templates/_helpers.tpl create mode 100644 infra/charts/treatment-service/templates/deployment.yaml create mode 100644 infra/charts/treatment-service/templates/hpa.yaml create mode 100644 infra/charts/treatment-service/templates/ingress.yaml create mode 100644 infra/charts/treatment-service/templates/secrets.yaml create mode 100644 infra/charts/treatment-service/templates/service-swagger.yaml create mode 100644 infra/charts/treatment-service/templates/service-xp.yaml create mode 100644 infra/charts/treatment-service/values.yaml diff --git a/infra/charts/management-service/Chart.yaml b/infra/charts/management-service/Chart.yaml new file mode 100644 index 00000000..f9513328 --- /dev/null +++ b/infra/charts/management-service/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "0.0.1" +description: A Helm chart for Kubernetes Deployment of the XP Managment Service +name: xp-management +version: 0.0.1 diff --git a/infra/charts/management-service/README.md b/infra/charts/management-service/README.md new file mode 100644 index 00000000..a99ae228 --- /dev/null +++ b/infra/charts/management-service/README.md @@ -0,0 +1,99 @@ +# xp-management + +--- +![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) +![AppVersion: 0.0.1](https://img.shields.io/badge/AppVersion-0.0.1-informational?style=flat-square) + +A Helm chart for Kubernetes Deployment of the XP Managment Service + +## Introduction + +This Helm chart installs [Management Service](https://github.com/gojek/xp/management-service) and all its dependencies in a Kubernetes cluster. + +## Prerequisites + +To use the charts here, [Helm](https://helm.sh/) must be configured for your +Kubernetes cluster. Setting up Kubernetes and Helm is outside the scope of +this README. Please refer to the Kubernetes and Helm documentation. + +- **Helm 3.0+** – This chart was tested with Helm v3.7.1, but it is also expected to work with earlier Helm versions +- **Kubernetes 1.18+** – This chart was tested with GKE v1.20.x, but it's possible it works with earlier k8s versions too. + +## Installation + +### Add Helm repository + +```sh +$ helm repo add xp https://turing-ml.github.io/charts +``` + +### Installing the chart + +This command will install XP Management Service release named `management-service` in the `default` namespace. +Default chart values will be used for the installation: +```shell +$ helm install xp xp/management-service +``` + +You can (and most likely, should) override the default configuration with values suitable for your installation. +Refer to [Configuration](#configuration) section for the detailed description of available configuration keys. + +You can also refer to [values.minimal.yaml](./values.minimal.yaml) to check a minimal configuration that needs +to be provided for XP Management Service installation. + +### Uninstalling the chart + +To uninstall `management-service` release: +```shell +$ helm uninstall management-service +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release, +except for postgresql PVC, those will have to be removed manually. + +## Configuration + +The following table lists the configurable parameters of the XP Management Service chart and their default values. + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| global.mlp.encryption.key | string | `nil` | Global MLP Encryption Key to be used by all MLP components | +| global.sentry.dsn | string | `nil` | Global Sentry DSN value | +| swaggerUi.apiServer | string | `"http://127.0.0.1/v1"` | URL of API server | +| swaggerUi.image | object | `{"tag":"v3.47.1"}` | Docker tag for Swagger UI https://hub.docker.com/r/swaggerapi/swagger-ui | +| swaggerUi.service.externalPort | int | `8080` | Swagger UI Kubernetes service port number | +| swaggerUi.service.internalPort | int | `8081` | Swagger UI container port number | +| xpApi.config | object | `{}` | XP API server configuration. | +| xpApi.extraArgs | list | `[]` | List of string containing additional XP API server arguments. For example, multiple "-config" can be specified to use multiple config files | +| xpApi.extraEnvs | list | `[]` | List of extra environment variables to add to XP API server container | +| xpApi.extraLabels | object | `{}` | List of extra labels to add to XP API K8s resources | +| xpApi.extraVolumeMounts | list | `[]` | Extra volume mounts to attach to XP API server container. For example to mount the extra volume containing secrets | +| xpApi.extraVolumes | list | `[]` | Extra volumes to attach to the Pod. For example, you can mount additional secrets to these volumes | +| xpApi.image.pullPolicy | string | `"IfNotPresent"` | Docker image pull policy | +| xpApi.image.registry | string | `"docker.io/"` | Docker registry for XP API image | +| xpApi.image.repository | string | `"xp-management"` | Docker image repository for XP API | +| xpApi.image.tag | string | `"latest"` | Docker image tag for XP API | +| xpApi.ingress.class | string | `""` | Ingress class annotation to add to this Ingress rule, useful when there are multiple ingress controllers installed | +| xpApi.ingress.enabled | bool | `false` | Enable ingress to provision Ingress resource for external access to XP API | +| xpApi.ingress.host | string | `""` | Set host value to enable name based virtual hosting. This allows routing HTTP traffic to multiple host names at the same IP address. If no host is specified, the ingress rule applies to all inbound HTTP traffic through the IP address specified. https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting | +| xpApi.labels | object | `{}` | | +| xpApi.livenessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | +| xpApi.livenessProbe.path | string | `"/v1/internal/live"` | HTTP path for liveness check | +| xpApi.livenessProbe.periodSeconds | int | `10` | | +| xpApi.livenessProbe.successThreshold | int | `1` | | +| xpApi.livenessProbe.timeoutSeconds | int | `5` | | +| xpApi.readinessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | +| xpApi.readinessProbe.path | string | `"/v1/internal/ready"` | HTTP path for readiness check | +| xpApi.readinessProbe.periodSeconds | int | `10` | | +| xpApi.readinessProbe.successThreshold | int | `1` | | +| xpApi.readinessProbe.timeoutSeconds | int | `5` | | +| xpApi.replicaCount | int | `1` | | +| xpApi.resources | object | `{}` | Resources requests and limits for XP API. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | +| xpApi.sentry.dsn | string | `""` | Sentry DSN value used by both XP API and XP UI | +| xpApi.sentry.enabled | bool | `false` | | +| xpApi.service.externalPort | int | `8080` | XP API Kubernetes service port number | +| xpApi.service.internalPort | int | `8080` | XP API container port number | +| xpApi.serviceAccount.annotations | object | `{}` | | +| xpApi.serviceAccount.create | bool | `true` | | +| xpApi.serviceAccount.name | string | `""` | | +| xpApi.uiConfig | object | `{"apiConfig":{"mlpApiUrl":"/api/v1","xpApiUrl":"/api/xp/v1"},"appConfig":{"docsUrl":[{"href":"https://github.com/gojek/xp/tree/main/docs","label":"XP User Guide"}]},"authConfig":{"oauthClientId":""},"sentryConfig":{}}` | XP UI configuration. | diff --git a/infra/charts/management-service/README.md.gotmpl b/infra/charts/management-service/README.md.gotmpl new file mode 100644 index 00000000..602b6ca5 --- /dev/null +++ b/infra/charts/management-service/README.md.gotmpl @@ -0,0 +1,57 @@ +{{ template "chart.header" . }} +--- +{{ template "chart.versionBadge" . }} +{{ template "chart.appVersionBadge" . }} + +{{ template "chart.description" . }} + +## Introduction + +This Helm chart installs [Management Service](https://github.com/gojek/xp/management-service) and all its dependencies in a Kubernetes cluster. + +## Prerequisites + +To use the charts here, [Helm](https://helm.sh/) must be configured for your +Kubernetes cluster. Setting up Kubernetes and Helm is outside the scope of +this README. Please refer to the Kubernetes and Helm documentation. + +- **Helm 3.0+** – This chart was tested with Helm v3.7.1, but it is also expected to work with earlier Helm versions +- **Kubernetes 1.18+** – This chart was tested with GKE v1.20.x, but it's possible it works with earlier k8s versions too. + +## Installation + +### Add Helm repository + +```sh +$ helm repo add xp https://turing-ml.github.io/charts +``` + +### Installing the chart + +This command will install XP Management Service release named `management-service` in the `default` namespace. +Default chart values will be used for the installation: +```shell +$ helm install xp xp/management-service +``` + +You can (and most likely, should) override the default configuration with values suitable for your installation. +Refer to [Configuration](#configuration) section for the detailed description of available configuration keys. + +You can also refer to [values.minimal.yaml](./values.minimal.yaml) to check a minimal configuration that needs +to be provided for XP Management Service installation. + +### Uninstalling the chart + +To uninstall `management-service` release: +```shell +$ helm uninstall management-service +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release, +except for postgresql PVC, those will have to be removed manually. + +## Configuration + +The following table lists the configurable parameters of the XP Management Service chart and their default values. + +{{ template "chart.valuesTable" . }} diff --git a/infra/charts/management-service/templates/_helpers.tpl b/infra/charts/management-service/templates/_helpers.tpl new file mode 100644 index 00000000..c5ae5ac7 --- /dev/null +++ b/infra/charts/management-service/templates/_helpers.tpl @@ -0,0 +1,96 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "xp.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). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "xp.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "xp.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{- define "xp.environment" -}} +{{- .Values.global.environment | default .Values.xpApi.environment | default "dev" -}} +{{- end -}} + +{{/* +Common labels +*/}} +{{- define "xp.labels" -}} +helm.sh/chart: {{ include "xp.chart" . }} +{{- with .Values.xpApi.extraLabels }} +{{- toYaml . | nindent 0 }} +{{- end }} +{{ include "xp.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "xp.selectorLabels" -}} +app.kubernetes.io/name: {{ include "xp.fullname" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} + +{{/* +Create the name of the service account to use +*/}} +{{- define "xp.serviceAccountName" -}} +{{- if .Values.xpApi.serviceAccount.create }} +{{- default (include "xp.fullname" .) .Values.xpApi.serviceAccount.name }} +{{- else }} +{{- default "default" .Values.xpApi.serviceAccount.name }} +{{- end }} +{{- end }} + +{{- define "xp.sentry.enabled" -}} +{{ eq (.Values.xpApi.config.SentryConfig.Enabled | toString) "true" }} +{{- end -}} + +{{- define "xp.sentry.dsn" -}} +{{- .Values.global.sentry.dsn | default .Values.xpApi.sentry.dsn -}} +{{- end -}} + +{{- define "xp.ui.defaultConfig" -}} +{{- if .Values.xpApi.uiConfig -}} +appConfig: + environment: {{ .Values.xpApi.uiConfig.appConfig.environment | default (include "xp.environment" .) }} +authConfig: + oauthClientId: {{ .Values.global.oauthClientId | default .Values.xpApi.uiConfig.authConfig.oauthClientId | quote }} +{{- if (include "xp.sentry.enabled" .) }} +sentryConfig: + environment: {{ .Values.xpApi.uiConfig.sentryConfig.environment | default (include "xp.environment" .) }} + dsn: {{ .Values.xpApi.uiConfig.sentryConfig.dsn | default (include "xp.sentry.dsn" .) | quote }} +{{- end -}} +{{- end -}} +{{- end -}} + +{{- define "xp.ui.config" -}} +{{- $defaultConfig := include "xp.ui.defaultConfig" . | fromYaml -}} +{{ .Values.xpApi.uiConfig | merge $defaultConfig | toPrettyJson }} +{{- end -}} diff --git a/infra/charts/management-service/templates/deployment.yaml b/infra/charts/management-service/templates/deployment.yaml new file mode 100644 index 00000000..0a2bff1f --- /dev/null +++ b/infra/charts/management-service/templates/deployment.yaml @@ -0,0 +1,130 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "xp.fullname" . }} + labels: + {{- include "xp.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.xpApi.replicaCount }} + selector: + matchLabels: + app: {{ template "xp.name" .}} + release: {{ .Release.Name }} + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + template: + metadata: + labels: + app: {{ template "xp.name" .}} + release: {{ .Release.Name }} + {{- include "xp.labels" . | nindent 8 }} + spec: + {{- with .Values.xpApi.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + serviceAccountName: {{ include "xp.serviceAccountName" . }} + containers: + - name: api + image: "{{ .Values.xpApi.image.registry }}{{ .Values.xpApi.image.repository }}:{{ .Values.xpApi.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.xpApi.image.pullPolicy }} + env: + {{- with .Values.xpApi.extraEnvs }} + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: {{ .Values.xpApi.livenessProbe.path }} + port: {{ .Values.xpApi.service.internalPort }} + scheme: HTTP + initialDelaySeconds: {{ .Values.xpApi.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.xpApi.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.xpApi.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.xpApi.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.xpApi.readinessProbe.path }} + port: {{ .Values.xpApi.service.internalPort }} + scheme: HTTP + initialDelaySeconds: {{ .Values.xpApi.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.xpApi.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.xpApi.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.xpApi.readinessProbe.timeoutSeconds }} + resources: + {{- toYaml .Values.xpApi.resources | nindent 12 }} + # Give time for running pods to terminate existing connection before letting + # Kubernetes terminate the pods. + # https://blog.sebastian-daschner.com/entries/zero-downtime-updates-kubernetes + lifecycle: + preStop: + exec: + command: ["/bin/bash", "-c", "sleep 15"] + args: + - serve + - --config=/etc/xp/config.yaml + {{- if .Values.xpApi.uiConfig }} + - -ui-config + - /etc/xp/ui.config.json + {{- end }} + {{- with .Values.xpApi.extraArgs }} + {{- toYaml . | nindent 8 }} + {{- end }} + volumeMounts: + - name: config + mountPath: /etc/xp + {{- with .Values.xpApi.extraVolumeMounts }} + {{- toYaml . | nindent 8 }} + {{- end }} + - name: swagger-ui + image: "swaggerapi/swagger-ui:{{ .Values.swaggerUi.image.tag }}" + imagePullPolicy: IfNotPresent + ports: + - containerPort: {{ .Values.swaggerUi.service.internalPort }} + resources: + requests: + cpu: 100m + memory: 64Mi + limits: + cpu: 500m + memory: 128Mi + env: + - name: LAYOUT + value: "BaseLayout" + - name: SWAGGER_JSON + value: "/app/experiments.yaml" + - name: PORT + value: "{{ .Values.swaggerUi.service.internalPort }}" + - name: API_SERVER + value: "{{ .Values.swaggerUi.apiServer }}" + command: ["sh", "-c"] + args: + - | + mkdir /app + export LOCAL_API_SERVER="http://127.0.0.1:{{ .Values.xpApi.service.internalPort }}" + echo "Fetching swagger configuration from ${LOCAL_API_SERVER}/experiments.yaml..." + until $$(wget -O $${SWAGGER_JSON} --tries 1 --timeout 1 ${LOCAL_API_SERVER}/experiments.yaml); do + printf '.' + sleep 10 + done + echo "Fetching swagger configuration from ${LOCAL_API_SERVER}/schema.yaml..." + until $$(wget -O /app/schema.yaml --tries 1 --timeout 1 ${LOCAL_API_SERVER}/schema.yaml); do + printf '.' + sleep 10 + done + echo "Update Swagger config..." + sed -r -i 's%^((\s*)-(\s*)url\s*:).*$$%\1 "'$${API_SERVER}'"%' $${SWAGGER_JSON} + echo "Running Swagger UI..." + /usr/share/nginx/run.sh + volumes: + - name: config + secret: + secretName: {{ template "xp.fullname" .}}-api-config + {{- with .Values.xpApi.extraVolumes }} + {{- toYaml . | nindent 6 }} + {{- end }} diff --git a/infra/charts/management-service/templates/ingress.yaml b/infra/charts/management-service/templates/ingress.yaml new file mode 100644 index 00000000..b37808c0 --- /dev/null +++ b/infra/charts/management-service/templates/ingress.yaml @@ -0,0 +1,33 @@ +{{- if .Values.xpApi.ingress.enabled }} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "xp.fullname" .}} + namespace: {{ .Release.Namespace }} + annotations: + {{- with .Values.xpApi.ingress.class }} + ingress.class: {{ . }} + {{- end }} + labels: + app: {{ include "xp.fullname" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + helm.sh/chart: {{ include "xp.chart" . }} + app.kubernetes.io/name: {{ include "xp.fullname" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- if .Values.xpApi.labels }} +{{ toYaml .Values.xpApi.labels | indent 4 }} +{{- end }} +spec: + rules: + - {{- with .Values.xpApi.ingress.host }} + host: {{ . }} + {{- end }} + http: + paths: + - path: / + backend: + serviceName: {{ template "xp.fullname" .}} + servicePort: {{ .Values.xpApi.service.externalPort }} +{{- end }} diff --git a/infra/charts/management-service/templates/secrets.yaml b/infra/charts/management-service/templates/secrets.yaml new file mode 100644 index 00000000..56dcd5ac --- /dev/null +++ b/infra/charts/management-service/templates/secrets.yaml @@ -0,0 +1,12 @@ +apiVersion: v1 +kind: Secret +metadata: + namespace: {{ .Release.Namespace }} + name: {{ template "xp.fullname" .}}-api-config +stringData: + config.yaml: | + {{- toYaml .Values.xpApi.config | nindent 4 -}} + {{- if .Values.xpApi.uiConfig }} + ui.config.json: | + {{- include "xp.ui.config" . | nindent 4 -}} + {{- end }} diff --git a/infra/charts/management-service/templates/service-swagger.yaml b/infra/charts/management-service/templates/service-swagger.yaml new file mode 100644 index 00000000..f3c4ff44 --- /dev/null +++ b/infra/charts/management-service/templates/service-swagger.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "xp.fullname" .}}-swagger + namespace: {{ .Release.Namespace }} + labels: + app: {{ template "xp.fullname" .}} + chart: {{ template "xp.chart" .}} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{ if .Values.xpApi.labels -}} +{{ toYaml .Values.xpApi.labels | indent 4 -}} +{{- end }} +spec: + type: ClusterIP + ports: + - port: {{ .Values.swaggerUi.service.externalPort }} + targetPort: {{ .Values.swaggerUi.service.internalPort }} + protocol: TCP + selector: + app: {{ template "xp.fullname" .}} + release: {{ .Release.Name }} diff --git a/infra/charts/management-service/templates/service-xp.yaml b/infra/charts/management-service/templates/service-xp.yaml new file mode 100644 index 00000000..4f86846f --- /dev/null +++ b/infra/charts/management-service/templates/service-xp.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ template "xp.fullname" .}} + namespace: {{ .Release.Namespace }} + labels: + app: {{ template "xp.fullname" .}} + chart: {{ template "xp.chart" .}} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{ if .Values.xpApi.labels -}} +{{ toYaml .Values.xpApi.labels | indent 4 -}} +{{- end }} +spec: + type: ClusterIP + ports: + - port: {{ .Values.xpApi.service.externalPort }} + targetPort: {{ .Values.xpApi.service.internalPort }} + protocol: TCP + selector: + app: {{ template "xp.name" .}} + release: {{ .Release.Name }} diff --git a/infra/charts/management-service/templates/serviceaccount.yaml b/infra/charts/management-service/templates/serviceaccount.yaml new file mode 100644 index 00000000..a854c7cd --- /dev/null +++ b/infra/charts/management-service/templates/serviceaccount.yaml @@ -0,0 +1,12 @@ +{{- if .Values.xpApi.serviceAccount.create -}} +apiVersion: v1 +kind: ServiceAccount +metadata: + name: {{ include "xp.serviceAccountName" . }} + labels: + {{- include "xp.labels" . | nindent 4 }} + {{- with .Values.xpApi.serviceAccount.annotations }} + annotations: + {{- toYaml . | nindent 4 }} + {{- end }} +{{- end }} diff --git a/infra/charts/management-service/values.yaml b/infra/charts/management-service/values.yaml new file mode 100644 index 00000000..a96d2a90 --- /dev/null +++ b/infra/charts/management-service/values.yaml @@ -0,0 +1,137 @@ +xpApi: + image: + # -- Docker registry for XP API image + registry: docker.io/ + # -- Docker image repository for XP API + repository: xp-management + # -- Docker image tag for XP API + tag: latest + # -- Docker image pull policy + pullPolicy: IfNotPresent + + labels: {} + replicaCount: 1 + + # -- Resources requests and limits for XP API. This should be set + # according to your cluster capacity and service level objectives. + # Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + resources: {} + + livenessProbe: + # -- HTTP path for liveness check + path: "/v1/internal/live" + # -- Liveness probe delay and thresholds + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + + readinessProbe: + # -- HTTP path for readiness check + path: "/v1/internal/ready" + # -- Liveness probe delay and thresholds + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + + service: + # -- XP API Kubernetes service port number + externalPort: 8080 + # -- XP API container port number + internalPort: 8080 + + ingress: + # -- Enable ingress to provision Ingress resource for external access to XP API + enabled: false + # -- Set host value to enable name based virtual hosting. This allows routing + # HTTP traffic to multiple host names at the same IP address. If no host is + # specified, the ingress rule applies to all inbound HTTP traffic through + # the IP address specified. + # https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting + host: "" + # -- Ingress class annotation to add to this Ingress rule, + # useful when there are multiple ingress controllers installed + class: "" + + # -- XP API server configuration. + config: {} + + # -- XP UI configuration. + uiConfig: + apiConfig: + xpApiUrl: /api/xp/v1 + mlpApiUrl: /api/v1 + appConfig: + docsUrl: + - label: XP User Guide + href: https://github.com/gojek/xp/tree/main/docs + authConfig: + oauthClientId: "" + sentryConfig: { } + + # -- List of string containing additional XP API server arguments. For + # example, multiple "-config" can be specified to use multiple config files + extraArgs: [] + # Example + # - --config=/etc/secrets/experiment.yaml + # - --config=/etc/secrets/database.yaml + + # -- List of extra environment variables to add to XP API server container + extraEnvs: [] + # # Example + # - name: DEMO_GREETING + # value: "Hello from the environment" + + # -- List of extra labels to add to XP API K8s resources + extraLabels: {} + + # -- Extra volumes to attach to the Pod. For example, you can mount + # additional secrets to these volumes + extraVolumes: [] + # # Example + # - name: varlog + # emptyDir: {} + + # -- Extra volume mounts to attach to XP API server container. For example + # to mount the extra volume containing secrets + extraVolumeMounts: [] + # # Example + # - name: varlog + # mountPath: /var/log + + serviceAccount: + # Specifies whether a service account should be created + create: true + # Annotations to add to the service account + annotations: {} + # The name of the service account to use. + # If not set and create is true, a name is generated using the fullname template + name: "" + + sentry: + enabled: false + # -- Sentry DSN value used by both XP API and XP UI + dsn: "" + +global: + sentry: + # -- (string) Global Sentry DSN value + dsn: + + mlp: + encryption: + # -- (string) Global MLP Encryption Key to be used by all MLP components + key: + +swaggerUi: + # -- Docker tag for Swagger UI https://hub.docker.com/r/swaggerapi/swagger-ui + image: + tag: v3.47.1 + # -- URL of API server + apiServer: http://127.0.0.1/v1 + service: + # -- Swagger UI container port number + internalPort: 8081 + # -- Swagger UI Kubernetes service port number + externalPort: 8080 diff --git a/infra/charts/treatment-service/Chart.yaml b/infra/charts/treatment-service/Chart.yaml new file mode 100644 index 00000000..2f60e0ab --- /dev/null +++ b/infra/charts/treatment-service/Chart.yaml @@ -0,0 +1,5 @@ +apiVersion: v1 +appVersion: "0.0.1" +name: xp-treatment +description: A Helm chart for Kubernetes Deployment of the XP Treatment Service +version: 0.0.1 diff --git a/infra/charts/treatment-service/README.md b/infra/charts/treatment-service/README.md new file mode 100644 index 00000000..5b7fe32a --- /dev/null +++ b/infra/charts/treatment-service/README.md @@ -0,0 +1,97 @@ +# xp-treatment + +--- +![Version: 0.0.1](https://img.shields.io/badge/Version-0.0.1-informational?style=flat-square) +![AppVersion: 0.0.1](https://img.shields.io/badge/AppVersion-0.0.1-informational?style=flat-square) + +A Helm chart for Kubernetes Deployment of the XP Treatment Service + +## Introduction + +This Helm chart installs [Treatment Service](https://github.com/gojek/xp/treatment-service) and all its dependencies in a Kubernetes cluster. + +## Prerequisites + +To use the charts here, [Helm](https://helm.sh/) must be configured for your +Kubernetes cluster. Setting up Kubernetes and Helm is outside the scope of +this README. Please refer to the Kubernetes and Helm documentation. + +- **Helm 3.0+** – This chart was tested with Helm v3.7.1, but it is also expected to work with earlier Helm versions +- **Kubernetes 1.18+** – This chart was tested with GKE v1.20.x, but it's possible it works with earlier k8s versions too. + +## Installation + +### Add Helm repository + +```sh +$ helm repo add xp https://turing-ml.github.io/charts +``` + +### Installing the chart + +This command will install XP Treatment Service release named `treatment-service` in the `default` namespace. +Default chart values will be used for the installation: +```shell +$ helm install xp xp/treatment-service +``` + +You can (and most likely, should) override the default configuration with values suitable for your installation. +Refer to [Configuration](#configuration) section for the detailed description of available configuration keys. + +You can also refer to [values.minimal.yaml](./values.minimal.yaml) to check a minimal configuration that needs +to be provided for XP Treatment Service installation. + +### Uninstalling the chart + +To uninstall `treatment-service` release: +```shell +$ helm uninstall treatment-service +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release, +except for postgresql PVC, those will have to be removed manually. + +## Configuration + +The following table lists the configurable parameters of the XP Treatment Service chart and their default values. + +| Key | Type | Default | Description | +|-----|------|---------|-------------| +| swaggerUi.apiServer | string | `"http://127.0.0.1/v1"` | URL of API server | +| swaggerUi.enabled | bool | `false` | | +| swaggerUi.image | object | `{"tag":"v3.47.1"}` | Docker tag for Swagger UI https://hub.docker.com/r/swaggerapi/swagger-ui | +| swaggerUi.service.externalPort | int | `8080` | Swagger UI Kubernetes service port number | +| swaggerUi.service.internalPort | int | `8081` | Swagger UI container port number | +| xpTreatment.autoscaling.enabled | bool | `false` | | +| xpTreatment.autoscaling.maxReplicas | int | `2` | | +| xpTreatment.autoscaling.minReplicas | int | `1` | | +| xpTreatment.autoscaling.targetCPUUtilizationPercentage | int | `80` | | +| xpTreatment.autoscaling.targetMemoryUtilizationPercentage | int | `80` | | +| xpTreatment.extraEnvs | list | `[]` | List of extra environment variables to add to XP Treatment Service server container | +| xpTreatment.extraLabels | object | `{}` | List of extra labels to add to XP Treatment Service K8s resources | +| xpTreatment.extraVolumeMounts | list | `[]` | Extra volume mounts to attach to XP Treatment Service server container. For example to mount the extra volume containing secrets | +| xpTreatment.extraVolumes | list | `[]` | Extra volumes to attach to the Pod. For example, you can mount additional secrets to these volumes | +| xpTreatment.image.pullPolicy | string | `"IfNotPresent"` | Docker image pull policy | +| xpTreatment.image.registry | string | `"docker.io/"` | Docker registry for XP Treatment Service image | +| xpTreatment.image.repository | string | `"xp-treatment"` | Docker image repository for XP Treatment Service | +| xpTreatment.image.tag | string | `"latest"` | Docker image tag for XP Treatment Service | +| xpTreatment.ingress.class | string | `""` | Ingress class annotation to add to this Ingress rule, useful when there are multiple ingress controllers installed | +| xpTreatment.ingress.enabled | bool | `false` | Enable ingress to provision Ingress resource for external access to XP Treatment Service | +| xpTreatment.ingress.host | string | `""` | Set host value to enable name based virtual hosting. This allows routing HTTP traffic to multiple host names at the same IP address. If no host is specified, the ingress rule applies to all inbound HTTP traffic through the IP address specified. https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting | +| xpTreatment.labels | object | `{}` | | +| xpTreatment.livenessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | +| xpTreatment.livenessProbe.path | string | `"/v1/internal/health/live"` | HTTP path for liveness check | +| xpTreatment.livenessProbe.periodSeconds | int | `10` | | +| xpTreatment.livenessProbe.successThreshold | int | `1` | | +| xpTreatment.livenessProbe.timeoutSeconds | int | `5` | | +| xpTreatment.nodeSelector | object | `{}` | | +| xpTreatment.readinessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | +| xpTreatment.readinessProbe.path | string | `"/v1/internal/health/ready"` | HTTP path for readiness check | +| xpTreatment.readinessProbe.periodSeconds | int | `10` | | +| xpTreatment.readinessProbe.successThreshold | int | `1` | | +| xpTreatment.readinessProbe.timeoutSeconds | int | `5` | | +| xpTreatment.replicaCount | int | `1` | | +| xpTreatment.resources | object | `{}` | Resources requests and limits for XP Treatment Service. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | +| xpTreatment.service.externalPort | int | `8080` | XP API Kubernetes service port number | +| xpTreatment.service.internalPort | int | `8080` | XP API container port number | +| xpTreatment.service.type | string | `"ClusterIP"` | | diff --git a/infra/charts/treatment-service/README.md.gotmpl b/infra/charts/treatment-service/README.md.gotmpl new file mode 100644 index 00000000..0586547a --- /dev/null +++ b/infra/charts/treatment-service/README.md.gotmpl @@ -0,0 +1,57 @@ +{{ template "chart.header" . }} +--- +{{ template "chart.versionBadge" . }} +{{ template "chart.appVersionBadge" . }} + +{{ template "chart.description" . }} + +## Introduction + +This Helm chart installs [Treatment Service](https://github.com/gojek/xp/treatment-service) and all its dependencies in a Kubernetes cluster. + +## Prerequisites + +To use the charts here, [Helm](https://helm.sh/) must be configured for your +Kubernetes cluster. Setting up Kubernetes and Helm is outside the scope of +this README. Please refer to the Kubernetes and Helm documentation. + +- **Helm 3.0+** – This chart was tested with Helm v3.7.1, but it is also expected to work with earlier Helm versions +- **Kubernetes 1.18+** – This chart was tested with GKE v1.20.x, but it's possible it works with earlier k8s versions too. + +## Installation + +### Add Helm repository + +```sh +$ helm repo add xp https://turing-ml.github.io/charts +``` + +### Installing the chart + +This command will install XP Treatment Service release named `treatment-service` in the `default` namespace. +Default chart values will be used for the installation: +```shell +$ helm install xp xp/treatment-service +``` + +You can (and most likely, should) override the default configuration with values suitable for your installation. +Refer to [Configuration](#configuration) section for the detailed description of available configuration keys. + +You can also refer to [values.minimal.yaml](./values.minimal.yaml) to check a minimal configuration that needs +to be provided for XP Treatment Service installation. + +### Uninstalling the chart + +To uninstall `treatment-service` release: +```shell +$ helm uninstall treatment-service +``` + +The command removes all the Kubernetes components associated with the chart and deletes the release, +except for postgresql PVC, those will have to be removed manually. + +## Configuration + +The following table lists the configurable parameters of the XP Treatment Service chart and their default values. + +{{ template "chart.valuesTable" . }} diff --git a/infra/charts/treatment-service/templates/_helpers.tpl b/infra/charts/treatment-service/templates/_helpers.tpl new file mode 100644 index 00000000..ca41813a --- /dev/null +++ b/infra/charts/treatment-service/templates/_helpers.tpl @@ -0,0 +1,54 @@ +{{/* +Expand the name of the chart. +*/}} +{{- define "xp.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). +If release name contains chart name it will be used as a full name. +*/}} +{{- define "xp.fullname" -}} +{{- if .Values.fullnameOverride }} +{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- $name := default .Chart.Name .Values.nameOverride }} +{{- if contains $name .Release.Name }} +{{- .Release.Name | trunc 63 | trimSuffix "-" }} +{{- else }} +{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }} +{{- end }} +{{- end }} +{{- end }} + +{{/* +Create chart name and version as used by the chart label. +*/}} +{{- define "xp.chart" -}} +{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }} +{{- end }} + +{{/* +Common labels +*/}} +{{- define "xp.labels" -}} +helm.sh/chart: {{ include "xp.chart" . }} +{{- with .Values.xpTreatment.extraLabels }} +{{- toYaml . | nindent 0 }} +{{- end }} +{{ include "xp.selectorLabels" . }} +{{- if .Chart.AppVersion }} +app.kubernetes.io/version: {{ .Chart.AppVersion | quote }} +{{- end }} +app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- end }} + +{{/* +Selector labels +*/}} +{{- define "xp.selectorLabels" -}} +app.kubernetes.io/name: {{ include "xp.fullname" . }} +app.kubernetes.io/instance: {{ .Release.Name }} +{{- end }} diff --git a/infra/charts/treatment-service/templates/deployment.yaml b/infra/charts/treatment-service/templates/deployment.yaml new file mode 100644 index 00000000..8cbdb3fb --- /dev/null +++ b/infra/charts/treatment-service/templates/deployment.yaml @@ -0,0 +1,136 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: {{ include "xp.fullname" . }} + labels: + {{- include "xp.labels" . | nindent 4 }} +spec: + replicas: {{ .Values.xpTreatment.replicaCount }} + selector: + matchLabels: + app: {{ template "xp.name" . }} + release: {{ .Release.Name }} + strategy: + type: RollingUpdate + rollingUpdate: + maxUnavailable: 0 + template: + metadata: + labels: + app: {{ template "xp.name" . }} + release: {{ .Release.Name }} + {{- include "xp.labels" . | nindent 8 }} + {{- with .Values.xpTreatment.annotations }} + annotations: + {{- toYaml . | nindent 8 }} + {{- end }} + spec: + {{- with .Values.xpTreatment.imagePullSecrets }} + imagePullSecrets: + {{- toYaml . | nindent 8 }} + {{- end }} + containers: + - name: xp-treatment + image: "{{ .Values.xpTreatment.image.registry }}{{ .Values.xpTreatment.image.repository }}:{{ .Values.xpTreatment.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.xpTreatment.image.pullPolicy }} + env: + {{- with .Values.xpTreatment.extraEnvs }} + {{- toYaml . | nindent 12 }} + {{- end }} + ports: + - name: http + containerPort: 8080 + protocol: TCP + livenessProbe: + httpGet: + path: {{ .Values.xpTreatment.livenessProbe.path }} + port: {{ .Values.xpTreatment.service.internalPort }} + scheme: HTTP + initialDelaySeconds: {{ .Values.xpTreatment.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.xpTreatment.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.xpTreatment.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.xpTreatment.livenessProbe.timeoutSeconds }} + readinessProbe: + httpGet: + path: {{ .Values.xpTreatment.readinessProbe.path }} + port: {{ .Values.xpTreatment.service.internalPort }} + scheme: HTTP + initialDelaySeconds: {{ .Values.xpTreatment.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.xpTreatment.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.xpTreatment.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.xpTreatment.readinessProbe.timeoutSeconds }} + resources: + {{- toYaml .Values.xpTreatment.resources | nindent 12 }} + # Give time for running pods to terminate existing connection before letting + # Kubernetes terminate the pods. + # https://blog.sebastian-daschner.com/entries/zero-downtime-updates-kubernetes + lifecycle: + preStop: + exec: + command: ["/bin/bash", "-c", "sleep 15"] + args: + - serve + - --config=/etc/xp/config.yaml + {{- with .Values.xpTreatment.extraArgs }} + {{- toYaml . | nindent 8 }} + {{- end }} + volumeMounts: + - name: config + mountPath: /etc/xp + {{- with .Values.xpTreatment.extraVolumeMounts }} + {{- toYaml . | nindent 8 }} + {{- end }} + {{- if .Values.swaggerUi.enabled }} + - name: swagger-ui + image: "swaggerapi/swagger-ui:{{ .Values.swaggerUi.image.tag }}" + imagePullPolicy: IfNotPresent + ports: + - containerPort: {{ .Values.swaggerUi.service.internalPort }} + resources: + requests: + cpu: 100m + memory: 64Mi + limits: + cpu: 500m + memory: 128Mi + env: + - name: LAYOUT + value: "BaseLayout" + - name: SWAGGER_JSON + value: "/app/treatment.yaml" + - name: PORT + value: "{{ .Values.swaggerUi.service.internalPort }}" + - name: API_SERVER + value: "{{ .Values.swaggerUi.apiServer }}" + command: ["sh", "-c"] + args: + - | + mkdir /app + export LOCAL_API_SERVER="http://127.0.0.1:{{ .Values.xpTreatment.service.internalPort }}" + echo "Fetching swagger configuration from ${LOCAL_API_SERVER}/treatment.yaml..." + until $$(wget -O $${SWAGGER_JSON} --tries 1 --timeout 1 ${LOCAL_API_SERVER}/treatment.yaml); do + printf '.' + sleep 10 + done + echo "Fetching swagger configuration from ${LOCAL_API_SERVER}/schema.yaml..." + until $$(wget -O /app/schema.yaml --tries 1 --timeout 1 ${LOCAL_API_SERVER}/schema.yaml); do + printf '.' + sleep 10 + done + echo "Update Swagger config..." + sed -r -i 's%^((\s*)-(\s*)url\s*:).*$$%\1 "'$${API_SERVER}'"%' $${SWAGGER_JSON} + echo "Running Swagger UI..." + /usr/share/nginx/run.sh + {{- end }} + volumes: + - name: config + secret: + secretName: {{ template "xp.fullname" .}}-config + {{- with .Values.xpTreatment.extraVolumes }} + {{- toYaml . | nindent 6 }} + {{- end }} + +{{- if .Values.xpTreatment.nodeSelector }} + nodeSelector: +{{ toYaml .Values.xpTreatment.nodeSelector | nindent 8 }} +{{ end -}} diff --git a/infra/charts/treatment-service/templates/hpa.yaml b/infra/charts/treatment-service/templates/hpa.yaml new file mode 100644 index 00000000..e002200b --- /dev/null +++ b/infra/charts/treatment-service/templates/hpa.yaml @@ -0,0 +1,32 @@ +{{- if .Values.xpTreatment.autoscaling.enabled }} +apiVersion: autoscaling/v2beta2 +kind: HorizontalPodAutoscaler +metadata: + name: {{ include "xp.fullname" . }} + labels: + {{- include "xp.labels" . | nindent 4 }} +spec: + scaleTargetRef: + apiVersion: apps/v1 + kind: Deployment + name: {{ include "xp.fullname" . }} + minReplicas: {{ .Values.xpTreatment.autoscaling.minReplicas }} + maxReplicas: {{ .Values.xpTreatment.autoscaling.maxReplicas }} + metrics: + {{- if .Values.xpTreatment.autoscaling.targetCPUUtilizationPercentage }} + - type: Resource + resource: + name: cpu + target: + type: Utilization + averageUtilization: {{ .Values.xpTreatment.autoscaling.targetCPUUtilizationPercentage }} + {{- end }} + {{- if .Values.xpTreatment.autoscaling.targetMemoryUtilizationPercentage }} + - type: Resource + resource: + name: memory + target: + type: Utilization + averageUtilization: {{ .Values.xpTreatment.autoscaling.targetMemoryUtilizationPercentage }} + {{- end }} +{{- end }} diff --git a/infra/charts/treatment-service/templates/ingress.yaml b/infra/charts/treatment-service/templates/ingress.yaml new file mode 100644 index 00000000..d6db030b --- /dev/null +++ b/infra/charts/treatment-service/templates/ingress.yaml @@ -0,0 +1,33 @@ +{{- if .Values.xpTreatment.ingress.enabled }} +apiVersion: extensions/v1beta1 +kind: Ingress +metadata: + name: {{ template "xp.fullname" .}} + namespace: {{ .Release.Namespace }} + annotations: + {{- with .Values.xpTreatment.ingress.class }} + ingress.class: {{ . }} + {{- end }} + labels: + app: {{ include "xp.fullname" . }} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} + helm.sh/chart: {{ include "xp.chart" . }} + app.kubernetes.io/name: {{ include "xp.fullname" . }} + app.kubernetes.io/instance: {{ .Release.Name }} + app.kubernetes.io/managed-by: {{ .Release.Service }} +{{- if .Values.xpTreatment.labels }} +{{ toYaml .Values.xpTreatment.labels | indent 4 }} +{{- end }} +spec: + rules: + - {{- with .Values.xpTreatment.ingress.host }} + host: {{ . }} + {{- end }} + http: + paths: + - path: / + backend: + serviceName: {{ template "xp.fullname" .}} + servicePort: {{ .Values.xpTreatment.service.externalPort }} +{{- end }} diff --git a/infra/charts/treatment-service/templates/secrets.yaml b/infra/charts/treatment-service/templates/secrets.yaml new file mode 100644 index 00000000..e8745645 --- /dev/null +++ b/infra/charts/treatment-service/templates/secrets.yaml @@ -0,0 +1,8 @@ +apiVersion: v1 +kind: Secret +metadata: + namespace: {{ .Release.Namespace }} + name: {{ template "xp.fullname" .}}-config +stringData: + config.yaml: | + {{- toYaml .Values.xpTreatment.config | nindent 4 -}} diff --git a/infra/charts/treatment-service/templates/service-swagger.yaml b/infra/charts/treatment-service/templates/service-swagger.yaml new file mode 100644 index 00000000..1223ab71 --- /dev/null +++ b/infra/charts/treatment-service/templates/service-swagger.yaml @@ -0,0 +1,24 @@ +{{- if .Values.swaggerUi.enabled }} +apiVersion: v1 +kind: Service +metadata: + name: {{ include "xp.fullname" . }}-swagger + namespace: {{ .Release.Namespace }} + labels: + app: {{ template "xp.fullname" .}} + chart: {{ template "xp.chart" .}} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{ if .Values.xpTreatment.labels -}} +{{ toYaml .Values.xpTreatment.labels | indent 4 -}} +{{- end }} +spec: + type: {{ .Values.swaggerUi.service.type }} + ports: + - port: {{ .Values.swaggerUi.service.externalPort }} + targetPort: {{ .Values.swaggerUi.service.internalPort }} + protocol: TCP + selector: + app: {{ template "xp.fullname" .}} + release: {{ .Release.Name }} +{{- end }} diff --git a/infra/charts/treatment-service/templates/service-xp.yaml b/infra/charts/treatment-service/templates/service-xp.yaml new file mode 100644 index 00000000..a1b7a2b3 --- /dev/null +++ b/infra/charts/treatment-service/templates/service-xp.yaml @@ -0,0 +1,22 @@ +apiVersion: v1 +kind: Service +metadata: + name: {{ include "xp.fullname" . }} + namespace: {{ .Release.Namespace }} + labels: + app: {{ template "xp.fullname" .}} + chart: {{ template "xp.chart" .}} + release: {{ .Release.Name }} + heritage: {{ .Release.Service }} +{{ if .Values.xpTreatment.labels -}} +{{ toYaml .Values.xpTreatment.labels | indent 4 -}} +{{- end }} +spec: + type: {{ .Values.xpTreatment.service.type }} + ports: + - port: {{ .Values.xpTreatment.service.externalPort }} + targetPort: {{ .Values.xpTreatment.service.internalPort }} + protocol: TCP + selector: + app: {{ template "xp.name" .}} + release: {{ .Release.Name }} diff --git a/infra/charts/treatment-service/values.yaml b/infra/charts/treatment-service/values.yaml new file mode 100644 index 00000000..7871ad57 --- /dev/null +++ b/infra/charts/treatment-service/values.yaml @@ -0,0 +1,98 @@ +xpTreatment: + image: + # -- Docker registry for XP Treatment Service image + registry: docker.io/ + # -- Docker image repository for XP Treatment Service + repository: xp-treatment + # -- Docker image tag for XP Treatment Service + tag: latest + # -- Docker image pull policy + pullPolicy: IfNotPresent + + labels: {} + replicaCount: 1 + + # -- Resources requests and limits for XP Treatment Service. This should be set + # according to your cluster capacity and service level objectives. + # Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ + resources: {} + + livenessProbe: + # -- HTTP path for liveness check + path: "/v1/internal/health/live" + # -- Liveness probe delay and thresholds + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + + readinessProbe: + # -- HTTP path for readiness check + path: "/v1/internal/health/ready" + # -- Liveness probe delay and thresholds + initialDelaySeconds: 60 + periodSeconds: 10 + successThreshold: 1 + timeoutSeconds: 5 + + service: + type: ClusterIP + # -- XP API Kubernetes service port number + externalPort: 8080 + # -- XP API container port number + internalPort: 8080 + + ingress: + # -- Enable ingress to provision Ingress resource for external access to XP Treatment Service + enabled: false + # -- Set host value to enable name based virtual hosting. This allows routing + # HTTP traffic to multiple host names at the same IP address. If no host is + # specified, the ingress rule applies to all inbound HTTP traffic through + # the IP address specified. + # https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting + host: "" + # -- Ingress class annotation to add to this Ingress rule, + # useful when there are multiple ingress controllers installed + class: "" + + # -- List of extra environment variables to add to XP Treatment Service server container + extraEnvs: [] + + # -- List of extra labels to add to XP Treatment Service K8s resources + extraLabels: {} + + # -- Extra volumes to attach to the Pod. For example, you can mount + # additional secrets to these volumes + extraVolumes: [] + # # Example + # - name: varlog + # emptyDir: {} + + # -- Extra volume mounts to attach to XP Treatment Service server container. For example + # to mount the extra volume containing secrets + extraVolumeMounts: [] + # # Example + # - name: varlog + # mountPath: /var/log + + nodeSelector: {} + + autoscaling: + enabled: false + minReplicas: 1 + maxReplicas: 2 + targetCPUUtilizationPercentage: 80 + targetMemoryUtilizationPercentage: 80 + +swaggerUi: + enabled: false + # -- Docker tag for Swagger UI https://hub.docker.com/r/swaggerapi/swagger-ui + image: + tag: v3.47.1 + # -- URL of API server + apiServer: http://127.0.0.1/v1 + service: + # -- Swagger UI container port number + internalPort: 8081 + # -- Swagger UI Kubernetes service port number + externalPort: 8080 From 1ca5ac52c661b0dcd9a97be15dfa56313b64d92c Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 13:22:58 +0800 Subject: [PATCH 02/17] Rename management service helm chart values --- infra/charts/management-service/README.md | 68 +++++++++---------- .../management-service/templates/_helpers.tpl | 26 +++---- .../templates/deployment.yaml | 46 ++++++------- .../management-service/templates/ingress.yaml | 12 ++-- .../management-service/templates/secrets.yaml | 4 +- .../templates/service-swagger.yaml | 4 +- .../templates/service-xp.yaml | 8 +-- .../templates/serviceaccount.yaml | 4 +- infra/charts/management-service/values.yaml | 4 +- 9 files changed, 88 insertions(+), 88 deletions(-) diff --git a/infra/charts/management-service/README.md b/infra/charts/management-service/README.md index a99ae228..77834ba9 100644 --- a/infra/charts/management-service/README.md +++ b/infra/charts/management-service/README.md @@ -63,37 +63,37 @@ The following table lists the configurable parameters of the XP Management Servi | swaggerUi.image | object | `{"tag":"v3.47.1"}` | Docker tag for Swagger UI https://hub.docker.com/r/swaggerapi/swagger-ui | | swaggerUi.service.externalPort | int | `8080` | Swagger UI Kubernetes service port number | | swaggerUi.service.internalPort | int | `8081` | Swagger UI container port number | -| xpApi.config | object | `{}` | XP API server configuration. | -| xpApi.extraArgs | list | `[]` | List of string containing additional XP API server arguments. For example, multiple "-config" can be specified to use multiple config files | -| xpApi.extraEnvs | list | `[]` | List of extra environment variables to add to XP API server container | -| xpApi.extraLabels | object | `{}` | List of extra labels to add to XP API K8s resources | -| xpApi.extraVolumeMounts | list | `[]` | Extra volume mounts to attach to XP API server container. For example to mount the extra volume containing secrets | -| xpApi.extraVolumes | list | `[]` | Extra volumes to attach to the Pod. For example, you can mount additional secrets to these volumes | -| xpApi.image.pullPolicy | string | `"IfNotPresent"` | Docker image pull policy | -| xpApi.image.registry | string | `"docker.io/"` | Docker registry for XP API image | -| xpApi.image.repository | string | `"xp-management"` | Docker image repository for XP API | -| xpApi.image.tag | string | `"latest"` | Docker image tag for XP API | -| xpApi.ingress.class | string | `""` | Ingress class annotation to add to this Ingress rule, useful when there are multiple ingress controllers installed | -| xpApi.ingress.enabled | bool | `false` | Enable ingress to provision Ingress resource for external access to XP API | -| xpApi.ingress.host | string | `""` | Set host value to enable name based virtual hosting. This allows routing HTTP traffic to multiple host names at the same IP address. If no host is specified, the ingress rule applies to all inbound HTTP traffic through the IP address specified. https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting | -| xpApi.labels | object | `{}` | | -| xpApi.livenessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | -| xpApi.livenessProbe.path | string | `"/v1/internal/live"` | HTTP path for liveness check | -| xpApi.livenessProbe.periodSeconds | int | `10` | | -| xpApi.livenessProbe.successThreshold | int | `1` | | -| xpApi.livenessProbe.timeoutSeconds | int | `5` | | -| xpApi.readinessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | -| xpApi.readinessProbe.path | string | `"/v1/internal/ready"` | HTTP path for readiness check | -| xpApi.readinessProbe.periodSeconds | int | `10` | | -| xpApi.readinessProbe.successThreshold | int | `1` | | -| xpApi.readinessProbe.timeoutSeconds | int | `5` | | -| xpApi.replicaCount | int | `1` | | -| xpApi.resources | object | `{}` | Resources requests and limits for XP API. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | -| xpApi.sentry.dsn | string | `""` | Sentry DSN value used by both XP API and XP UI | -| xpApi.sentry.enabled | bool | `false` | | -| xpApi.service.externalPort | int | `8080` | XP API Kubernetes service port number | -| xpApi.service.internalPort | int | `8080` | XP API container port number | -| xpApi.serviceAccount.annotations | object | `{}` | | -| xpApi.serviceAccount.create | bool | `true` | | -| xpApi.serviceAccount.name | string | `""` | | -| xpApi.uiConfig | object | `{"apiConfig":{"mlpApiUrl":"/api/v1","xpApiUrl":"/api/xp/v1"},"appConfig":{"docsUrl":[{"href":"https://github.com/gojek/xp/tree/main/docs","label":"XP User Guide"}]},"authConfig":{"oauthClientId":""},"sentryConfig":{}}` | XP UI configuration. | +| xpManagement.apiConfig | object | `{}` | XP API server configuration. | +| xpManagement.extraArgs | list | `[]` | List of string containing additional XP API server arguments. For example, multiple "-config" can be specified to use multiple config files | +| xpManagement.extraEnvs | list | `[]` | List of extra environment variables to add to XP API server container | +| xpManagement.extraLabels | object | `{}` | List of extra labels to add to XP API K8s resources | +| xpManagement.extraVolumeMounts | list | `[]` | Extra volume mounts to attach to XP API server container. For example to mount the extra volume containing secrets | +| xpManagement.extraVolumes | list | `[]` | Extra volumes to attach to the Pod. For example, you can mount additional secrets to these volumes | +| xpManagement.image.pullPolicy | string | `"IfNotPresent"` | Docker image pull policy | +| xpManagement.image.registry | string | `"docker.io/"` | Docker registry for XP API image | +| xpManagement.image.repository | string | `"xp-management"` | Docker image repository for XP API | +| xpManagement.image.tag | string | `"latest"` | Docker image tag for XP API | +| xpManagement.ingress.class | string | `""` | Ingress class annotation to add to this Ingress rule, useful when there are multiple ingress controllers installed | +| xpManagement.ingress.enabled | bool | `false` | Enable ingress to provision Ingress resource for external access to XP API | +| xpManagement.ingress.host | string | `""` | Set host value to enable name based virtual hosting. This allows routing HTTP traffic to multiple host names at the same IP address. If no host is specified, the ingress rule applies to all inbound HTTP traffic through the IP address specified. https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting | +| xpManagement.labels | object | `{}` | | +| xpManagement.livenessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | +| xpManagement.livenessProbe.path | string | `"/v1/internal/live"` | HTTP path for liveness check | +| xpManagement.livenessProbe.periodSeconds | int | `10` | | +| xpManagement.livenessProbe.successThreshold | int | `1` | | +| xpManagement.livenessProbe.timeoutSeconds | int | `5` | | +| xpManagement.readinessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | +| xpManagement.readinessProbe.path | string | `"/v1/internal/ready"` | HTTP path for readiness check | +| xpManagement.readinessProbe.periodSeconds | int | `10` | | +| xpManagement.readinessProbe.successThreshold | int | `1` | | +| xpManagement.readinessProbe.timeoutSeconds | int | `5` | | +| xpManagement.replicaCount | int | `1` | | +| xpManagement.resources | object | `{}` | Resources requests and limits for XP API. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | +| xpManagement.sentry.dsn | string | `""` | Sentry DSN value used by both XP API and XP UI | +| xpManagement.sentry.enabled | bool | `false` | | +| xpManagement.service.externalPort | int | `8080` | XP API Kubernetes service port number | +| xpManagement.service.internalPort | int | `8080` | XP API container port number | +| xpManagement.serviceAccount.annotations | object | `{}` | | +| xpManagement.serviceAccount.create | bool | `true` | | +| xpManagement.serviceAccount.name | string | `""` | | +| xpManagement.uiConfig | object | `{"apiConfig":{"mlpApiUrl":"/api/v1","xpApiUrl":"/api/xp/v1"},"appConfig":{"docsUrl":[{"href":"https://github.com/gojek/xp/tree/main/docs","label":"XP User Guide"}]},"authConfig":{"oauthClientId":""},"sentryConfig":{}}` | XP UI configuration. | diff --git a/infra/charts/management-service/templates/_helpers.tpl b/infra/charts/management-service/templates/_helpers.tpl index c5ae5ac7..089f94ca 100644 --- a/infra/charts/management-service/templates/_helpers.tpl +++ b/infra/charts/management-service/templates/_helpers.tpl @@ -31,7 +31,7 @@ Create chart name and version as used by the chart label. {{- end }} {{- define "xp.environment" -}} -{{- .Values.global.environment | default .Values.xpApi.environment | default "dev" -}} +{{- .Values.global.environment | default .Values.xpManagement.environment | default "dev" -}} {{- end -}} {{/* @@ -39,7 +39,7 @@ Common labels */}} {{- define "xp.labels" -}} helm.sh/chart: {{ include "xp.chart" . }} -{{- with .Values.xpApi.extraLabels }} +{{- with .Values.xpManagement.extraLabels }} {{- toYaml . | nindent 0 }} {{- end }} {{ include "xp.selectorLabels" . }} @@ -61,36 +61,36 @@ app.kubernetes.io/instance: {{ .Release.Name }} Create the name of the service account to use */}} {{- define "xp.serviceAccountName" -}} -{{- if .Values.xpApi.serviceAccount.create }} -{{- default (include "xp.fullname" .) .Values.xpApi.serviceAccount.name }} +{{- if .Values.xpManagement.serviceAccount.create }} +{{- default (include "xp.fullname" .) .Values.xpManagement.serviceAccount.name }} {{- else }} -{{- default "default" .Values.xpApi.serviceAccount.name }} +{{- default "default" .Values.xpManagement.serviceAccount.name }} {{- end }} {{- end }} {{- define "xp.sentry.enabled" -}} -{{ eq (.Values.xpApi.config.SentryConfig.Enabled | toString) "true" }} +{{ eq (.Values.xpManagement.apiConfig.SentryConfig.Enabled | toString) "true" }} {{- end -}} {{- define "xp.sentry.dsn" -}} -{{- .Values.global.sentry.dsn | default .Values.xpApi.sentry.dsn -}} +{{- .Values.global.sentry.dsn | default .Values.xpManagement.sentry.dsn -}} {{- end -}} {{- define "xp.ui.defaultConfig" -}} -{{- if .Values.xpApi.uiConfig -}} +{{- if .Values.xpManagement.uiConfig -}} appConfig: - environment: {{ .Values.xpApi.uiConfig.appConfig.environment | default (include "xp.environment" .) }} + environment: {{ .Values.xpManagement.uiConfig.appConfig.environment | default (include "xp.environment" .) }} authConfig: - oauthClientId: {{ .Values.global.oauthClientId | default .Values.xpApi.uiConfig.authConfig.oauthClientId | quote }} + oauthClientId: {{ .Values.global.oauthClientId | default .Values.xpManagement.uiConfig.authConfig.oauthClientId | quote }} {{- if (include "xp.sentry.enabled" .) }} sentryConfig: - environment: {{ .Values.xpApi.uiConfig.sentryConfig.environment | default (include "xp.environment" .) }} - dsn: {{ .Values.xpApi.uiConfig.sentryConfig.dsn | default (include "xp.sentry.dsn" .) | quote }} + environment: {{ .Values.xpManagement.uiConfig.sentryConfig.environment | default (include "xp.environment" .) }} + dsn: {{ .Values.xpManagement.uiConfig.sentryConfig.dsn | default (include "xp.sentry.dsn" .) | quote }} {{- end -}} {{- end -}} {{- end -}} {{- define "xp.ui.config" -}} {{- $defaultConfig := include "xp.ui.defaultConfig" . | fromYaml -}} -{{ .Values.xpApi.uiConfig | merge $defaultConfig | toPrettyJson }} +{{ .Values.xpManagement.uiConfig | merge $defaultConfig | toPrettyJson }} {{- end -}} diff --git a/infra/charts/management-service/templates/deployment.yaml b/infra/charts/management-service/templates/deployment.yaml index 0a2bff1f..665ad10f 100644 --- a/infra/charts/management-service/templates/deployment.yaml +++ b/infra/charts/management-service/templates/deployment.yaml @@ -5,7 +5,7 @@ metadata: labels: {{- include "xp.labels" . | nindent 4 }} spec: - replicas: {{ .Values.xpApi.replicaCount }} + replicas: {{ .Values.xpManagement.replicaCount }} selector: matchLabels: app: {{ template "xp.name" .}} @@ -21,17 +21,17 @@ spec: release: {{ .Release.Name }} {{- include "xp.labels" . | nindent 8 }} spec: - {{- with .Values.xpApi.imagePullSecrets }} + {{- with .Values.xpManagement.imagePullSecrets }} imagePullSecrets: {{- toYaml . | nindent 8 }} {{- end }} serviceAccountName: {{ include "xp.serviceAccountName" . }} containers: - name: api - image: "{{ .Values.xpApi.image.registry }}{{ .Values.xpApi.image.repository }}:{{ .Values.xpApi.image.tag | default .Chart.AppVersion }}" - imagePullPolicy: {{ .Values.xpApi.image.pullPolicy }} + image: "{{ .Values.xpManagement.image.registry }}{{ .Values.xpManagement.image.repository }}:{{ .Values.xpManagement.image.tag | default .Chart.AppVersion }}" + imagePullPolicy: {{ .Values.xpManagement.image.pullPolicy }} env: - {{- with .Values.xpApi.extraEnvs }} + {{- with .Values.xpManagement.extraEnvs }} {{- toYaml . | nindent 12 }} {{- end }} ports: @@ -40,24 +40,24 @@ spec: protocol: TCP livenessProbe: httpGet: - path: {{ .Values.xpApi.livenessProbe.path }} - port: {{ .Values.xpApi.service.internalPort }} + path: {{ .Values.xpManagement.livenessProbe.path }} + port: {{ .Values.xpManagement.service.internalPort }} scheme: HTTP - initialDelaySeconds: {{ .Values.xpApi.livenessProbe.initialDelaySeconds }} - periodSeconds: {{ .Values.xpApi.livenessProbe.periodSeconds }} - successThreshold: {{ .Values.xpApi.livenessProbe.successThreshold }} - timeoutSeconds: {{ .Values.xpApi.livenessProbe.timeoutSeconds }} + initialDelaySeconds: {{ .Values.xpManagement.livenessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.xpManagement.livenessProbe.periodSeconds }} + successThreshold: {{ .Values.xpManagement.livenessProbe.successThreshold }} + timeoutSeconds: {{ .Values.xpManagement.livenessProbe.timeoutSeconds }} readinessProbe: httpGet: - path: {{ .Values.xpApi.readinessProbe.path }} - port: {{ .Values.xpApi.service.internalPort }} + path: {{ .Values.xpManagement.readinessProbe.path }} + port: {{ .Values.xpManagement.service.internalPort }} scheme: HTTP - initialDelaySeconds: {{ .Values.xpApi.readinessProbe.initialDelaySeconds }} - periodSeconds: {{ .Values.xpApi.readinessProbe.periodSeconds }} - successThreshold: {{ .Values.xpApi.readinessProbe.successThreshold }} - timeoutSeconds: {{ .Values.xpApi.readinessProbe.timeoutSeconds }} + initialDelaySeconds: {{ .Values.xpManagement.readinessProbe.initialDelaySeconds }} + periodSeconds: {{ .Values.xpManagement.readinessProbe.periodSeconds }} + successThreshold: {{ .Values.xpManagement.readinessProbe.successThreshold }} + timeoutSeconds: {{ .Values.xpManagement.readinessProbe.timeoutSeconds }} resources: - {{- toYaml .Values.xpApi.resources | nindent 12 }} + {{- toYaml .Values.xpManagement.resources | nindent 12 }} # Give time for running pods to terminate existing connection before letting # Kubernetes terminate the pods. # https://blog.sebastian-daschner.com/entries/zero-downtime-updates-kubernetes @@ -68,17 +68,17 @@ spec: args: - serve - --config=/etc/xp/config.yaml - {{- if .Values.xpApi.uiConfig }} + {{- if .Values.xpManagement.uiConfig }} - -ui-config - /etc/xp/ui.config.json {{- end }} - {{- with .Values.xpApi.extraArgs }} + {{- with .Values.xpManagement.extraArgs }} {{- toYaml . | nindent 8 }} {{- end }} volumeMounts: - name: config mountPath: /etc/xp - {{- with .Values.xpApi.extraVolumeMounts }} + {{- with .Values.xpManagement.extraVolumeMounts }} {{- toYaml . | nindent 8 }} {{- end }} - name: swagger-ui @@ -106,7 +106,7 @@ spec: args: - | mkdir /app - export LOCAL_API_SERVER="http://127.0.0.1:{{ .Values.xpApi.service.internalPort }}" + export LOCAL_API_SERVER="http://127.0.0.1:{{ .Values.xpManagement.service.internalPort }}" echo "Fetching swagger configuration from ${LOCAL_API_SERVER}/experiments.yaml..." until $$(wget -O $${SWAGGER_JSON} --tries 1 --timeout 1 ${LOCAL_API_SERVER}/experiments.yaml); do printf '.' @@ -125,6 +125,6 @@ spec: - name: config secret: secretName: {{ template "xp.fullname" .}}-api-config - {{- with .Values.xpApi.extraVolumes }} + {{- with .Values.xpManagement.extraVolumes }} {{- toYaml . | nindent 6 }} {{- end }} diff --git a/infra/charts/management-service/templates/ingress.yaml b/infra/charts/management-service/templates/ingress.yaml index b37808c0..abdf5112 100644 --- a/infra/charts/management-service/templates/ingress.yaml +++ b/infra/charts/management-service/templates/ingress.yaml @@ -1,11 +1,11 @@ -{{- if .Values.xpApi.ingress.enabled }} +{{- if .Values.xpManagement.ingress.enabled }} apiVersion: extensions/v1beta1 kind: Ingress metadata: name: {{ template "xp.fullname" .}} namespace: {{ .Release.Namespace }} annotations: - {{- with .Values.xpApi.ingress.class }} + {{- with .Values.xpManagement.ingress.class }} ingress.class: {{ . }} {{- end }} labels: @@ -16,12 +16,12 @@ metadata: app.kubernetes.io/name: {{ include "xp.fullname" . }} app.kubernetes.io/instance: {{ .Release.Name }} app.kubernetes.io/managed-by: {{ .Release.Service }} -{{- if .Values.xpApi.labels }} -{{ toYaml .Values.xpApi.labels | indent 4 }} +{{- if .Values.xpManagement.labels }} +{{ toYaml .Values.xpManagement.labels | indent 4 }} {{- end }} spec: rules: - - {{- with .Values.xpApi.ingress.host }} + - {{- with .Values.xpManagement.ingress.host }} host: {{ . }} {{- end }} http: @@ -29,5 +29,5 @@ spec: - path: / backend: serviceName: {{ template "xp.fullname" .}} - servicePort: {{ .Values.xpApi.service.externalPort }} + servicePort: {{ .Values.xpManagement.service.externalPort }} {{- end }} diff --git a/infra/charts/management-service/templates/secrets.yaml b/infra/charts/management-service/templates/secrets.yaml index 56dcd5ac..1ab09eda 100644 --- a/infra/charts/management-service/templates/secrets.yaml +++ b/infra/charts/management-service/templates/secrets.yaml @@ -5,8 +5,8 @@ metadata: name: {{ template "xp.fullname" .}}-api-config stringData: config.yaml: | - {{- toYaml .Values.xpApi.config | nindent 4 -}} - {{- if .Values.xpApi.uiConfig }} + {{- toYaml .Values.xpManagement.apiConfig | nindent 4 -}} + {{- if .Values.xpManagement.uiConfig }} ui.config.json: | {{- include "xp.ui.config" . | nindent 4 -}} {{- end }} diff --git a/infra/charts/management-service/templates/service-swagger.yaml b/infra/charts/management-service/templates/service-swagger.yaml index f3c4ff44..2fe65b6d 100644 --- a/infra/charts/management-service/templates/service-swagger.yaml +++ b/infra/charts/management-service/templates/service-swagger.yaml @@ -8,8 +8,8 @@ metadata: chart: {{ template "xp.chart" .}} release: {{ .Release.Name }} heritage: {{ .Release.Service }} -{{ if .Values.xpApi.labels -}} -{{ toYaml .Values.xpApi.labels | indent 4 -}} +{{ if .Values.xpManagement.labels -}} +{{ toYaml .Values.xpManagement.labels | indent 4 -}} {{- end }} spec: type: ClusterIP diff --git a/infra/charts/management-service/templates/service-xp.yaml b/infra/charts/management-service/templates/service-xp.yaml index 4f86846f..fb2cbcea 100644 --- a/infra/charts/management-service/templates/service-xp.yaml +++ b/infra/charts/management-service/templates/service-xp.yaml @@ -8,14 +8,14 @@ metadata: chart: {{ template "xp.chart" .}} release: {{ .Release.Name }} heritage: {{ .Release.Service }} -{{ if .Values.xpApi.labels -}} -{{ toYaml .Values.xpApi.labels | indent 4 -}} +{{ if .Values.xpManagement.labels -}} +{{ toYaml .Values.xpManagement.labels | indent 4 -}} {{- end }} spec: type: ClusterIP ports: - - port: {{ .Values.xpApi.service.externalPort }} - targetPort: {{ .Values.xpApi.service.internalPort }} + - port: {{ .Values.xpManagement.service.externalPort }} + targetPort: {{ .Values.xpManagement.service.internalPort }} protocol: TCP selector: app: {{ template "xp.name" .}} diff --git a/infra/charts/management-service/templates/serviceaccount.yaml b/infra/charts/management-service/templates/serviceaccount.yaml index a854c7cd..6e88baa9 100644 --- a/infra/charts/management-service/templates/serviceaccount.yaml +++ b/infra/charts/management-service/templates/serviceaccount.yaml @@ -1,11 +1,11 @@ -{{- if .Values.xpApi.serviceAccount.create -}} +{{- if .Values.xpManagement.serviceAccount.create -}} apiVersion: v1 kind: ServiceAccount metadata: name: {{ include "xp.serviceAccountName" . }} labels: {{- include "xp.labels" . | nindent 4 }} - {{- with .Values.xpApi.serviceAccount.annotations }} + {{- with .Values.xpManagement.serviceAccount.annotations }} annotations: {{- toYaml . | nindent 4 }} {{- end }} diff --git a/infra/charts/management-service/values.yaml b/infra/charts/management-service/values.yaml index a96d2a90..4da45819 100644 --- a/infra/charts/management-service/values.yaml +++ b/infra/charts/management-service/values.yaml @@ -1,4 +1,4 @@ -xpApi: +xpManagement: image: # -- Docker registry for XP API image registry: docker.io/ @@ -55,7 +55,7 @@ xpApi: class: "" # -- XP API server configuration. - config: {} + apiConfig: {} # -- XP UI configuration. uiConfig: From 2aee26cd580541f6a76d93fdefa6554b5045c006 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 13:42:07 +0800 Subject: [PATCH 03/17] Add build and publish steps --- .github/actions/release-rules/action.yml | 36 ++++++ .github/workflows/release.yml | 76 ++++++++++++ .github/workflows/tests.yml | 147 +++++++++++++++++++++++ Makefile | 18 ++- docker-entrypoint.sh | 2 +- 5 files changed, 274 insertions(+), 5 deletions(-) create mode 100644 .github/actions/release-rules/action.yml create mode 100644 .github/workflows/release.yml diff --git a/.github/actions/release-rules/action.yml b/.github/actions/release-rules/action.yml new file mode 100644 index 00000000..5f156c0c --- /dev/null +++ b/.github/actions/release-rules/action.yml @@ -0,0 +1,36 @@ +name: Release Rules Checker +description: Determines release type based on the git ref and provided rules + +inputs: + release_tag_regex: + required: false + description: 'Regex to match the git tag to determine if this a release run of the workflow' + default: 'v[0-9]+(\.[0-9]+){0,2}' + prerelease_tag_regex: + required: false + description: 'Regex to match the git tag to determine if this a pre-release run of the workflow' + default: 'v[0-9]+(\.[0-9]+){0,2}(-([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?' + prefix: + required: false + description: "(Optional) prefix of git tags to use. Example: 'sdk/'" + default: '' +outputs: + release-type: + description: 'Type of the release. One of: [dev, pre-release, release]' + value: ${{ steps.tag-check.outputs.release-type }} + +runs: + using: composite + steps: + - run: | + release_regex='^refs/tags/${{ inputs.prefix }}${{ inputs.release_tag_regex }}$' + prerelease_regex='^refs/tags/${{ inputs.prefix }}${{ inputs.prerelease_tag_regex }}$' + if [[ '${{ github.event.ref }}' =~ ${release_regex} ]]; then + echo '::set-output name=release-type::release' + elif [[ '${{ github.event.ref }}' =~ ${prerelease_regex} ]]; then + echo '::set-output name=release-type::pre-release' + else + echo '::set-output name=release-type::dev' + fi + id: tag-check + shell: bash diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..79619ee5 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,76 @@ +name: XP Release CI + +on: + workflow_call: + inputs: + management_service_version: + required: true + type: string + description: Semantic version of xp-management artifact to be published + treatment_service_version: + required: true + type: string + description: Semantic version of xp-treatment artifact to be published + container_registry: + type: string + required: false + default: ghcr.io + environment: + type: string + required: false + secrets: + ghcr_token: + required: true + +jobs: + publish-management-service: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ inputs.container_registry }} + username: ${{ github.actor }} + password: ${{ secrets.ghcr_token }} + + - name: Download Docker image tar + uses: actions/download-artifact@v2 + with: + name: xp-management.${{ inputs.management_service_version }}.tar + + - name: Publish Docker Image + env: + DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} + run: | + docker image load --input xp-management.${{ inputs.management_service_version }}.tar + docker tag \ + xp-management:${{ inputs.management_service_version }} \ + ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ inputs.management_service_version }} + docker push ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ inputs.management_service_version }} + + publish-treatment-service: + runs-on: ubuntu-latest + environment: ${{ inputs.environment }} + steps: + - name: Log in to the Container registry + uses: docker/login-action@v1 + with: + registry: ${{ inputs.container_registry }} + username: ${{ github.actor }} + password: ${{ secrets.ghcr_token }} + + - name: Download Docker image tar + uses: actions/download-artifact@v2 + with: + name: xp-treatment.${{ inputs.treatment_service_version }}.tar + + - name: Publish Docker Image + env: + DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} + run: | + docker image load --input xp-treatment.${{ inputs.treatment_service_version }}.tar + docker tag \ + xp-treatment:${{ inputs.treatment_service_version }} \ + ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ inputs.treatment_service_version }} + docker push ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ inputs.treatment_service_version }} diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d2adc0ed..d2ffaf0c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,12 @@ on: pull_request: branches: - main + + # To make it possible to trigger e2e CI workflow for any arbitrary git ref + workflow_dispatch: + +env: + ARTIFACT_RETENTION_DAYS: 7 jobs: lint-python: @@ -180,3 +186,144 @@ jobs: DATABASE_USER: xp DATABASE_PASSWORD: xp run: make e2e-ci + + build-ui: + runs-on: ubuntu-latest + steps: + - name: Checkout to the target branch + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 14 + + - name: Cache Dependencies + uses: actions/cache@v3 + with: + path: ui/node_modules + key: ${{ runner.os }}-modules-${{ hashFiles('ui/yarn.lock') }} + restore-keys: ${{ runner.os }}-modules- + + - name: Install + run: yarn install --network-concurrency 1 + + - name: Lint code + run: yarn lint + + - name: Build UI + env: + NODE_OPTIONS: "--max_old_space_size=4096" + run: yarn build + + - name: Publish Artifact + uses: actions/upload-artifact@v3 + with: + name: xp-ui-dist + path: ui/build/ + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + build-management-service: + runs-on: ubuntu-latest + env: + APP_NAME: xp-management + needs: + - build-ui + outputs: + api-version: ${{ steps.build-image.outputs.api-version }} + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build Docker image + id: build-image + run: | + set -o pipefail + make BIN_NAME=$APP_NAME build-image | tee output.log + echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" + + - name: Save Docker image + run: | + docker image save \ + --output xp-management.${{ steps.build-image.outputs.api-version }}.tar \ + xp-management:${{ steps.build-image.outputs.api-version }} + + - name: Publish Artifact + uses: actions/upload-artifact@v3 + with: + name: xp-management.${{ steps.build-image.outputs.api-version }}.tar + path: xp-management.${{ steps.build-image.outputs.api-version }}.tar + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + build-treatment-service: + runs-on: ubuntu-latest + env: + APP_NAME: xp-treatment + outputs: + api-version: ${{ steps.build-image.outputs.api-version }} + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Build Docker image + id: build-image + working-directory: treatment-service + run: | + set -o pipefail + make BIN_NAME=$APP_NAME build-image | tee output.log + echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" + + - name: Save Docker image + run: | + docker image save \ + --output xp-treatment.${{ steps.build-image.outputs.api-version }}.tar \ + xp-treatment:${{ steps.build-image.outputs.api-version }} + + - name: Publish Artifact + uses: actions/upload-artifact@v3 + with: + name: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar + path: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + release-rules: + runs-on: ubuntu-latest + outputs: + release-type: ${{ steps.release-rules.outputs.release-type }} + steps: + - uses: actions/checkout@v2 + - id: release-rules + uses: ./.github/actions/release-rules + + release: + # Automatically publish release and pre-release artifacts. + # + # As for dev releases, make it possible to publish artifacts + # manually by approving 'deployment' in the 'manual' environment. + # + # Dev build can be released either from the 'main' branch or + # by running this workflow manually with `workflow_dispatch` event. + if: >- + contains('release,pre-release', needs.release-rules.outputs.release-type) + || ( github.event_name != 'pull_request' ) + || ( github.event.pull_request.head.repo.full_name == github.repository ) + needs: + - lint-python + - lint-go + - unit-tests-management + - unit-tests-treatment + - e2e-tests + - build-ui + - build-management-service + - build-treatment-service + - release-rules + uses: gojek/xp/.github/workflows/release.yml@main + with: + management_service_version: ${{ needs.build-management-service.outputs.api-version }} + treatment_service_version: ${{ needs.build-treatment-service.outputs.api-version }} + environment: ${{ needs.release-rules.outputs.release-type == 'dev' && 'manual' || '' }} + secrets: + ghcr_token: ${{ secrets.GITHUB_TOKEN }} diff --git a/Makefile b/Makefile index 4eb019c3..e2e0259a 100644 --- a/Makefile +++ b/Makefile @@ -25,10 +25,17 @@ OPENAPI_VERSION=1.8.1 # General # ================================== +.PHONY: format format: format-python format-go +.PHONY: lint lint: lint-python lint-go +.PHONY: version +version: + $(eval VERSION=$(if $(OVERWRITE_VERSION),$(OVERWRITE_VERSION),v$(shell scripts/vertagen/vertagen.sh))) + @echo "xp-api version:" $(VERSION) + generate-api: test -x ${GOPATH}/bin/oapi-codegen || go get github.com/deepmap/oapi-codegen/cmd/oapi-codegen@v${OPENAPI_VERSION} oapi-codegen -config api/common/schema.conf api/schema.yaml @@ -136,14 +143,14 @@ test: test-management-service test-treatment-service # Build recipes # ================================== -build-management-service: +build-management-service: version @echo "Building binary..." @cd ${MANAGEMENT_SVC_PATH} && go build -o ./bin/${MANAGEMENT_SVC_BIN_NAME} @echo "Copying OpenAPI specs..." @cp api/experiments.yaml ${MANAGEMENT_SVC_PATH}/bin @cp api/schema.yaml ${MANAGEMENT_SVC_PATH}/bin -build-treatment-service: +build-treatment-service: version @echo "Building binary..." @cd ${TREATMENT_SVC_PATH} && go build -o ./bin/${TREATMENT_SVC_BIN_NAME} @cp api/treatment.yaml ${TREATMENT_SVC_PATH}/bin @@ -151,8 +158,11 @@ build-treatment-service: build: build-management-service build-treatment-service -version: ## Get git-tags based version - @echo ${VERSION_NUMBER} +.PHONY: build-image +build-image: version + @$(eval IMAGE_TAG = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)${BIN_NAME}:${VERSION}) + @echo "Building docker image: ${IMAGE_TAG}" + docker build --tag ${IMAGE_TAG} . # ================================== # Python E2E tests diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh index 230af237..5c64b9d6 100755 --- a/docker-entrypoint.sh +++ b/docker-entrypoint.sh @@ -65,5 +65,5 @@ parse_command_line(){ main "$@" -echo "Launching xp-api server: " "$XP_API_BIN" "${CMD[@]}" +echo "Launching xp-management server: " "$XP_API_BIN" "${CMD[@]}" exec "$XP_API_BIN" "${CMD[@]}" From 8c158a1d1d16a2c8b938ea4e355d5585838a82ef Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 13:59:02 +0800 Subject: [PATCH 04/17] Rename CI workflow file --- .github/workflows/{tests.yml => xp.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{tests.yml => xp.yml} (100%) diff --git a/.github/workflows/tests.yml b/.github/workflows/xp.yml similarity index 100% rename from .github/workflows/tests.yml rename to .github/workflows/xp.yml From 284fb190993f486775ed9186db789499d813c889 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 14:08:06 +0800 Subject: [PATCH 05/17] Temporarily remove publish step --- .github/workflows/xp.yml | 58 ++++++++++++++++++++-------------------- 1 file changed, 29 insertions(+), 29 deletions(-) diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index d2ffaf0c..04dad840 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -298,32 +298,32 @@ jobs: - id: release-rules uses: ./.github/actions/release-rules - release: - # Automatically publish release and pre-release artifacts. - # - # As for dev releases, make it possible to publish artifacts - # manually by approving 'deployment' in the 'manual' environment. - # - # Dev build can be released either from the 'main' branch or - # by running this workflow manually with `workflow_dispatch` event. - if: >- - contains('release,pre-release', needs.release-rules.outputs.release-type) - || ( github.event_name != 'pull_request' ) - || ( github.event.pull_request.head.repo.full_name == github.repository ) - needs: - - lint-python - - lint-go - - unit-tests-management - - unit-tests-treatment - - e2e-tests - - build-ui - - build-management-service - - build-treatment-service - - release-rules - uses: gojek/xp/.github/workflows/release.yml@main - with: - management_service_version: ${{ needs.build-management-service.outputs.api-version }} - treatment_service_version: ${{ needs.build-treatment-service.outputs.api-version }} - environment: ${{ needs.release-rules.outputs.release-type == 'dev' && 'manual' || '' }} - secrets: - ghcr_token: ${{ secrets.GITHUB_TOKEN }} + # release: + # # Automatically publish release and pre-release artifacts. + # # + # # As for dev releases, make it possible to publish artifacts + # # manually by approving 'deployment' in the 'manual' environment. + # # + # # Dev build can be released either from the 'main' branch or + # # by running this workflow manually with `workflow_dispatch` event. + # if: >- + # contains('release,pre-release', needs.release-rules.outputs.release-type) + # || ( github.event_name != 'pull_request' ) + # || ( github.event.pull_request.head.repo.full_name == github.repository ) + # needs: + # - lint-python + # - lint-go + # - unit-tests-management + # - unit-tests-treatment + # - e2e-tests + # - build-ui + # - build-management-service + # - build-treatment-service + # - release-rules + # uses: gojek/xp/.github/workflows/release.yml@main + # with: + # management_service_version: ${{ needs.build-management-service.outputs.api-version }} + # treatment_service_version: ${{ needs.build-treatment-service.outputs.api-version }} + # environment: ${{ needs.release-rules.outputs.release-type == 'dev' && 'manual' || '' }} + # secrets: + # ghcr_token: ${{ secrets.GITHUB_TOKEN }} From 3469d24b71a06c24f0ad516e7187a3cd749ad523 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 14:50:52 +0800 Subject: [PATCH 06/17] Fix CI build-publish workflows --- .github/workflows/xp.yml | 23 +++++++++++++++++++---- Makefile | 5 +++++ treatment-service/Makefile | 33 +++++++++++++++++++++++++++++++++ 3 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 treatment-service/Makefile diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index 04dad840..18da5e55 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -189,6 +189,9 @@ jobs: build-ui: runs-on: ubuntu-latest + defaults: + run: + working-directory: ui steps: - name: Checkout to the target branch uses: actions/checkout@v3 @@ -197,12 +200,18 @@ jobs: with: node-version: 14 - - name: Cache Dependencies + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache YARN uses: actions/cache@v3 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) with: - path: ui/node_modules - key: ${{ runner.os }}-modules-${{ hashFiles('ui/yarn.lock') }} - restore-keys: ${{ runner.os }}-modules- + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- - name: Install run: yarn install --network-concurrency 1 @@ -236,6 +245,9 @@ jobs: with: fetch-depth: 0 + - name: Construct vendor directory + run: make vendor + - name: Build Docker image id: build-image run: | @@ -268,6 +280,9 @@ jobs: with: fetch-depth: 0 + - name: Build Treatment Service binary + run: make build-treatment-service + - name: Build Docker image id: build-image working-directory: treatment-service diff --git a/Makefile b/Makefile index e2e0259a..47613a0c 100644 --- a/Makefile +++ b/Makefile @@ -31,6 +31,11 @@ format: format-python format-go .PHONY: lint lint: lint-python lint-go +.PHONY: vendor +vendor: + @echo "Fetching dependencies..." + go mod vendor + .PHONY: version version: $(eval VERSION=$(if $(OVERWRITE_VERSION),$(OVERWRITE_VERSION),v$(shell scripts/vertagen/vertagen.sh))) diff --git a/treatment-service/Makefile b/treatment-service/Makefile new file mode 100644 index 00000000..1e2fb43b --- /dev/null +++ b/treatment-service/Makefile @@ -0,0 +1,33 @@ +export + +TREATMENT_SVC_BIN_NAME=$(if $(TREATMENT_APP_NAME),$(TREATMENT_APP_NAME),xp-treatment) + +# ================================== +# General +# ================================== + +.PHONY: vendor +vendor: + @echo "Fetching dependencies..." + go mod vendor + +.PHONY: version +version: + $(eval VERSION=$(if $(OVERWRITE_VERSION),$(OVERWRITE_VERSION),v$(shell ../scripts/vertagen/vertagen.sh))) + @echo "xp-api version:" $(VERSION) + +# ================================== +# Build recipes +# ================================== + +build-treatment-service: version + @echo "Building binary..." + @cd ${TREATMENT_SVC_PATH} && go build -o ./bin/${TREATMENT_SVC_BIN_NAME} + @cp api/treatment.yaml ${TREATMENT_SVC_PATH}/bin + @cp api/schema.yaml ${TREATMENT_SVC_PATH}/bin + +.PHONY: build-image +build-image: vendor version + @$(eval IMAGE_TAG = $(if $(DOCKER_REGISTRY),$(DOCKER_REGISTRY)/,)${BIN_NAME}:${VERSION}) + @echo "Building docker image: ${IMAGE_TAG}" + docker build --tag ${IMAGE_TAG} . From 9dbf9dc69f1ca8ed88ae72507a59219d5017f041 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 16:13:26 +0800 Subject: [PATCH 07/17] Add dependencies to build stage workflow --- .github/workflows/xp.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index 18da5e55..e93ebdee 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -236,6 +236,8 @@ jobs: env: APP_NAME: xp-management needs: + - lint-go + - unit-tests-management - build-ui outputs: api-version: ${{ steps.build-image.outputs.api-version }} @@ -246,6 +248,7 @@ jobs: fetch-depth: 0 - name: Construct vendor directory + working-directory: management-service run: make vendor - name: Build Docker image @@ -272,6 +275,9 @@ jobs: runs-on: ubuntu-latest env: APP_NAME: xp-treatment + needs: + - lint-go + - unit-tests-treatment outputs: api-version: ${{ steps.build-image.outputs.api-version }} steps: From 256c1db4934abccfb3434a7225d6d65052a90fa8 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 16:29:57 +0800 Subject: [PATCH 08/17] Update golangci-lint --- .github/workflows/xp.yml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index e93ebdee..33a0827b 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -41,32 +41,33 @@ jobs: lint-go: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - name: Setup Go id: setup-go - uses: actions/setup-go@v2 + uses: actions/setup-go@v3 with: - go-version: "1.16" + go-version: 1.16 + - uses: actions/checkout@v3 - name: Lint Common module - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: version: v1.41.1 working-directory: common - skip-go-installation: true args: --timeout 3m --verbose - name: Lint Management Service module - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: version: v1.41.1 working-directory: management-service - skip-go-installation: true + skip-pkg-cache: true + skip-build-cache: true args: --timeout 3m --verbose - name: Lint Treatment Service module - uses: golangci/golangci-lint-action@v2 + uses: golangci/golangci-lint-action@v3 with: version: v1.41.1 working-directory: treatment-service - skip-go-installation: true + skip-pkg-cache: true + skip-build-cache: true args: --timeout 3m --verbose unit-tests-management: From 479c51aaf1133066f469cbb32ae3dded874dc328 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 16:41:39 +0800 Subject: [PATCH 09/17] Fix go vendoring step --- .github/workflows/xp.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index 33a0827b..ede45cdf 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -250,7 +250,9 @@ jobs: - name: Construct vendor directory working-directory: management-service - run: make vendor + run: | + echo "Fetching dependencies..." + go mod vendor - name: Build Docker image id: build-image From 4057495987db3098e0e6ff88c642d67a6d021bdd Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 6 Jun 2022 18:00:29 +0800 Subject: [PATCH 10/17] Download UI cache --- .github/workflows/xp.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index ede45cdf..6fe12728 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -248,6 +248,12 @@ jobs: with: fetch-depth: 0 + - name: Download UI Dist + uses: actions/download-artifact@v2 + with: + name: xp-ui-dist + path: ui/build + - name: Construct vendor directory working-directory: management-service run: | From 204aa04dbc33847e7f007662ae76b7f6bde9387d Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 13 Jun 2022 08:10:12 -0700 Subject: [PATCH 11/17] Rename treatment service api container --- infra/charts/treatment-service/templates/deployment.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/infra/charts/treatment-service/templates/deployment.yaml b/infra/charts/treatment-service/templates/deployment.yaml index 8cbdb3fb..f6d16697 100644 --- a/infra/charts/treatment-service/templates/deployment.yaml +++ b/infra/charts/treatment-service/templates/deployment.yaml @@ -30,7 +30,7 @@ spec: {{- toYaml . | nindent 8 }} {{- end }} containers: - - name: xp-treatment + - name: api image: "{{ .Values.xpTreatment.image.registry }}{{ .Values.xpTreatment.image.repository }}:{{ .Values.xpTreatment.image.tag | default .Chart.AppVersion }}" imagePullPolicy: {{ .Values.xpTreatment.image.pullPolicy }} env: From 2e065a1fd8330ec8294de90c4a022fb16ee85a85 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 13 Jun 2022 23:47:56 -0700 Subject: [PATCH 12/17] Add helm chart publish workflow --- .github/workflows/helm-chart.yml | 35 ++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 .github/workflows/helm-chart.yml diff --git a/.github/workflows/helm-chart.yml b/.github/workflows/helm-chart.yml new file mode 100644 index 00000000..1855e9cd --- /dev/null +++ b/.github/workflows/helm-chart.yml @@ -0,0 +1,35 @@ +name: helm-chart + +on: + push: + paths: + - ".github/workflows/helm-chart.yml" + - "infra/charts/**" + branches: + - main + workflow_dispatch: + inputs: + owner: + description: The GitHub user or org that owns this repository + type: string + required: true + repository: + description: The GitHub repository + type: string + required: true + default: "charts" + +jobs: + release: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Run chart-releaser + uses: stefanprodan/helm-gh-pages@v1.4.1 + with: + token: "${{ secrets.GH_PAGES_TOKEN }}" + charts_dir: infra/charts + owner: "${{ github.event.inputs.owner || 'turing-ml' }}" + repository: "${{ github.event.inputs.repository || 'charts' }}" + commit_username: ${{ github.actor }} + commit_email: "${{ github.actor }}@users.noreply.github.com" From 0de81b52006fe98a42132a34102a522bef1c707c Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Mon, 13 Jun 2022 23:48:01 -0700 Subject: [PATCH 13/17] Update README.md with replace directive instructions --- README.md | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/README.md b/README.md index d47a47b1..04dbe107 100644 --- a/README.md +++ b/README.md @@ -54,6 +54,17 @@ To test authorization for Management Service locally, make the following changes - Set AuthorizationConfig.Enabled=true in the config file that's being used - Issue requests to the app with the header User-Email: test-user@gojek.com +#### c. Using XP + +To use XP, `replace` directives need to be used when consuming both the Management and Treatment API modules since the API modules uses local relative path. + +```go +replace github.com/gojek/xp/clients => github.com/gojek/turing-experiments/clients v0.0.0 +replace github.com/gojek/xp/common => github.com/gojek/turing-experiments/common v0.0.0 +replace github.com/gojek/xp/management-service => github.com/gojek/turing-experiments/management-service v0.0.0 +replace github.com/gojek/xp/treatment-service => github.com/gojek/turing-experiments/treatment-service v0.0.0 +``` + ## Contributing XP is still under active development. Please have a look at our contributing and development guides if you want to contribute to the project: From fc72732b15acd5b9c56cc8b78762c0ddcdc6c2d4 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Thu, 16 Jun 2022 23:07:36 -0700 Subject: [PATCH 14/17] Cleanup docs --- README.md | 2 +- infra/charts/management-service/README.md | 28 ++++++++++----------- infra/charts/management-service/values.yaml | 28 ++++++++++----------- infra/charts/treatment-service/README.md | 4 +-- infra/charts/treatment-service/values.yaml | 4 +-- 5 files changed, 33 insertions(+), 33 deletions(-) diff --git a/README.md b/README.md index 04dbe107..bbb3f228 100644 --- a/README.md +++ b/README.md @@ -56,7 +56,7 @@ To test authorization for Management Service locally, make the following changes #### c. Using XP -To use XP, `replace` directives need to be used when consuming both the Management and Treatment API modules since the API modules uses local relative path. +To use the XP Go modules as API dependencies, `replace` directives need to be used when consuming both the Management and Treatment API modules since the API modules uses local relative path. ```go replace github.com/gojek/xp/clients => github.com/gojek/turing-experiments/clients v0.0.0 diff --git a/infra/charts/management-service/README.md b/infra/charts/management-service/README.md index 77834ba9..e7539b18 100644 --- a/infra/charts/management-service/README.md +++ b/infra/charts/management-service/README.md @@ -63,18 +63,18 @@ The following table lists the configurable parameters of the XP Management Servi | swaggerUi.image | object | `{"tag":"v3.47.1"}` | Docker tag for Swagger UI https://hub.docker.com/r/swaggerapi/swagger-ui | | swaggerUi.service.externalPort | int | `8080` | Swagger UI Kubernetes service port number | | swaggerUi.service.internalPort | int | `8081` | Swagger UI container port number | -| xpManagement.apiConfig | object | `{}` | XP API server configuration. | -| xpManagement.extraArgs | list | `[]` | List of string containing additional XP API server arguments. For example, multiple "-config" can be specified to use multiple config files | -| xpManagement.extraEnvs | list | `[]` | List of extra environment variables to add to XP API server container | -| xpManagement.extraLabels | object | `{}` | List of extra labels to add to XP API K8s resources | -| xpManagement.extraVolumeMounts | list | `[]` | Extra volume mounts to attach to XP API server container. For example to mount the extra volume containing secrets | +| xpManagement.apiConfig | object | `{}` | XP Management Service server configuration. | +| xpManagement.extraArgs | list | `[]` | List of string containing additional XP Management Service server arguments. For example, multiple "-config" can be specified to use multiple config files | +| xpManagement.extraEnvs | list | `[]` | List of extra environment variables to add to XP Management Service server container | +| xpManagement.extraLabels | object | `{}` | List of extra labels to add to XP Management Service K8s resources | +| xpManagement.extraVolumeMounts | list | `[]` | Extra volume mounts to attach to XP Management Service server container. For example to mount the extra volume containing secrets | | xpManagement.extraVolumes | list | `[]` | Extra volumes to attach to the Pod. For example, you can mount additional secrets to these volumes | | xpManagement.image.pullPolicy | string | `"IfNotPresent"` | Docker image pull policy | -| xpManagement.image.registry | string | `"docker.io/"` | Docker registry for XP API image | -| xpManagement.image.repository | string | `"xp-management"` | Docker image repository for XP API | -| xpManagement.image.tag | string | `"latest"` | Docker image tag for XP API | -| xpManagement.ingress.class | string | `""` | Ingress class annotation to add to this Ingress rule, useful when there are multiple ingress controllers installed | -| xpManagement.ingress.enabled | bool | `false` | Enable ingress to provision Ingress resource for external access to XP API | +| xpManagement.image.registry | string | `"docker.io/"` | Docker registry for XP Management Service image | +| xpManagement.image.repository | string | `"xp-management"` | Docker image repository for XP Management Service | +| xpManagement.image.tag | string | `"latest"` | Docker image tag for XP Management Service | +| xpManagement.ingress.class | string | `""` | Ingress class annotation to add to this Ingress rule, useful when there are multiple ingress controllers installed | +| xpManagement.ingress.enabled | bool | `false` | Enable ingress to provision Ingress resource for external access to XP Management Service | | xpManagement.ingress.host | string | `""` | Set host value to enable name based virtual hosting. This allows routing HTTP traffic to multiple host names at the same IP address. If no host is specified, the ingress rule applies to all inbound HTTP traffic through the IP address specified. https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting | | xpManagement.labels | object | `{}` | | | xpManagement.livenessProbe.initialDelaySeconds | int | `60` | Liveness probe delay and thresholds | @@ -88,11 +88,11 @@ The following table lists the configurable parameters of the XP Management Servi | xpManagement.readinessProbe.successThreshold | int | `1` | | | xpManagement.readinessProbe.timeoutSeconds | int | `5` | | | xpManagement.replicaCount | int | `1` | | -| xpManagement.resources | object | `{}` | Resources requests and limits for XP API. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | -| xpManagement.sentry.dsn | string | `""` | Sentry DSN value used by both XP API and XP UI | +| xpManagement.resources | object | `{}` | Resources requests and limits for XP Management Service. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | +| xpManagement.sentry.dsn | string | `""` | Sentry DSN value used by both XP Management Service and XP UI | | xpManagement.sentry.enabled | bool | `false` | | -| xpManagement.service.externalPort | int | `8080` | XP API Kubernetes service port number | -| xpManagement.service.internalPort | int | `8080` | XP API container port number | +| xpManagement.service.externalPort | int | `8080` | XP Management Service Kubernetes service port number | +| xpManagement.service.internalPort | int | `8080` | XP Management Service container port number | | xpManagement.serviceAccount.annotations | object | `{}` | | | xpManagement.serviceAccount.create | bool | `true` | | | xpManagement.serviceAccount.name | string | `""` | | diff --git a/infra/charts/management-service/values.yaml b/infra/charts/management-service/values.yaml index 4da45819..52745551 100644 --- a/infra/charts/management-service/values.yaml +++ b/infra/charts/management-service/values.yaml @@ -1,10 +1,10 @@ xpManagement: image: - # -- Docker registry for XP API image + # -- Docker registry for XP Management Service image registry: docker.io/ - # -- Docker image repository for XP API + # -- Docker image repository for XP Management Service repository: xp-management - # -- Docker image tag for XP API + # -- Docker image tag for XP Management Service tag: latest # -- Docker image pull policy pullPolicy: IfNotPresent @@ -12,7 +12,7 @@ xpManagement: labels: {} replicaCount: 1 - # -- Resources requests and limits for XP API. This should be set + # -- Resources requests and limits for XP Management Service. This should be set # according to your cluster capacity and service level objectives. # Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ resources: {} @@ -36,13 +36,13 @@ xpManagement: timeoutSeconds: 5 service: - # -- XP API Kubernetes service port number + # -- XP Management Service Kubernetes service port number externalPort: 8080 - # -- XP API container port number + # -- XP Management Service container port number internalPort: 8080 ingress: - # -- Enable ingress to provision Ingress resource for external access to XP API + # -- Enable ingress to provision Ingress resource for external access to XP Management Service enabled: false # -- Set host value to enable name based virtual hosting. This allows routing # HTTP traffic to multiple host names at the same IP address. If no host is @@ -50,11 +50,11 @@ xpManagement: # the IP address specified. # https://kubernetes.io/docs/concepts/services-networking/ingress/#name-based-virtual-hosting host: "" - # -- Ingress class annotation to add to this Ingress rule, + # -- Ingress class annotation to add to this Ingress rule, # useful when there are multiple ingress controllers installed class: "" - # -- XP API server configuration. + # -- XP Management Service server configuration. apiConfig: {} # -- XP UI configuration. @@ -70,20 +70,20 @@ xpManagement: oauthClientId: "" sentryConfig: { } - # -- List of string containing additional XP API server arguments. For + # -- List of string containing additional XP Management Service server arguments. For # example, multiple "-config" can be specified to use multiple config files extraArgs: [] # Example # - --config=/etc/secrets/experiment.yaml # - --config=/etc/secrets/database.yaml - # -- List of extra environment variables to add to XP API server container + # -- List of extra environment variables to add to XP Management Service server container extraEnvs: [] # # Example # - name: DEMO_GREETING # value: "Hello from the environment" - # -- List of extra labels to add to XP API K8s resources + # -- List of extra labels to add to XP Management Service K8s resources extraLabels: {} # -- Extra volumes to attach to the Pod. For example, you can mount @@ -93,7 +93,7 @@ xpManagement: # - name: varlog # emptyDir: {} - # -- Extra volume mounts to attach to XP API server container. For example + # -- Extra volume mounts to attach to XP Management Service server container. For example # to mount the extra volume containing secrets extraVolumeMounts: [] # # Example @@ -111,7 +111,7 @@ xpManagement: sentry: enabled: false - # -- Sentry DSN value used by both XP API and XP UI + # -- Sentry DSN value used by both XP Management Service and XP UI dsn: "" global: diff --git a/infra/charts/treatment-service/README.md b/infra/charts/treatment-service/README.md index 5b7fe32a..081a45a1 100644 --- a/infra/charts/treatment-service/README.md +++ b/infra/charts/treatment-service/README.md @@ -92,6 +92,6 @@ The following table lists the configurable parameters of the XP Treatment Servic | xpTreatment.readinessProbe.timeoutSeconds | int | `5` | | | xpTreatment.replicaCount | int | `1` | | | xpTreatment.resources | object | `{}` | Resources requests and limits for XP Treatment Service. This should be set according to your cluster capacity and service level objectives. Reference: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | -| xpTreatment.service.externalPort | int | `8080` | XP API Kubernetes service port number | -| xpTreatment.service.internalPort | int | `8080` | XP API container port number | +| xpTreatment.service.externalPort | int | `8080` | XP Treatment Service Kubernetes service port number | +| xpTreatment.service.internalPort | int | `8080` | XP Treatment Service container port number | | xpTreatment.service.type | string | `"ClusterIP"` | | diff --git a/infra/charts/treatment-service/values.yaml b/infra/charts/treatment-service/values.yaml index 7871ad57..37adab00 100644 --- a/infra/charts/treatment-service/values.yaml +++ b/infra/charts/treatment-service/values.yaml @@ -37,9 +37,9 @@ xpTreatment: service: type: ClusterIP - # -- XP API Kubernetes service port number + # -- XP Treatment Service Kubernetes service port number externalPort: 8080 - # -- XP API container port number + # -- XP Treatment Service container port number internalPort: 8080 ingress: From 047efe4ff7b0945bfa0fc3af1692222e9e894ba8 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Thu, 16 Jun 2022 23:08:48 -0700 Subject: [PATCH 15/17] Test binary artifact upload and download --- .github/workflows/xp.yml | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index 6fe12728..a89f542b 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -180,6 +180,20 @@ jobs: - name: Build binaries run: make build + - name: Publish Management Service Artifact + uses: actions/upload-artifact@v3 + with: + name: management-service-binary + path: management-service/bin/ + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + - name: Publish Treatment Service Artifact + uses: actions/upload-artifact@v3 + with: + name: treatment-service-binary + path: treatment-service/bin/ + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + - name: Run E2E tests env: DATABASE_HOST: localhost @@ -254,7 +268,13 @@ jobs: name: xp-ui-dist path: ui/build - - name: Construct vendor directory + - name: Download Management Service binary + uses: actions/download-artifact@v2 + with: + name: management-service-binary + path: management-service/bin/ + + - name: Sync vendor directory working-directory: management-service run: | echo "Fetching dependencies..." @@ -295,8 +315,11 @@ jobs: with: fetch-depth: 0 - - name: Build Treatment Service binary - run: make build-treatment-service + - name: Download Treatment Service binary + uses: actions/download-artifact@v2 + with: + name: treatment-service-binary + path: treatment-service/bin/ - name: Build Docker image id: build-image From aa787a69f81fb9542fddbabf18c4b65b0c835ad4 Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Thu, 16 Jun 2022 23:34:33 -0700 Subject: [PATCH 16/17] Combine build publish steps --- .github/workflows/release.yml | 170 ++++++++++++++++++++++++++++++---- .github/workflows/xp.yml | 145 ----------------------------- 2 files changed, 152 insertions(+), 163 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 79619ee5..1cf54df0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -3,14 +3,6 @@ name: XP Release CI on: workflow_call: inputs: - management_service_version: - required: true - type: string - description: Semantic version of xp-management artifact to be published - treatment_service_version: - required: true - type: string - description: Semantic version of xp-treatment artifact to be published container_registry: type: string required: false @@ -22,10 +14,150 @@ on: ghcr_token: required: true +env: + ARTIFACT_RETENTION_DAYS: 7 + jobs: + build-ui: + runs-on: ubuntu-latest + defaults: + run: + working-directory: ui + steps: + - name: Checkout to the target branch + uses: actions/checkout@v3 + + - uses: actions/setup-node@v3 + with: + node-version: 14 + + - name: Get yarn cache directory path + id: yarn-cache-dir-path + run: echo "::set-output name=dir::$(yarn cache dir)" + + - name: Cache YARN + uses: actions/cache@v3 + id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) + with: + path: ${{ steps.yarn-cache-dir-path.outputs.dir }} + key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} + restore-keys: | + ${{ runner.os }}-yarn- + + - name: Install + run: yarn install --network-concurrency 1 + + - name: Lint code + run: yarn lint + + - name: Build UI + env: + NODE_OPTIONS: "--max_old_space_size=4096" + run: yarn build + + - name: Publish Artifact + uses: actions/upload-artifact@v3 + with: + name: xp-ui-dist + path: ui/build/ + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + build-management-service: + runs-on: ubuntu-latest + env: + APP_NAME: xp-management + needs: + - build-ui + outputs: + api-version: ${{ steps.build-image.outputs.api-version }} + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Download UI Dist + uses: actions/download-artifact@v2 + with: + name: xp-ui-dist + path: ui/build + + - name: Download Management Service binary + uses: actions/download-artifact@v2 + with: + name: management-service-binary + path: management-service/bin/ + + - name: Sync vendor directory + working-directory: management-service + run: | + echo "Fetching dependencies..." + go mod vendor + + - name: Build Docker image + id: build-image + run: | + set -o pipefail + make BIN_NAME=$APP_NAME build-image | tee output.log + echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" + + - name: Save Docker image + run: | + docker image save \ + --output xp-management.${{ steps.build-image.outputs.api-version }}.tar \ + xp-management:${{ steps.build-image.outputs.api-version }} + + - name: Publish Artifact + uses: actions/upload-artifact@v3 + with: + name: xp-management.${{ steps.build-image.outputs.api-version }}.tar + path: xp-management.${{ steps.build-image.outputs.api-version }}.tar + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + + build-treatment-service: + runs-on: ubuntu-latest + env: + APP_NAME: xp-treatment + outputs: + api-version: ${{ steps.build-image.outputs.api-version }} + steps: + - name: Check out code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Download Treatment Service binary + uses: actions/download-artifact@v2 + with: + name: treatment-service-binary + path: treatment-service/bin/ + + - name: Build Docker image + id: build-image + working-directory: treatment-service + run: | + set -o pipefail + make BIN_NAME=$APP_NAME build-image | tee output.log + echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" + + - name: Save Docker image + run: | + docker image save \ + --output xp-treatment.${{ steps.build-image.outputs.api-version }}.tar \ + xp-treatment:${{ steps.build-image.outputs.api-version }} + + - name: Publish Artifact + uses: actions/upload-artifact@v3 + with: + name: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar + path: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar + retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} + publish-management-service: runs-on: ubuntu-latest environment: ${{ inputs.environment }} + needs: + - build-management-service steps: - name: Log in to the Container registry uses: docker/login-action@v1 @@ -37,21 +169,23 @@ jobs: - name: Download Docker image tar uses: actions/download-artifact@v2 with: - name: xp-management.${{ inputs.management_service_version }}.tar + name: xp-management.${{ needs.build-management-service.outputs.api-version }}.tar - name: Publish Docker Image env: DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} run: | - docker image load --input xp-management.${{ inputs.management_service_version }}.tar + docker image load --input xp-management.${{ needs.build-management-service.outputs.api-version }}.tar docker tag \ - xp-management:${{ inputs.management_service_version }} \ - ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ inputs.management_service_version }} - docker push ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ inputs.management_service_version }} + xp-management:${{ needs.build-management-service.outputs.api-version }} \ + ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }} + docker push ${{ env.DOCKER_REPOSITORY }}/xp-management:${{ needs.build-management-service.outputs.api-version }} publish-treatment-service: runs-on: ubuntu-latest environment: ${{ inputs.environment }} + needs: + - build-treatment-service steps: - name: Log in to the Container registry uses: docker/login-action@v1 @@ -63,14 +197,14 @@ jobs: - name: Download Docker image tar uses: actions/download-artifact@v2 with: - name: xp-treatment.${{ inputs.treatment_service_version }}.tar + name: xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar - name: Publish Docker Image env: DOCKER_REPOSITORY: ${{ inputs.container_registry }}/${{ github.repository }} run: | - docker image load --input xp-treatment.${{ inputs.treatment_service_version }}.tar + docker image load --input xp-treatment.${{ needs.build-treatment-service.outputs.api-version }}.tar docker tag \ - xp-treatment:${{ inputs.treatment_service_version }} \ - ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ inputs.treatment_service_version }} - docker push ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ inputs.treatment_service_version }} + xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} \ + ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} + docker push ${{ env.DOCKER_REPOSITORY }}/xp-treatment:${{ needs.build-treatment-service.outputs.api-version }} diff --git a/.github/workflows/xp.yml b/.github/workflows/xp.yml index a89f542b..1883eb54 100644 --- a/.github/workflows/xp.yml +++ b/.github/workflows/xp.yml @@ -202,146 +202,6 @@ jobs: DATABASE_PASSWORD: xp run: make e2e-ci - build-ui: - runs-on: ubuntu-latest - defaults: - run: - working-directory: ui - steps: - - name: Checkout to the target branch - uses: actions/checkout@v3 - - - uses: actions/setup-node@v3 - with: - node-version: 14 - - - name: Get yarn cache directory path - id: yarn-cache-dir-path - run: echo "::set-output name=dir::$(yarn cache dir)" - - - name: Cache YARN - uses: actions/cache@v3 - id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) - with: - path: ${{ steps.yarn-cache-dir-path.outputs.dir }} - key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - restore-keys: | - ${{ runner.os }}-yarn- - - - name: Install - run: yarn install --network-concurrency 1 - - - name: Lint code - run: yarn lint - - - name: Build UI - env: - NODE_OPTIONS: "--max_old_space_size=4096" - run: yarn build - - - name: Publish Artifact - uses: actions/upload-artifact@v3 - with: - name: xp-ui-dist - path: ui/build/ - retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} - - build-management-service: - runs-on: ubuntu-latest - env: - APP_NAME: xp-management - needs: - - lint-go - - unit-tests-management - - build-ui - outputs: - api-version: ${{ steps.build-image.outputs.api-version }} - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Download UI Dist - uses: actions/download-artifact@v2 - with: - name: xp-ui-dist - path: ui/build - - - name: Download Management Service binary - uses: actions/download-artifact@v2 - with: - name: management-service-binary - path: management-service/bin/ - - - name: Sync vendor directory - working-directory: management-service - run: | - echo "Fetching dependencies..." - go mod vendor - - - name: Build Docker image - id: build-image - run: | - set -o pipefail - make BIN_NAME=$APP_NAME build-image | tee output.log - echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" - - - name: Save Docker image - run: | - docker image save \ - --output xp-management.${{ steps.build-image.outputs.api-version }}.tar \ - xp-management:${{ steps.build-image.outputs.api-version }} - - - name: Publish Artifact - uses: actions/upload-artifact@v3 - with: - name: xp-management.${{ steps.build-image.outputs.api-version }}.tar - path: xp-management.${{ steps.build-image.outputs.api-version }}.tar - retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} - - build-treatment-service: - runs-on: ubuntu-latest - env: - APP_NAME: xp-treatment - needs: - - lint-go - - unit-tests-treatment - outputs: - api-version: ${{ steps.build-image.outputs.api-version }} - steps: - - name: Check out code - uses: actions/checkout@v2 - with: - fetch-depth: 0 - - - name: Download Treatment Service binary - uses: actions/download-artifact@v2 - with: - name: treatment-service-binary - path: treatment-service/bin/ - - - name: Build Docker image - id: build-image - working-directory: treatment-service - run: | - set -o pipefail - make BIN_NAME=$APP_NAME build-image | tee output.log - echo "::set-output name=api-version::$(sed -n 's%xp-api version: \(.*\)%\1%p' output.log)" - - - name: Save Docker image - run: | - docker image save \ - --output xp-treatment.${{ steps.build-image.outputs.api-version }}.tar \ - xp-treatment:${{ steps.build-image.outputs.api-version }} - - - name: Publish Artifact - uses: actions/upload-artifact@v3 - with: - name: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar - path: xp-treatment.${{ steps.build-image.outputs.api-version }}.tar - retention-days: ${{ env.ARTIFACT_RETENTION_DAYS }} - release-rules: runs-on: ubuntu-latest outputs: @@ -369,14 +229,9 @@ jobs: # - unit-tests-management # - unit-tests-treatment # - e2e-tests - # - build-ui - # - build-management-service - # - build-treatment-service # - release-rules # uses: gojek/xp/.github/workflows/release.yml@main # with: - # management_service_version: ${{ needs.build-management-service.outputs.api-version }} - # treatment_service_version: ${{ needs.build-treatment-service.outputs.api-version }} # environment: ${{ needs.release-rules.outputs.release-type == 'dev' && 'manual' || '' }} # secrets: # ghcr_token: ${{ secrets.GITHUB_TOKEN }} From cb30c37c2ffeca9732f58a4345a009971f92f4af Mon Sep 17 00:00:00 2001 From: Terence Lim Date: Fri, 17 Jun 2022 01:02:07 -0700 Subject: [PATCH 17/17] Rename release CI step --- .github/workflows/release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 1cf54df0..3813797a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,4 +1,4 @@ -name: XP Release CI +name: XP Release on: workflow_call: