This repository has been archived by the owner on Sep 23, 2021. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Create deployment * Add infra as a code * Update readme file * Remove example files
- Loading branch information
1 parent
af48c20
commit b59c2a0
Showing
11 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
FROM hseeberger/scala-sbt as builder | ||
ARG PROJECT | ||
WORKDIR /build | ||
COPY project project | ||
COPY build.sbt . | ||
RUN sbt update | ||
COPY . . | ||
RUN sbt $PROJECT/universal:packageBin | ||
|
||
FROM openjdk:8u181-jre-slim | ||
ARG VERSION | ||
ARG PROJECT | ||
ENV version=$VERSION | ||
COPY --from=builder /build/$PROJECT/target/universal/. . | ||
RUN unzip -o ./mu-smart-home-$VERSION.zip | ||
RUN chmod +x mu-smart-home-$VERSION/bin/mu-smart-home | ||
ENTRYPOINT mu-smart-home-$version/bin/mu-smart-home |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
imports: | ||
- path: deployment/k8s.jinja | ||
name: k8s.jinja | ||
- path: deployment/docker.jinja | ||
name: docker.jinja | ||
- path: deployment/bigquery.jinja | ||
name: bigquery.jinja | ||
- path: deployment/pubsub.jinja | ||
name: pubsub.jinja | ||
- path: deployment/server.jinja | ||
name: server.jinja | ||
|
||
resources: | ||
- name: pubsub | ||
type: pubsub.jinja | ||
- name: mu-table | ||
type: bigquery.jinja | ||
- name: mu-build | ||
type: docker.jinja | ||
properties: | ||
project: server | ||
version: 0.1.0 | ||
branch: master | ||
- name: mu-cluster | ||
type: k8s.jinja | ||
properties: | ||
description: "Mu Cluster" | ||
zones: | ||
- europe-west1-b | ||
- europe-west1-c | ||
initialNodeCount: 1 | ||
- name: mu-smart-home-server | ||
type: server.jinja | ||
properties: | ||
cluster-type: $(ref.mu-cluster.clusterType) | ||
cluster-type-apps: $(ref.mu-cluster.clusterType-apps) | ||
cluster-type-v1beta1-extensions: $(ref.mu-cluster.clusterType-v1beta1-extensions) | ||
version: 0.1.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{% set DATASET = (env["deployment"] + "-dataset")|replace("-","_") %} | ||
{% set TABLE = (env["deployment"] + "-table")|replace("-","_") %} | ||
|
||
resources: | ||
- name: {{ DATASET }} | ||
type: gcp-types/bigquery-v2:datasets | ||
properties: | ||
datasetReference: | ||
datasetId: {{ DATASET }} | ||
- name: {{ TABLE }} | ||
type: gcp-types/bigquery-v2:tables | ||
properties: | ||
datasetId: $(ref.{{ DATASET }}.datasetReference.datasetId) | ||
tableReference: | ||
tableId: {{ TABLE }} | ||
schema: | ||
fields: | ||
- name: timestamp | ||
type: TIMESTAMP | ||
- name: lat | ||
type: FLOAT | ||
- name: long | ||
type: FLOAT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
{% set IMAGE = "eu.gcr.io/" + env["project"] + "/mu-smart-home:" + properties['version'] %} | ||
|
||
resources: | ||
- name: build-mu | ||
action: gcp-types/cloudbuild-v1:cloudbuild.projects.builds.create | ||
metadata: | ||
runtimePolicy: | ||
- UPDATE_ON_CHANGE | ||
properties: | ||
steps: | ||
- name: gcr.io/cloud-builders/git | ||
args: | ||
- clone | ||
- https://github.com/47deg/mu-smart-home.git | ||
- name: gcr.io/cloud-builders/git | ||
dir: mu-smart-home/ | ||
args: | ||
- checkout | ||
- {{ properties['branch'] }} | ||
- name: gcr.io/cloud-builders/docker | ||
dir: mu-smart-home/ | ||
args: | ||
- build | ||
- --build-arg | ||
- PROJECT={{ properties['project'] }} | ||
- --build-arg | ||
- VERSION={{ properties['version'] }} | ||
- -t | ||
- {{ IMAGE }} | ||
- . | ||
images: | ||
- {{ IMAGE }} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
{% set K8S_ENDPOINTS = { | ||
'': 'api/v1', | ||
'-apps': 'apis/apps/v1', | ||
'-rbac': 'apis/rbac.authorization.k8s.io/v1', | ||
'-v1beta1-extensions': 'apis/extensions/v1beta1' | ||
} %} | ||
|
||
resources: | ||
- name: {{ env['name'] }} | ||
type: container.v1.cluster | ||
properties: | ||
zone: {{ properties['zones'][0] }} | ||
cluster: | ||
description: {{ properties['description'] }} | ||
initialClusterVersion: '1.12.7-gke.10' | ||
locations: {{ properties['zones'] }} | ||
nodePools: | ||
- name: {{ env['name'] }}-pool | ||
initialNodeCount: {{ properties['initialNodeCount'] | default(1) }} | ||
config: | ||
machineType: {{ properties['machineType'] | default('n1-standard-1') }} | ||
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 | ||
management: | ||
autoUpgrade: true | ||
autoRepair: true | ||
|
||
{% for typeSuffix, endpoint in K8S_ENDPOINTS.iteritems() %} | ||
- name: {{ env['name'] }}-type{{ typeSuffix }} | ||
type: deploymentmanager.v2beta.typeProvider | ||
properties: | ||
options: | ||
validationOptions: | ||
# Kubernetes API accepts ints, in fields they annotate with string. | ||
# This validation will show as warning rather than failure for | ||
# Deployment Manager. | ||
# https://github.com/kubernetes/kubernetes/issues/2971 | ||
schemaValidation: IGNORE_WITH_WARNINGS | ||
# According to kubernetes spec, the path parameter 'name' | ||
# should be the value inside the metadata field | ||
# https://github.com/kubernetes/community/blob/master/contributors/devel/api-conventions.md | ||
# This mapping specifies that | ||
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()) | ||
descriptorUrl: https://$(ref.{{ env['name'] }}.endpoint)/swaggerapi/{{ endpoint }} | ||
{% endfor %} | ||
|
||
outputs: | ||
{% for typeSuffix, endpoint in K8S_ENDPOINTS.iteritems() %} | ||
- name: clusterType{{ typeSuffix }} | ||
value: {{ env['name'] }}-type{{ typeSuffix }} | ||
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{% set topic = env['deployment'] + '-' + env['name'] + '-topic' %} | ||
{% set subscription = env['deployment'] + '-' + env['name'] + '-subscription' %} | ||
|
||
resources: | ||
- name: my-topic | ||
#type: pubsub.v1.topic | ||
type: gcp-types/pubsub-v1:projects.topics | ||
properties: | ||
topic: {{ topic }} | ||
- name: my-subscription | ||
#type: pubsub.v1.subscription | ||
type: gcp-types/pubsub-v1:projects.subscriptions | ||
properties: | ||
subscription: {{ subscription }} | ||
topic: $(ref.my-topic.name) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
{% set NAME_PREFIX = env['deployment'] %} | ||
{% set CLUSTER_TYPE = env['project'] + '/' + properties['cluster-type'] %} | ||
{% set CLUSTER_TYPE_APPS = env['project'] + '/' + properties['cluster-type-apps'] %} | ||
{% set CLUSTER_TYPE_BETA = env['project'] + '/' + properties['cluster-type-v1beta1-extensions'] %} | ||
{% set DEPLOYMENT_COLLECTION = '/apis/apps/v1/namespaces/{namespace}/deployments' %} | ||
{% set SERVICE_COLLECTION = '/api/v1/namespaces/{namespace}/services' %} | ||
{% set IMAGE = "eu.gcr.io/" + env["project"] + "/mu-smart-home:" + properties['version'] %} | ||
|
||
resources: | ||
- name: {{ NAME_PREFIX }} | ||
type: {{ CLUSTER_TYPE_APPS }}:{{ DEPLOYMENT_COLLECTION }} | ||
metadata: | ||
dependsOn: | ||
- {{ properties['cluster-type-apps'] }} | ||
properties: | ||
apiVersion: apps/v1 | ||
kind: Deployment | ||
namespace: {{ properties['namespace'] | default('default') }} | ||
metadata: | ||
labels: | ||
app: {{ env['name'] }} | ||
deployment: {{ env['deployment'] }} | ||
spec: | ||
replicas: {{ properties['replicas'] | default(2) }} | ||
selector: | ||
matchLabels: | ||
app: {{ env['name'] }} | ||
deployment: {{ env['deployment'] }} | ||
template: | ||
metadata: | ||
labels: | ||
app: {{ env['name'] }} | ||
deployment: {{ env['deployment'] }} | ||
spec: | ||
containers: | ||
- image: {{ IMAGE }} | ||
name: mu-smart-home-server | ||
ports: | ||
- containerPort: 9111 | ||
|
||
- name: {{ NAME_PREFIX }}-svc | ||
type: {{ CLUSTER_TYPE }}:{{ SERVICE_COLLECTION }} | ||
metadata: | ||
dependsOn: | ||
- {{ properties['cluster-type'] }} | ||
properties: | ||
apiVersion: v1 | ||
kind: Service | ||
namespace: {{ properties['namespace'] | default('default') }} | ||
metadata: | ||
name: {{ NAME_PREFIX }}-svc | ||
labels: | ||
app: {{ env['name'] }} | ||
deployment: {{ env['deployment'] }} | ||
spec: | ||
type: LoadBalancer | ||
ports: | ||
- port: 80 | ||
targetPort: 9111 | ||
selector: | ||
app: {{ env['name'] }} | ||
deployment: {{ env['deployment'] }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
addSbtPlugin("io.higherkindness" % "sbt-mu-idlgen" % "0.18.0") | ||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.0.0") | ||
addSbtPlugin("com.typesafe.sbt" % "sbt-native-packager" % "1.3.20") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters