Skip to content

Commit

Permalink
Feat/#299 kube deployment (#311)
Browse files Browse the repository at this point in the history
* -init created template file

* -added kubernetes template for deploy and expose a service.

* -instead of using "test" as tag, using the version defined in config.yml as tag. In future we may need to remove the version from the image name.

* -added following to the kubernetes deploy template:
       resource requests/limits
       liveness/readiness checks
       label for environment
  • Loading branch information
BalloonWen committed Jun 26, 2019
1 parent 94827bd commit 0d8dd75
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@
import com.networknt.oas.OpenApiParser;
import com.networknt.oas.model.*;
import com.networknt.oas.model.impl.OpenApi3Impl;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.lang.model.SourceVersion;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -24,21 +27,8 @@
import java.util.Map.Entry;
import java.util.stream.Collectors;

import com.networknt.oas.model.Example;
import com.networknt.oas.model.MediaType;
import com.networknt.oas.model.OpenApi3;
import com.networknt.oas.model.Operation;
import com.networknt.oas.model.Parameter;
import com.networknt.oas.model.Path;
import com.networknt.oas.model.Response;
import com.networknt.oas.model.Schema;
import com.networknt.oas.model.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import static java.io.File.separator;

import javax.lang.model.SourceVersion;

/**
* The input for OpenAPI 3.0 generator include config with json format and OpenAPI specification in yaml format.
*
Expand Down Expand Up @@ -155,6 +145,7 @@ public void generate(final String targetPath, Object model, Any config) throws I
transfer(targetPath, "docker", "Dockerfile", templates.rest.dockerfile.template(config, expose));
transfer(targetPath, "docker", "Dockerfile-Redhat", templates.rest.dockerfileredhat.template(config, expose));
transfer(targetPath, "", "build.sh", templates.rest.buildSh.template(dockerOrganization, serviceId));
transfer(targetPath, "", "kubernetes.yml", templates.rest.kubernetes.template(dockerOrganization, serviceId, config.get("artifactId").toString().trim(), expose, version));
transfer(targetPath, "", ".gitignore", templates.rest.gitignore.template());
transfer(targetPath, "", "README.md", templates.rest.README.template());
transfer(targetPath, "", "LICENSE", templates.rest.LICENSE.template());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
@args (String org, String serviceId, String artifact, String expose, String version)
#change the image tag before you deploy, if using minikube, please use any tag other than "latest"
apiVersion: apps/v1
kind: Deployment
metadata:
name: @artifact-deployment
labels:
app: @artifact
environment: dev
spec:
replicas: 1
selector:
matchLabels:
app: @artifact
template:
metadata:
labels:
app: @artifact
spec:
containers:
- name: @artifact
image: @org/@serviceId:@version
ports:
- containerPort: @expose
resources:
requests:
memory: "64Mi"
#0.25 cpu
cpu: "250m"
limits:
#0.5 cpu
memory: "128Mi"
cpu: "500m"
#cannot use httpcheck due to the server can be https
readinessProbe:
tcpSocket:
port: @expose
initialDelaySeconds: 3
periodSeconds: 3
livenessProbe:
tcpSocket:
port: @expose
initialDelaySeconds: 5
periodSeconds: 20
---
apiVersion: v1
kind: Service
metadata:
name: @artifact-service
labels:
app: @artifact
spec:
selector:
app: @artifact
type: NodePort
ports:
- protocol: TCP
port: @expose

0 comments on commit 0d8dd75

Please sign in to comment.