Skip to content
This repository has been archived by the owner on Apr 13, 2024. It is now read-only.

Commit

Permalink
Merge pull request #13 from kaviththiranga/master
Browse files Browse the repository at this point in the history
Enhance look & feel, Fix k8s PVs
  • Loading branch information
kaviththiranga committed Nov 10, 2019
2 parents cc89d99 + e5cc2a1 commit d46bb54
Show file tree
Hide file tree
Showing 29 changed files with 367 additions and 49 deletions.
16 changes: 15 additions & 1 deletion api/compiler/src/playground_compiler/compile.bal
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ballerina/file;
import ballerina/filepath;
import ballerina/io;
import ballerina/log;

const buildCacheDir = "/build-cache";

Expand All @@ -13,37 +14,50 @@ const buildCacheDir = "/build-cache";
#
function createSourceFile(string cacheId, string sourceCode) returns string|error {
if (file:exists(buildCacheDir)) {
log:printDebug("Build cache is mounted. " );
string cachedBuildDir = check filepath:build(buildCacheDir, cacheId);
string cachedAppPath = check filepath:build(buildCacheDir, cacheId, "app.bal");
if (!file:exists(cachedBuildDir)) {
log:printDebug("Creating source file for compilation. " + cachedAppPath);
io:WritableByteChannel appFile = check io:openWritableFile(cachedAppPath);
_ = check appFile.write(sourceCode.toBytes(), 0);
check appFile.close();
} else {
log:printDebug("Found existing source file for compilation. " + cachedAppPath);
}
return cachedAppPath;
} else {
log:printError("Build cache is not mounted. " );
return file:FileNotFoundError( message = "Build Cache Directory " + buildCacheDir + " not found.");
}
}

