diff --git a/gcp/README.md b/gcp/README.md new file mode 100644 index 0000000..51a9c2a --- /dev/null +++ b/gcp/README.md @@ -0,0 +1,17 @@ +# GCP templates + +This collection of templates is intended to be used with GPC Deployment Manager. + +How to use: +* Currently a work in progress. There seems to be some bugs around GKE and Deployment Manager that the Google team are working on. +* Essentially this template is a two step process for creating re-usable deployment +templates on GCP. We start by creating the cluster and a custom type to create concepts with, and then move +to the actual service definitions for GKE. + +## Deployment Manager + +TBD + +## GKE + +TBD \ No newline at end of file diff --git a/gcp/prisma_cluster.jinja b/gcp/prisma_cluster.jinja new file mode 100644 index 0000000..8e50d4c --- /dev/null +++ b/gcp/prisma_cluster.jinja @@ -0,0 +1,57 @@ +# This script is a little flaky due to what seems to be an issue pointed out here: +# +# https://github.com/GoogleCloudPlatform/deploymentmanager-samples/issues/148 +# +# Looks like GKE might need a bit of an update in order to properly setup the initial cluster for the follow up step. +# I've also found that after a few retries I've had success and the cluster gets created. + +# Endpoints needed to create proper resources +{% set K8S_ENDPOINTS = {'': 'api/v1', '-v1beta1-extensions': 'apis/extensions/v1beta1', '-apps-v1beta1': 'apps/v1beta1'} %} + +resources: + # https://cloud.google.com/kubernetes-engine/docs/reference/rest/v1/projects.zones.clusters + - name: prisma-cluster + type: container.v1.cluster + properties: + # In order to change versions run the following command and replace with the version you desire. + # gcloud container get-server-config + initialClusterVersion: 1.9.6-gke.0 + zone: {{ properties['zone'] }} + # You'll notice the key doesn't exist in the definition for this particular resource. This is the primary + # key that will get mapped to values below for our custom type definition and give us a reference to + # our Kubernetes api. + cluster: + name: prisma-cluster + initialNodeCount: {{ properties['initialNodeCount'] }} + nodeConfig: + oauthScopes: + - https://www.googleapis.com/auth/compute + - https://www.googleapis.com/auth/devstorage.read_only + - https://www.googleapis.com/auth/logging.write + - https://www.googleapis.com/auth/monitoring + {% for typeSuffix, endpoint in K8S_ENDPOINTS.iteritems() %} + # https://cloud.google.com/deployment-manager/docs/reference/v2beta/typeProviders + - name: prisma-cluster-type{{typeSuffix}} + type: deploymentmanager.v2beta.typeProvider + properties: + # We're only setting up the official api/v1 endpoint for Kubernetes here. If you need additional + # url extensions you can create a loop to make X custom types per endpoint. Prisma doesn't require anything + # that isn't in the standard V1 API. + descriptorUrl: https://$(ref.prisma-cluster.endpoint)/swaggerapi/{{ endpoint }} + options: + validationOptions: + schemaValidation: IGNORE_WITH_WARNINGS + inputMappings: + - fieldName: name + location: PATH + methodMatch: ^(GET|DELETE|PUT)$ + value: $.ifNull($.resource.properties.metadata.name, $.resource.name) + - fieldName: metadata.name + location: BODY + methodMatch: ^(PUT|POST)$ + value: $.ifNull($.resource.properties.metadata.name, $.resource.name) + - fieldName: Authorization + location: HEADER + value: > + $.concat("Bearer ", $.googleOauth2AccessToken()) + {% endfor %} diff --git a/gcp/prisma_cluster.jinja.schema b/gcp/prisma_cluster.jinja.schema new file mode 100644 index 0000000..1fcf208 --- /dev/null +++ b/gcp/prisma_cluster.jinja.schema @@ -0,0 +1,17 @@ +info: + title: Prisma Cluster + author: Aric Beagley + description: | + Creates a Kubernetes cluster which will host a prisma cluster and sets a reference point for other DM scripts + +required: + - zone + +properties: + zone: + type: string + description: Which zone you want your cluster to exist in + initialNodeCount: + type: integer + description: How many nodes you want to run in your cluster by default + default: 2 diff --git a/gcp/prisma_cluster.yml b/gcp/prisma_cluster.yml new file mode 100644 index 0000000..54f80aa --- /dev/null +++ b/gcp/prisma_cluster.yml @@ -0,0 +1,9 @@ +imports: + - path: prisma_cluster.jinja + +resources: + - name: prisma-cluster + type: prisma_cluster.jinja + properties: + zone: us-west1-b + # initialNodeCount: 2 diff --git a/gcp/prisma_service.jinja b/gcp/prisma_service.jinja new file mode 100644 index 0000000..5734bb4 --- /dev/null +++ b/gcp/prisma_service.jinja @@ -0,0 +1,68 @@ +resources: + - name: prisma-service + type: prisma-cluster-type:/api/v1/namespaces/{namespace}/service + properties: + apiVersion: v1 + kind: Service + namespace: default + metadata: + name: prisma-service + spec: + type: LoadBalancer + ports: + - port: 60000 + targetPort: 60000 + protocol: TCP + selector: + name: prisma-service + + - name: prisma-deployment + type: prisma-cluster-type-apps-v1beta1:/apps/v1beta1/deployment + properties: + apiVersion: apps/v1beta1 + kind: Deployment + metadata: + name: prisma-deployment + spec: + replicas: 2 + template: + metadata: + labels: + app: prisma-instance + spec: + containers: + - name: prisma-container + image: prismagraphql/prisma:1.6-beta + env: + - name: PORT + value: 60000 + - name: SQL_CLIENT_HOST + value: {{ properties['dbHost'] }} + - name: SQL_CLIENT_PORT + value: {{ properties['dbPort'] }} + - name: SQL_CLIENT_USER + value: {{ properties['dbUser'] }} + - name: SQL_CLIENT_PASSWORD + value: {{ properties['dbPass'] }} + - name: SQL_CLIENT_CONNECTION_LIMIT + value: 10 + - name: SQL_INTERNAL_HOST + value: {{ properties['dbHost'] }} + - name: SQL_INTERNAL_PORT + value: {{ properties['dbPort'] }} + - name: SQL_INTERNAL_USER + value: {{ properties['dbUser'] }} + - name: SQL_INTERNAL_PASSWORD + value: {{ properties['dbPass'] }} + - name: SQL_INTERNAL_DATABASE + value: graphcool + - name: SQL_INTERNAL_CONNECTION_LIMIT + value: 10 + - name: JAVA_OPTS + value: {{ properties['jvmOpts'] }} + - name: CLUSTER_ADDRESS + value: {{ properties['clusterAddress'] }} + - name: SCHEMA_MANAGER_SECRET + value: notrequired + - name: BUGSNAG_API_KEY + value: "" diff --git a/gcp/prisma_service.jinja.schema b/gcp/prisma_service.jinja.schema new file mode 100644 index 0000000..0180ce3 --- /dev/null +++ b/gcp/prisma_service.jinja.schema @@ -0,0 +1,41 @@ +info: + title: Prisma Service + author: Aric Beagley + description: | + Creates the proper concepts for the created prisma-cluster in order to run a GCP hosted prisma cluster + +required: + - dbHost + - dbUser + - dbPassword + +properties: + dbHost: + description: The MySQL database host for Prisma to consume + type: string + + dbPort: + type: integer + description: The MySQL database port for Prisma to consume + default: 3306 + + dbUser: + description: The MySQL database user for Prisma to consume + type: string + + dbPassword: + description: The MySQL database password for Prisma to consume + type: string + + jvmOpts: + description: The JVM options passed to prisma. For example, change this value when changing the memory parameter. Max heap memory (Xmx) should be roughly two thirds of the total memory. + type: String + default: '-Xmx1350m' + + clusterAddress: + description: The url or ip of your public service that connects to the Prisma nodes + type: String + + clusterPublicKey: + description: The RSA public key you want to secure your cluster with. Omitting leads to your cluster deployment and introspection endpoints being unsecured. + type: String \ No newline at end of file diff --git a/gcp/prisma_service.yml b/gcp/prisma_service.yml new file mode 100644 index 0000000..e69de29