Repository: JockDaRock/Time2Code Branch: master Commit: 4a86d4f26b78 Files: 33 Total size: 110.9 KB Directory structure: gitextract_8uxbsio_/ ├── .gitignore ├── CONTRIBUTING.md ├── Dockerfile ├── Dockerfile.nofaas ├── FortranSample.md ├── LICENSE ├── QuickCodeTutorial.md ├── QuickCodeTutorial_PWK.md ├── README.md ├── Sample.md ├── code.txt ├── deploy_pwk.sh ├── docker-compose.yml ├── handler.py ├── ide-server.py ├── ide.py ├── ide_server.py ├── k8s_templates/ │ ├── aci-beta.yml │ ├── faas_function_k8s.yml │ └── str8_k8s.yml ├── minikube.sh ├── templates/ │ ├── alloy_server.html │ ├── base_test.html │ ├── base_test_server.html │ ├── boostrap_server.html │ ├── index-panel.html │ ├── index-tut.html │ ├── index-tutorial.html │ └── index.html ├── time2code-faas-cli-functions.yml ├── time2code-server-k8s.yml ├── time2code-swarm-deploy.yml └── time2deploy.sh ================================================ FILE CONTENTS ================================================ ================================================ FILE: .gitignore ================================================ # Created by .ignore support plugin (hsz.mobi) ### Example user template template ### Example user template # IntelliJ project files .idea *.iml out gen .time2code-faas-cli-minikube.yml ================================================ FILE: CONTRIBUTING.md ================================================ ## Contributing ### Guidelines Here are a few guidelines for contributing: * If you have found a bug please raise an issue and fill out the whole template. * Don't raise PRs for typos, these aren't necessary - just raise an Issue * If you would like to contribute to the codebase please raise an issue to propose the change and fill out the whole template. * If the documentation can be improved / translated etc please raise an issue to discuss. * Please always provide a summary of what you changed, how you did it and how it can be tested. ### Community This project is written in mostly HTML and Javascript on the frontend, Python-Flask for serving the WebIDE Pages, and Python for the code execution management on the OpenFaaS framework. If you'd like to help in any way then that would be more than welcome whatever your level of experience. ### License This project is licensed under the MIT License. #### Sign your work The sign-off is a simple line at the end of the explanation for a patch. Your signature certifies that you wrote the patch or otherwise have the right to pass it on as an open-source patch. The rules are pretty simple: if you can certify the below (from [developercertificate.org](http://developercertificate.org/)): ``` Developer Certificate of Origin Version 1.1 Copyright (C) 2004, 2006 The Linux Foundation and its contributors. 1 Letterman Drive Suite D4700 San Francisco, CA, 94129 Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Developer's Certificate of Origin 1.1 By making a contribution to this project, I certify that: (a) The contribution was created in whole or in part by me and I have the right to submit it under the open source license indicated in the file; or (b) The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate open source license and I have the right under that license to submit that work with modifications, whether created in whole or in part by me, under the same open source license (unless I am permitted to submit under a different license), as indicated in the file; or (c) The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it. (d) I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the open source license(s) involved. ``` Then you just add a line to every git commit message: Signed-off-by: Joe Smith Use your real name (sorry, no pseudonyms or anonymous contributions.) If you set your `user.name` and `user.email` git configs, you can sign your commit automatically with `git commit -s`. * Please sign your commits with `git commit -s` so that commits are traceable. ================================================ FILE: Dockerfile ================================================ FROM alpine RUN apk add -Uuv --no-cache python3 \ && apk upgrade -v --available --no-cache \ && apk add ca-certificates && pip3 install --no-cache-dir --upgrade pip setuptools wheel \ && pip3 install requests flask markdown # ADD https://github.com/alexellis/faas/releases/download/0.6.15/fwatchdog /usr/bin ADD https://github.com/openfaas-incubator/of-watchdog/releases/download/0.2.1/of-watchdog /usr/bin/fwatchdog RUN chmod +x /usr/bin/fwatchdog WORKDIR /root/ # COPY ide.py . COPY ide_server.py . COPY handler.py . COPY templates ./templates ENV fprocess="python3 handler.py" ENV cgi_headers="true" ENV cgi_body="true" ENV mode="serializing" ENV content_type="text/html" HEALTHCHECK --interval=1s CMD [ -e /tmp/.lock ] || exit 1 CMD ["fwatchdog"] ================================================ FILE: Dockerfile.nofaas ================================================ FROM alpine RUN apk add -Uuv --no-cache python3 \ && apk upgrade -v --available --no-cache \ && apk add ca-certificates && pip3 install --no-cache-dir --upgrade pip setuptools wheel \ && pip3 install requests flask markdown pymdown.extensions Pygments WORKDIR /root/ COPY static ./static COPY ide-server.py . COPY templates ./templates EXPOSE 5555 CMD ["python3", "ide-server.py"] ================================================ FILE: FortranSample.md ================================================ # Test out your code ## Random instructions Like any programming language, we need to start with Hello World. Click the code ```fortran program hello Print *, "Hello World!" end program Hello ``` Then click the `RUN IT` button at the bottom navigation bar. Wait a sec... dot dot dot and your code is complete. ================================================ FILE: LICENSE ================================================ MIT License Copyright (c) 2017 Kristopher Jock Reed Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ================================================ FILE: QuickCodeTutorial.md ================================================ ## Code Tutorial This is a quick tutorial to highlight the tutorial page feature of Time2Code. It is generated from MarkDown pages on GitHub. I will do a few quick HTTP Request code examples you can try in a few languages. ### Golang Select the Golang code language from the menu button on the bottom navbar. ![](https://raw.githubusercontent.com/JockDaRock/Time2Code/master/images/lang_sel.png) Then enter the Code below in the **IDE** on the **right**. ```golang package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "http://api.open-notify.org/iss-now.json" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("cache-control", "no-cache") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` Click the **RUN IT** button and watch as your code is executed quickly. Click the **CLEAR TERM** button once you are done and Repeat the same steps as above for the NodeJS and Python examples. **AND Dont forget to select the appropriate code langauge when running the different code snippets.** ### NodeJS ```node var request = require("request"); var options = { method: 'GET', url: 'http://api.open-notify.org/iss-now.json', headers: { 'cache-control': 'no-cache' } }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); ``` ### Python ```python import requests url = "http://api.open-notify.org/iss-now.json" r = requests.get(url) print(r.text) ```