function compile(CompileData data) returns CompilerResponse|error {
log:printDebug("Compiling request: " + data.toString());
string? cacheId = getCacheId(data.sourceCode, data.balVersion);
if (cacheId is string) {
boolean hasCachedOutputResult = hasCachedOutput(cacheId);
log:printDebug("Searching for cached output. Cache ID: " + cacheId);
if (hasCachedOutputResult) {
string? cachedOutput = getCachedOutput(cacheId);
if (cachedOutput is string) {
log:printDebug("Found cached output. " + cachedOutput);
return createDataResponse(cachedOutput);
} else {
log:printError("Empty cached output returned. " );
return createErrorResponse("Invalid cached output returned from cache.");
}
} else {
log:printDebug("Cached output not found.");
string sourceFile = check createSourceFile(cacheId, data.sourceCode);
string buildDir = check filepath:parent(sourceFile);
log:printDebug("Using " + sourceFile + " for compilation.");
string|error execStatus = execBallerinaCmd(buildDir, "build", "app.bal");
if (execStatus is error) {
return createErrorResponse(execStatus.reason());
log:printError("Error while executing compile command. ", execStatus);
return createErrorResponse(execStatus.reason());
} else {
log:printDebug("Finished executing compile command. Output: " + execStatus);
string jarPath = check filepath:build(buildDir, "app.jar");
setCachedOutput(cacheId, execStatus);
return createDataResponse(execStatus);
Expand Down
11 changes: 10 additions & 1 deletion api/executor/src/playground_executor/execute.bal
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import ballerina/file;
import ballerina/filepath;
import ballerina/log;

const buildCacheDir = "/build-cache";

function getAppJar(string cacheId) returns string|error {
Expand All @@ -16,23 +18,30 @@ function getAppJar(string cacheId) returns string|error {
}

function execute(ExecuteData data) returns ExecutorResponse|error {
log:printDebug("Executing request: " + data.toString());
string? cacheId = getCacheId(data.sourceCode, data.balVersion);
if (cacheId is string) {
log:printDebug("Searching for cached output. Cache ID: " + cacheId);
boolean hasCachedOutputResult = hasCachedOutput(cacheId);
if (hasCachedOutputResult) {
string? cachedOutput = getCachedOutput(cacheId);
if (cachedOutput is string) {
log:printDebug("Found cached output. " + cachedOutput);
return createDataResponse(cachedOutput);
} else {
return createErrorResponse("Invalid cached output returned from cache.");
}
} else {
log:printDebug("Cached output not found.");
string appJar = check getAppJar(cacheId);
log:printDebug("Executing jar: " + appJar);
string cwd = check filepath:parent(appJar);
string|error execStatus = execJar(cwd, appJar);
if (execStatus is error) {
return createErrorResponse(execStatus.reason());
log:printError("Error while executing jar: " + execStatus.reason());
return createErrorResponse(execStatus.reason());
} else {
log:printDebug("Executed jar: " + execStatus);
setCachedOutput(cacheId, execStatus);
return createDataResponse(execStatus);
}
Expand Down
1 change: 1 addition & 0 deletions docker/nginx/nginx.conf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
events { }

http {
include /etc/nginx/mime.types;
server {
location / {
root /usr/share/nginx/html;
Expand Down
4 changes: 2 additions & 2 deletions k8s/compiler/compiler-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
app: ballerina-playground-compiler
spec:
replicas: 2
replicas: 6
selector:
matchLabels:
app: ballerina-playground-compiler
Expand All @@ -23,7 +23,7 @@ spec:
volumes:
- name: pvc-nfs
persistentVolumeClaim:
claimName: nfs
claimName: pvc-build-cache-rw
containers:
- name: ballerina-playground-compiler-container
imagePullPolicy: Always
Expand Down
2 changes: 1 addition & 1 deletion k8s/controller/controller-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
app: ballerina-playground-controller
spec:
replicas: 2
replicas: 4
selector:
matchLabels:
app: ballerina-playground-controller
Expand Down
4 changes: 2 additions & 2 deletions k8s/executor/executor-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ metadata:
labels:
app: ballerina-playground-executor
spec:
replicas: 2
replicas: 6
selector:
matchLabels:
app: ballerina-playground-executor
Expand All @@ -23,7 +23,7 @@ spec:
volumes:
- name: pvc-nfs
persistentVolumeClaim:
claimName: nfs
claimName: pvc-build-cache-rw
containers:
- name: ballerina-playground-executor-container
imagePullPolicy: Always
Expand Down
2 changes: 2 additions & 0 deletions k8s/kubectl-set-namespace.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
kubectl config set-context --current --namespace=ballerina-playground-v2
13 changes: 6 additions & 7 deletions k8s/nfs/pv-and-pvc.yaml
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
apiVersion: v1
kind: PersistentVolume
metadata:
name: nfs
annotations:
pv.beta.kubernetes.io/gid: "1000"
name: pv-build-cache
spec:
storageClassName: build.cache
capacity:
storage: 100Gi
accessModes:
- ReadWriteMany
nfs:
server: nfs-server.${BPG_NAMESPACE}.svc.cluster.local
path: "/exports"
path: "/exports/cache_101"

---
kind: PersistentVolumeClaim
apiVersion: v1
metadata:
name: nfs
name: pvc-build-cache-rw
spec:
accessModes:
- ReadWriteMany
storageClassName: ""
storageClassName: build.cache
resources:
requests:
storage: 90Gi
storage: 100Gi
4 changes: 2 additions & 2 deletions k8s/undeploy-nfs.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
kubectl delete svc nfs-server -n ballerina-playground-v2
kubectl delete deployment nfs-server -n ballerina-playground-v2
kubectl delete pvc nfs -n ballerina-playground-v2
kubectl delete pv nfs -n ballerina-playground-v2
kubectl delete pvc pvc-build-cache-rw -n ballerina-playground-v2
kubectl delete pv pv-build-cache -n ballerina-playground-v2
Binary file added web/images/android-chrome-192x192.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/images/android-chrome-512x512.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/images/apple-touch-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions web/images/ballerina-logo-play.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 52 additions & 0 deletions web/images/ballerina-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
9 changes: 9 additions & 0 deletions web/images/browserconfig.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<browserconfig>
<msapplication>
<tile>
<square150x150logo src="/mstile-150x150.png"/>
<TileColor>#da532c</TileColor>
</tile>
</msapplication>
</browserconfig>
Binary file added web/images/favicon-16x16.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/images/favicon-32x32.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added web/images/favicon.ico
Binary file not shown.
Binary file added web/images/mstile-150x150.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
89 changes: 89 additions & 0 deletions web/images/safari-pinned-tab.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
19 changes: 19 additions & 0 deletions web/images/site.webmanifest
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "",
"short_name": "",
"icons": [
{
"src": "/android-chrome-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/android-chrome-512x512.png",
"sizes": "512x512",
"type": "image/png"
}
],
"theme_color": "#ffffff",
"background_color": "#ffffff",
"display": "standalone"
}
Loading

0 comments on commit d46bb54

Please sign in to comment.