================================================ FILE: QuickCodeTutorial_PWK.md ================================================ ## Code Tutorial This is a quick tutorial to highlight the tutorial page feature of Time2Code. It is generated from MarkDown pages on GitHub. I will do a few quick HTTP Request code examples you can try in a few languages. If you are viewing this on GitHub you will need to get Time2Code started before you can do anything else. First click the **Try in PWD** Button. [![Try in PWD](https://cdn.rawgit.com/play-with-docker/stacks/cff22438/assets/images/button.png)](http://play-with-docker.com?stack=https://raw.githubusercontent.com/JockDaRock/Time2Code/master/time2code-swarm-deploy.yml&stack_name=time2code) Once Time2Code is started up click the 5555 tab at the top of the Play-With-Docker site. ![](https://raw.githubusercontent.com/JockDaRock/Time2Code/master/images/PWD-5555.png) Add `/tutorial?tut=https://github.com/JockDaRock/Time2Code/blob/master/QuickCodeTutorial.md` to the URL in the browser. Continue with the instructions below... ### Golang Select the Golang code language from the menu button on the bottom navbar. ![](https://raw.githubusercontent.com/JockDaRock/Time2Code/master/images/lang_sel.png) Then enter the Code below in the **IDE** on the **right**. ```Golang package main import ( "fmt" "net/http" "io/ioutil" ) func main() { url := "http://api.open-notify.org/iss-now.json" req, _ := http.NewRequest("GET", url, nil) req.Header.Add("cache-control", "no-cache") res, _ := http.DefaultClient.Do(req) defer res.Body.Close() body, _ := ioutil.ReadAll(res.Body) fmt.Println(res) fmt.Println(string(body)) } ``` Click the **RUN IT** button and watch as your code is executed quickly. Click the **CLEAR TERM** button once you are done and Repeat the same steps as above for the NodeJS and Python examples. **AND Dont forget to select the appropriate code language when running the different code snippets.** ### NodeJS ```NodeJS var request = require("request"); var options = { method: 'GET', url: 'http://api.open-notify.org/iss-now.json', headers: { 'cache-control': 'no-cache' } }; request(options, function (error, response, body) { if (error) throw new Error(error); console.log(body); }); ``` ### Python ```Python import requests url = "http://api.open-notify.org/iss-now.json" r = requests.get(url) print(r.text) ```













================================================ FILE: README.md ================================================ # Time2Code A portable, scalable web based code editor to integrate into your code learning experiences. The goal is to make deploying your own web based code editor easier and more fun. ![](/images/code_gif.gif) ## Tech Overview * The Code execution backend is built off of the serverless [FaaS](http://docs.get-faas.com/) Framework for scalability and ability to support many languages. Support for [k8s](https://kubernetes.io/) is ready through [faas-netes](https://github.com/alexellis/faas-netes) and appears to be working well. * UI Modelled after the wonderful [Play-with-Moby Site](http://play-with-moby.com) and the wonderful work the guys at [Play-With-Docker](https://github.com/play-with-docker/play-with-docker) do to make our Docker Learning Experiences Better. * Function handling and code execution are being handled by Python processes. Python handles the STDIN of all of the function requests and then passes it to the desired language for interpretation and execution or compilation and execution. * Web site is being driven by the [Flask](http://flask.pocoo.org/) Framework * Code editor is built from [Ace Editor](https://ace.c9.io/) project. * Terminal is built from [XTermJS](https://xtermjs.org/). ## Up and Running ### Docker Swarm The following snippet will initialize your swarm, Time2Code, FaaS and Time2code functions. ```sh $ docker swarm init --advertise-addr eth0 && \ git clone https://github.com/JockDaRock/Time2Code && \ cd Time2Code && \ bash time2deploy.sh && \ docker service ls ``` If you are on your laptop navigate to http://127.0.0.1:5555 and start coding. ### Kubernetes - minikube > Note: Revisiting this and revamping kubernetes deployment... You will need to have [minikube installed](https://kubernetes.io/docs/tasks/tools/install-minikube/) before you begin. Type the following snippets will get minikube started and faas-netes loaded into the kube cluster. `$ git clone https://github.com/JockDaRock/Time2Code` `$ minikube start` or `$ minikube start --vm-driver=xhyve` Then run the following bash script to load FaaS and Time2Code... `$ bash ./minikube.sh' Once the script is complete it will provide you with the url, like this http://192.168.99.100:31114/, to reach the Time2Code web editor. **BEFORE** you start using it, you will need to deploy the code execution functions after the FaaS services have started. It might take a minute or two for all of the necessary Kube pods to be Running. Keep checking the pods with `kubectl get pods`. To deploy the functions use the following command in your terminal. `$ faas-cli -action deploy -f ./time2code-faas-cli-minikube.yml` Once the kube pods for the code execution are running you can get to coding :)! ![](images/python_sample0.png) ## Latest News [Time2Code: Functions as Service and Code as a Function](https://medium.com/@JockDaRock/time2code-functions-as-service-and-code-as-a-function-3d9125fc49fb) More to come... ## Coding Languages Currently Supported * Python, Golang, Powershell, NodeJS, ... more coming very soon. * Currently working on... I am currently working C# code execution. Most of my tests are running well, but need to iron out some necessary dependencies and other issues. #### Repos for language specific code execution handlers * [Python](https://github.com/JockDaRock/Time2Py) * [Golang](https://github.com/JockDaRock/Time2Go) * [NodeJS](https://github.com/JockDaRock/Time2NodeJS) * [Powershell](https://github.com/JockDaRock/Time2Powershell) (WIP) * [C#](https://github.com/JockDaRock/Time2CSharp) (WIP) * Fortran ## Roadmap and Contributing Currently in progress: * Adding markdown and instruction functionality to accompany code execution. - check and check * Add language dependency builder for code execution functions. * Kubernetes Support - check and check Time2Code is written mostly in HTML and Javascript on the FrontEnd, Python and Flask to handle the WebIDE pages, and Python on the backend to handle code language execution on the OpenFaaS framework. This project is MIT licensed - contributions are welcomed whether that means providing feedback, testing existing and new features or hacking on the source. This project is still in early stages so I need people to generally try functionality and provide feedback. I need help building new code execution handlers for different languages or suggestions for languages to add. I also need help reducing the image sizes for the Microsoft languages handlers ([Powershell](https://github.com/JockDaRock/Time2Powershell) and [C#](https://github.com/JockDaRock/Time2CSharp)). ================================================ FILE: Sample.md ================================================ # Test out your code ## Random instructions Stick this code in the right panel. ```python import requests url = "https://httpbin.org/get" r = requests.get(url) print(r.status_code) print(r.headers) print(r.text) ``` Then click the `RUN IT` button at the bottom navigation bar. Wait a sec... dot dot dot and the your code complete. ================================================ FILE: code.txt ================================================ import requests import json url = "https://sandboxapicem.cisco.com/api/v1/ticket" payload = {"username": "devnetuser", "password": "Cisco123!"} data = json.dumps(payload) print(data) headers = {"content-type": "application/json"} response = requests.post(url, data=data, headers=headers, verify=False) print(response.text) ================================================ FILE: deploy_pwk.sh ================================================ #!/bin/sh yum update -y && yum install -y git kubeadm init --apiserver-advertise-address $(hostname -i) && \ kubectl apply -n kube-system -f "https://cloud.weave.works/k8s/net?k8s-version=$(kubectl version | base64 | tr -d '\n')" cd /root/ git clone https://github.com/alexellis/faas-netes.git \ && cd faas-netes && kubectl apply -f faas.yml,rbac.yml,monitoring.yml cd /root/ curl -sSL cli.get-faas.com | sh git clone https://github.com/JockDaRock/Time2Code.git \ && cd Time2Code && git checkout dev faas-cli -action deploy -f ~/Time2Code/time2code-faas-cli-functions.yml ================================================ FILE: docker-compose.yml ================================================ version: "3.0" services: time2codeserver: build: context: . dockerfile: Dockerfile.nofaas image: jockdarock/time2codeserver:latest networks: - time2net ports: - "5555:5555" networks: time2net: driver: overlay ================================================ FILE: handler.py ================================================ #!/usr/bin/python from wsgiref.handlers import CGIHandler import os from ide_server import app query_params = os.getenv("Http_Query", default="") whole_path = os.getenv("Http_Path", default="/ip") split_path = whole_path.split('/') if len(split_path) > 3: route_path = '/' + '/'.join(split_path[3:]) else: route_path = "/" http_method = os.getenv("Http_Method", default="GET") class ProxyFix(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ['SERVER_NAME'] = "127.0.0.1" environ['SERVER_PORT'] = "8080" environ['REQUEST_METHOD'] = http_method environ['SCRIPT_NAME'] = "" environ['PATH_INFO'] = route_path environ['QUERY_STRING'] = query_params environ['SERVER_PROTOCOL'] = "HTTP/1.1" environ['Http_X_Forwarded_For'] = os.getenv("Http_X_Forwarded_For", "127.0.0.1") return self.app(environ, start_response) class HeaderRewriterFix(object): def __init__(self, app, remove_headers=None, add_headers=None): self.app = app self.remove_headers = set(x.lower() for x in (remove_headers or ())) self.add_headers = list(add_headers or ()) def __call__(self, environ, start_response): def rewriting_start_response(status, headers, exc_info=None): new_headers = [] return start_response(status, new_headers, exc_info) return self.app(environ, rewriting_start_response) if __name__ == '__main__': app.wsgi_app = ProxyFix(app.wsgi_app) app.wsgi_app = HeaderRewriterFix(app.wsgi_app, remove_headers=['Status']) CGIHandler().run(app) ================================================ FILE: ide-server.py ================================================ from flask import Flask, request, render_template, Markup import requests from urllib.parse import urlparse import markdown import os import subprocess import socket app = Flask(__name__) try: # Looking for the IP address on the K8s faas = "faas-netesd.default" ip = socket.getaddrinfo(faas, 0, 0, 0, 0) faas_port = 8080 swarm_tag = "" except Exception: # finds Docker swarm host IP upon no K8s p1 = subprocess.Popen(["/sbin/ip", "route"], stdout=subprocess.PIPE) p2 = subprocess.Popen(["awk", "/default/ { print $3 }"], stdin=p1.stdout, stdout=subprocess.PIPE) faas = (p2.stdout).read().decode("utf-8").replace("\n", "") faas_port = 8080 swarm_tag = "time2code_" @app.route('/') def time2code(): text = request.args.get('code') lang = request.args.get('lang') straight_text = request.args.get('straight_text') code_text = "" if text: r_text = requests.get(text + "?raw=true") code_text = r_text.text elif straight_text: code_text = straight_text else: code_text = "" if lang: code_lang = lang else: code_lang = "python3" return render_template('index-panel.html', code_text=code_text, code_lang=code_lang) @app.route('/code', methods=['POST']) def code(): if request.method == 'POST': data = request.data lang = request.args.get('lang') hosturl = urlparse(request.url) host = hosturl.hostname # url = "http://%s:%s/function/time2py" % host url = "http://%s:%s/function/%s%s" % (faas, faas_port, swarm_tag, lang) # print(url) headers = {"Content-Type": "text/plain"} code_exec = requests.post(url, data=data, headers=headers) resp = code_exec.text # print(resp) return resp @app.route('/tutorial') def tutorial(): text = request.args.get('code') lang = request.args.get('lang') straight_text = request.args.get('straight_text') get_tut = request.args.get('tut') code_text = "" tut_url = "" mark = "" if get_tut: tut_url = get_tut + "?raw=true" r_tut = requests.get(tut_url) mark = r_tut.text else: tut_url = "https://raw.githubusercontent.com/JockDaRock/Time2Code/master/Sample.md?raw=true" r_tut = requests.get(tut_url) mark = r_tut.text if text: r_text = requests.get(text + "?raw=true") code_text = r_text.text elif straight_text: code_text = straight_text if lang: code_lang = lang else: code_lang = "python3" content = Markup(markdown.markdown(mark, extensions=['pymdownx.github', 'pymdownx.highlight'])) return render_template('index-tut.html', markdown=content, code_text=code_text, code_lang=code_lang) if __name__ == '__main__': app.run(host="0.0.0.0", port=5555, debug=True) ================================================ FILE: ide.py ================================================ from flask import Flask, request, render_template, Markup import requests from urllib.parse import urlparse import markdown from wsgiref.handlers import CGIHandler app = Flask(__name__) @app.route('/') def time2code(): url = "https://raw.githubusercontent.com/JockDaRock/Time2Code/master/Sample.md" r = requests.get(url) mark = r.text content = Markup(markdown.markdown(mark)) return render_template('index-panel.html', markd=content) class ProxyFix(object): def __init__(self, app): self.app = app def __call__(self, environ, start_response): environ['SERVER_NAME'] = "localhost" environ['SERVER_PORT'] = "8080" environ['REQUEST_METHOD'] = "GET" environ['SCRIPT_NAME'] = "" environ['PATH_INFO'] = "/" environ['QUERY_STRING'] = "" environ['SERVER_PROTOCOL'] = "HTTP/1.1" return self.app(environ, start_response) if __name__ == '__main__': app.wsgi_app = ProxyFix(app.wsgi_app) CGIHandler().run(app) ================================================ FILE: ide_server.py ================================================ from flask import Flask, request, render_template, Markup import requests from urllib.parse import urlparse import markdown import os import subprocess import socket app = Flask(__name__) @app.route('/') def time2code(): text = request.args.get('code') lang = request.args.get('lang') straight_text = request.args.get('straight_text') code_text = "" if text: r_text = requests.get(text + "?raw=true") code_text = r_text.text elif straight_text: code_text = straight_text else: code_text = "" if lang: code_lang = lang else: code_lang = "python3" return render_template('index.html', code_text=code_text, code_lang=code_lang) @app.route('/tutorial') def tutorial(): text = request.args.get('code') lang = request.args.get('lang') straight_text = request.args.get('straight_text') get_tut = request.args.get('tut') code_text = "" tut_url = "" mark = "" if get_tut: tut_url = get_tut + "?raw=true" r_tut = requests.get(tut_url) mark = r_tut.text else: tut_url = "https://raw.githubusercontent.com/JockDaRock/Time2Code/master/Sample.md?raw=true" r_tut = requests.get(tut_url) mark = r_tut.text if text: r_text = requests.get(text + "?raw=true") code_text = r_text.text elif straight_text: code_text = straight_text if lang: code_lang = lang else: code_lang = "python3" content = Markup(markdown.markdown(mark, extensions=['pymdownx.github', 'pymdownx.highlight'])) return render_template('index-tutorial.html', markdown=content, code_text=code_text, code_lang=code_lang) if __name__ == '__main__': app.run(host="0.0.0.0", port=5555, debug=True) ================================================ FILE: k8s_templates/aci-beta.yml ================================================ apiVersion: v1 kind: Service metadata: name: time2codeserver spec: type: LoadBalancer ports: - name: time2codeserver-5555 port: 5555 protocol: TCP targetPort: 5555 selector: app: time2codeserver component: time2codeserver --- apiVersion: v1 kind: Service metadata: name: gateway labels: app: gateway spec: type: LoadBalancer ports: - port: 8080 protocol: TCP targetPort: 8080 selector: app: gateway --- apiVersion: v1 kind: Service metadata: name: faas-netesd labels: app: faas-netesd spec: type: LoadBalancer ports: - port: 8080 protocol: TCP targetPort: 8080 selector: app: faas-netesd --- apiVersion: v1 kind: Service metadata: name: prometheus labels: app: prometheus spec: type: LoadBalancer ports: - port: 9090 protocol: TCP targetPort: 9090 selector: app: prometheus --- apiVersion: v1 kind: Service metadata: name: alertmanager labels: app: alertmanager spec: type: LoadBalancer ports: - port: 9093 protocol: TCP targetPort: 9093 selector: app: alertmanager --- apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: alertmanager spec: replicas: 1 template: metadata: labels: app: alertmanager spec: containers: - name: alertmanager image: functions/alertmanager:latest-k8s imagePullPolicy: Always imagePullPolicy: Always command: ["/bin/alertmanager","-config.file=/alertmanager.yml", "-storage.path=/alertmanager"] ports: - containerPort: 9003 protocol: TCP restartPolicy: Always volumes: null --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: csharp-experimental spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: csharp-experimental strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: csharp-experimental spec: containers: - env: - name: fprocess value: python3 time2CSharp.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2csharp:latest imagePullPolicy: Always name: csharp-experimental nodename: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: gateway spec: replicas: 1 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: gateway strategy: rollingUpdate: maxSurge: 10 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app: time2code component: gateway spec: containers: - env: - name: dnsrr value: "true" - name: read_timeout value: "60" - name: write_timeout value: "60" - name: functions_provider_url value: "http://faas-netesd.default:8080/" image: functions/gateway:0.5.8-alpha imagePullPolicy: Always name: gateway ports: - containerPort: 8080 protocol: TCP restartPolicy: Always --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: golang spec: replicas: 1 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: golang strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app: time2code component: golang spec: containers: - env: - name: fprocess value: python3 time2go.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2go:latest imagePullPolicy: Always name: golang nodename: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nodejs spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: nodejs strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: nodejs spec: containers: - env: - name: fprocess value: python3 time2nodejs.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2nodejs:latest imagePullPolicy: Always name: nodejs nodename: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: powershell spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: powershell strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: powershell spec: containers: - env: - name: fprocess value: python3 time2powershell.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2powershell:latest imagePullPolicy: Always name: powershell volumeMounts: null volumes: null nodename: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: prometheus spec: replicas: 1 template: metadata: labels: app: prometheus spec: containers: - name: prometheus image: functions/prometheus:latest-k8s imagePullPolicy: Always command: ["prometheus","-config.file=/etc/prometheus/prometheus.yml", "-storage.local.path=/prometheus", "-storage.local.memory-chunks=10000", "--alertmanager.url=http://alertmanager.default:9093"] imagePullPolicy: Always ports: - containerPort: 9090 protocol: TCP --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: python spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: python strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: python spec: containers: - env: - name: fprocess value: python3 time2py.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2py:latest imagePullPolicy: Always name: python volumeMounts: null volumes: null nodename: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: time2codeserver spec: replicas: 3 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: time2codeserver strategy: rollingUpdate: maxSurge: 10 maxUnavailable: 2 type: RollingUpdate template: metadata: labels: app: time2code component: time2codeserver spec: containers: - image: jockdarock/time2codeserver:latest name: time2codeserver imagePullPolicy: Always env: - name: time2code_provider_url value: "http://time2codeserver.default:5555" ports: - containerPort: 5555 protocol: TCP volumeMounts: null restartPolicy: Always volumes: null ================================================ FILE: k8s_templates/faas_function_k8s.yml ================================================ apiVersion: extensions/v1beta1 kind: Deployment metadata: name: csharp-experimental spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: csharp-experimental strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: csharp-experimental spec: containers: - env: - name: fprocess value: python3 time2CSharp.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2csharp:latest imagePullPolicy: Always name: csharp-experimental nodeSelector: dedicated: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: golang spec: replicas: 1 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: golang strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app: time2code component: golang spec: containers: - env: - name: fprocess value: python3 time2go.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2go:latest imagePullPolicy: Always name: golang nodeSelector: dedicated: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: nodejs spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: nodejs strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: nodejs spec: containers: - env: - name: fprocess value: python3 time2nodejs.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2nodejs:latest imagePullPolicy: Always name: nodejs nodeSelector: dedicated: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: powershell spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: powershell strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: powershell spec: containers: - env: - name: fprocess value: python3 time2powershell.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2powershell:latest imagePullPolicy: Always name: powershell volumeMounts: null volumes: null nodeSelector: dedicated: aci-connector --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: python spec: replicas: 0 rollbackTo: revision: 0 selector: matchLabels: app: time2code component: python strategy: rollingUpdate: maxSurge: 1000 maxUnavailable: 0 type: RollingUpdate template: metadata: labels: app: time2code component: python spec: containers: - env: - name: fprocess value: python3 time2py.py - name: https_proxy value: $https_proxy - name: no_proxy value: gateway - name: read_timeout value: "60" - name: write_timeout value: "60" image: jockdarock/time2py:latest imagePullPolicy: Always name: python volumeMounts: null volumes: null nodeSelector: dedicated: aci-connector ================================================ FILE: k8s_templates/str8_k8s.yml ================================================ apiVersion: v1 kind: Service metadata: name: time2codeserver spec: type: LoadBalancer ports: - name: time2codeserver-5555 port: 5555 protocol: TCP targetPort: 5555 selector: app: time2codeserver component: time2codeserver --- apiVersion: v1 kind: Service metadata: name: gateway labels: app: gateway spec: type: LoadBalancer ports: - port: 8080 protocol: TCP targetPort: 8080 selector: app: gateway --- apiVersion: v1 kind: Service metadata: name: faas-netesd labels: app: faas-netesd spec: type: LoadBalancer ports: - port: 8080 protocol: TCP targetPort: 8080 selector: app: faas-netesd --- apiVersion: v1 kind: Service metadata: name: prometheus labels: app: prometheus spec: type: LoadBalancer ports: - port: 9090 protocol: TCP targetPort: 9090 selector: app: prometheus --- apiVersion: v1 kind: Service metadata: name: alertmanager labels: app: alertmanager spec: type: LoadBalancer ports: - port: 9093 protocol: TCP targetPort: 9093 selector: app: alertmanager --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: time2codeserver spec: replicas: 3 rollbackTo: revision: 0 selector: matchLabels: app: time2codeserver component: time2codeserver strategy: rollingUpdate: maxSurge: 3 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app: time2codeserver component: time2codeserver spec: containers: - image: jockdarock/time2codeserver:latest name: time2codeserver imagePullPolicy: Always env: - name: time2code_provider_url value: "http://time2codeserver.default.svc.cluster.local:5555" ports: - containerPort: 5555 protocol: TCP restartPolicy: Always --- apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: faas-netesd spec: replicas: 1 template: metadata: labels: app: faas-netesd spec: containers: - name: faas-netesd image: functions/faas-netesd:0.3.4 imagePullPolicy: Always ports: - containerPort: 8080 protocol: TCP --- apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: gateway spec: replicas: 1 template: metadata: labels: app: gateway spec: containers: - name: gateway image: functions/gateway:0.6.13 imagePullPolicy: Always env: - name: functions_provider_url value: "http://faas-netesd.default.svc.cluster.local:8080/" ports: - containerPort: 8080 protocol: TCP --- apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: prometheus spec: replicas: 1 template: metadata: labels: app: prometheus spec: containers: - name: prometheus image: functions/prometheus:latest-k8s command: ["prometheus","-config.file=/etc/prometheus/prometheus.yml", "-storage.local.path=/prometheus", "-storage.local.memory-chunks=10000", "--alertmanager.url=http://alertmanager.default:9093"] imagePullPolicy: Always ports: - containerPort: 9090 protocol: TCP --- apiVersion: apps/v1beta1 # for versions before 1.6.0 use extensions/v1beta1 kind: Deployment metadata: name: alertmanager spec: replicas: 1 template: metadata: labels: app: alertmanager spec: containers: - name: alertmanager image: functions/alertmanager:latest-k8s imagePullPolicy: Always command: ["/bin/alertmanager","-config.file=/alertmanager.yml", "-storage.path=/alertmanager"] ports: - containerPort: 9003 protocol: TCP --- ================================================ FILE: minikube.sh ================================================ #! /bin/bash git clone https://github.com/alexellis/faas-netes curl -sSL cli.get-faas.com | sudo sh kubectl apply -f faas-netes/faas.yml,faas-netes/monitoring.yml,./time2code-server-k8s.yml sed "s/localhost:31112/$(minikube ip):31112/" time2code-faas-cli-functions.yml > .time2code-faas-cli-minikube.yml echo "Load the Code execution Functions with the faas-cli and then navigate to this site http://$(minikube ip):31114 in your favorite browser." ================================================ FILE: templates/alloy_server.html ================================================ Base Test Une
================================================ FILE: templates/base_test.html ================================================ Base Test Une
================================================ FILE: templates/base_test_server.html ================================================ Base Test Une
================================================ FILE: templates/boostrap_server.html ================================================ Bootstrap Example

Hello World!

Resize the browser window to see the effect.

{{ markd }}

Editor

print("Hello")
================================================ FILE: templates/index-panel.html ================================================
================================================ FILE: templates/index-tut.html ================================================
{{ markdown }}
{{ code_text }}
================================================ FILE: templates/index-tutorial.html ================================================
{{ markdown }}
{{ code_text }}
================================================ FILE: templates/index.html ================================================
================================================ FILE: time2code-faas-cli-functions.yml ================================================ provider: name: faas gateway: http://localhost:31112 functions: time2code: fprocess: python3 handler.py image: jockdarock/time2code:master golang: fprocess: python3 time2go.py image: jockdarock/time2go:latest python3: fprocess: python3 time2py.py image: jockdarock/time2py:latest powershell: fprocess: python3 time2powershell.py image: jockdarock/time2powershell:latest nodejs: fprocess: python3 time2nodejs.py image: jockdarock/time2nodejs:latest csharp-experimental: fprocess: python3 time2CSharp.py image: jockdarock/time2csharp:latest fortran: fprocess: python3 time2fortran.py image: jockdarock/time2fortran:latest ruby: fprocess: python3 time2ruby.py image: jockdarock/time2ruby:latest ================================================ FILE: time2code-server-k8s.yml ================================================ apiVersion: v1 kind: Service metadata: name: time2codeserver spec: type: LoadBalancer ports: - name: time2codeserver-5555 port: 5555 protocol: TCP targetPort: 5555 selector: app: time2codeserver component: time2codeserver --- apiVersion: extensions/v1beta1 kind: Deployment metadata: name: time2codeserver spec: replicas: 3 rollbackTo: revision: 0 selector: matchLabels: app: time2codeserver component: time2codeserver strategy: rollingUpdate: maxSurge: 3 maxUnavailable: 1 type: RollingUpdate template: metadata: labels: app: time2codeserver component: time2codeserver spec: containers: - image: jockdarock/time2codeserver:latest name: time2codeserver imagePullPolicy: Always env: - name: time2code_provider_url value: "http://time2codeserver.default:5555" ports: - containerPort: 5555 protocol: TCP restartPolicy: Always ================================================ FILE: time2code-swarm-deploy.yml ================================================ version: "3" services: # Setup FaaS Framework First # Core API services for FaaS are pinned, HA is provided for functions. gateway: volumes: - "/var/run/docker.sock:/var/run/docker.sock" ports: - 8080:8080 image: functions/gateway:0.6.13 networks: - functions environment: dnsrr: "true" # Temporarily use dnsrr in place of VIP while issue persists on PWD read_timeout: "60" write_timeout: "60" deploy: placement: constraints: [node.role == manager] prometheus: image: functions/prometheus:latest # autobuild from Dockerfile in repo. command: "-config.file=/etc/prometheus/prometheus.yml -storage.local.path=/prometheus -storage.local.memory-chunks=10000 --alertmanager.url=http://alertmanager:9093" ports: - 9090:9090 depends_on: - gateway - alertmanager environment: no_proxy: "gateway" networks: - functions deploy: placement: constraints: [node.role == manager] alertmanager: image: functions/alertmanager:latest # autobuild from Dockerfile in repo. environment: no_proxy: "gateway" command: - '-config.file=/alertmanager.yml' networks: - functions ports: - 9093:9093 deploy: placement: constraints: [node.role == manager] # Code execution functions on FaaS # Python Code Execution python3: image: jockdarock/time2py:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2py.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # Golang Code Execution golang: image: jockdarock/time2go:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2go.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # Powershell Code Execution powershell: image: jockdarock/time2powershell:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2powershell.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # DotNet / C# Code Execution csharp-experimental: image: jockdarock/time2csharp:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2CSharp.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # NodeJS Code Execution nodejs: image: jockdarock/time2nodejs:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2nodejs.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # Fortran Code Execution fortran: image: jockdarock/time2fortran:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2fortran.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # Fortran Code Execution ruby: image: jockdarock/time2ruby:latest labels: function: "true" depends_on: - gateway networks: - functions environment: fprocess: "python3 time2ruby.py" no_proxy: "gateway" https_proxy: $https_proxy read_timeout: "60" write_timeout: "60" # Time2Code Code Editor / Flask Web Server time2codeserver: depends_on: - gateway build: context: . dockerfile: Dockerfile.nofaas deploy: replicas: 2 image: jockdarock/time2codeserver:latest networks: - functions ports: - "5555:5555" networks: functions: driver: overlay ================================================ FILE: time2deploy.sh ================================================ #!/bin/sh echo "Deploying Time2Code on FaaS" curl -O https://raw.githubusercontent.com/JockDaRock/Time2Code/master/time2code-swarm-deploy.yml docker stack deploy time2code --compose-file time2code-swarm-deploy.yml