├── Dockerfile ├── LICENSE ├── OWNERS ├── README.md ├── app.py ├── k8s ├── deployment.yaml ├── route.yaml └── service.yaml ├── requirements.txt ├── static └── stylesheets │ └── style.css └── templates ├── index.html └── result ├── app.js ├── index.html ├── socket.io.js └── stylesheets └── style.css /Dockerfile: -------------------------------------------------------------------------------- 1 | # Using official python runtime base image 2 | FROM image-registry.openshift-image-registry.svc:5000/openshift/python:latest 3 | 4 | # Install our requirements.txt 5 | ADD requirements.txt /opt/app-root/src/requirements.txt 6 | RUN pip install -r requirements.txt 7 | 8 | # Copy our code from the current folder to /app inside the container 9 | ADD . /opt/app-root/src 10 | 11 | # Make port 80 available for links and/or publish 12 | EXPOSE 8080 13 | 14 | # Define our command to be run when launching the container 15 | #CMD ["gunicorn", "app:app", "-b", "0.0.0.0:8080", "--log-file", "-", "--access-logfile", "-", "--workers", "4", "--keep-alive", "0"] 16 | CMD ["python", "./app.py"] 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /OWNERS: -------------------------------------------------------------------------------- 1 | # The OWNERS file is used by prow to automatically merge approved PRs. 2 | 3 | approvers: 4 | - chmouel 5 | - vdemeester 6 | - nikhil-thomas 7 | - piyush-garg 8 | - savitaashture 9 | - pradeepitm12 10 | - bnallapeta 11 | - sm43 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Voting app for Tekton Pipeline examples 2 | Trigger from github 3 | -------------------------------------------------------------------------------- /app.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | # -*- coding: utf-8 -*- 3 | from flask import Flask, render_template, request, make_response, g, send_from_directory 4 | import os 5 | import socket 6 | import random 7 | import json 8 | import requests 9 | 10 | option_a = os.getenv('OPTION_A', u"Cat 🐺") 11 | option_b = os.getenv('OPTION_B', u"Dog 🐶") 12 | hostname = socket.gethostname() 13 | 14 | app = Flask(__name__) 15 | 16 | 17 | @app.route("/", methods=['POST','GET']) 18 | def hello(): 19 | rest_endpoint="http://" + os.environ["VOTING_API_SERVICE_HOST"] + ":" + os.environ["VOTING_API_SERVICE_PORT"] 20 | voter_id = request.cookies.get('voter_id') 21 | if not voter_id: 22 | voter_id = hex(random.getrandbits(64))[2:-1] 23 | 24 | vote = None 25 | if request.method == 'POST': 26 | vote = request.form['vote'] 27 | data = json.dumps({'voter_id': voter_id, 'vote': vote}) 28 | requests.post(url=rest_endpoint + "/vote", data=data) 29 | 30 | resp = make_response(render_template( 31 | 'index.html', 32 | option_a=option_a, 33 | option_b=option_b, 34 | hostname=hostname, 35 | vote=vote, 36 | )) 37 | resp.set_cookie('voter_id', voter_id) 38 | return resp 39 | 40 | @app.route("/result", methods=['GET']) 41 | def result(): 42 | return make_response(render_template('result/index.html')) 43 | 44 | 45 | @app.route("/votes", methods=['GET']) 46 | def votes(): 47 | rest_endpoint="http://" + os.environ["VOTING_API_SERVICE_HOST"] + ":" + os.environ["VOTING_API_SERVICE_PORT"] 48 | response = requests.get(url=rest_endpoint + "/vote") 49 | print(response.content) 50 | return response.content 51 | 52 | @app.route('/templates/') 53 | def send_js(path): 54 | return send_from_directory('templates', path) 55 | 56 | 57 | if __name__ == "__main__": 58 | app.run(host='0.0.0.0', port=8080, debug=True) 59 | -------------------------------------------------------------------------------- /k8s/deployment.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: apps/v1 2 | kind: Deployment 3 | metadata: 4 | labels: 5 | app: pipelines-vote-ui 6 | name: pipelines-vote-ui 7 | spec: 8 | replicas: 1 9 | selector: 10 | matchLabels: 11 | app: pipelines-vote-ui 12 | template: 13 | metadata: 14 | labels: 15 | app: pipelines-vote-ui 16 | spec: 17 | containers: 18 | - image: quay.io/openshift-pipeline/vote-ui:latest 19 | imagePullPolicy: Always 20 | name: pipelines-vote-ui 21 | ports: 22 | - containerPort: 8080 23 | protocol: TCP 24 | - containerPort: 9090 25 | protocol: TCP 26 | env: 27 | - name: VOTING_API_SERVICE_HOST 28 | value: pipelines-vote-api 29 | - name: VOTING_API_SERVICE_PORT 30 | value: "9000" 31 | -------------------------------------------------------------------------------- /k8s/route.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: route.openshift.io/v1 2 | kind: Route 3 | metadata: 4 | labels: 5 | app: pipelines-vote-ui 6 | name: pipelines-vote-ui 7 | spec: 8 | port: 9 | targetPort: 8080-tcp 10 | tls: 11 | insecureEdgeTerminationPolicy: Redirect 12 | termination: edge 13 | to: 14 | kind: Service 15 | name: pipelines-vote-ui 16 | weight: 100 17 | -------------------------------------------------------------------------------- /k8s/service.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: Service 3 | metadata: 4 | labels: 5 | app: pipelines-vote-ui 6 | name: pipelines-vote-ui 7 | spec: 8 | type: NodePort 9 | ports: 10 | - name: 8080-tcp 11 | port: 8080 12 | targetPort: 8080 13 | protocol: TCP 14 | selector: 15 | app: pipelines-vote-ui 16 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | Flask 2 | gunicorn 3 | requests 4 | -------------------------------------------------------------------------------- /static/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | @import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600); 2 | 3 | *{ 4 | box-sizing:border-box; 5 | } 6 | html,body{ 7 | margin: 0; 8 | padding: 0; 9 | background-color: #F7F8F9; 10 | height: 100vh; 11 | font-family: 'Open Sans'; 12 | } 13 | 14 | button{ 15 | border-radius: 0; 16 | width: 100%; 17 | height: 50%; 18 | } 19 | 20 | button[type="submit"] { 21 | -webkit-appearance:none; -webkit-border-radius:0; 22 | } 23 | 24 | button i{ 25 | float: right; 26 | padding-right: 30px; 27 | margin-top: 3px; 28 | } 29 | 30 | button.a{ 31 | background-color: #e00; 32 | } 33 | 34 | button.b{ 35 | background-color: #959595; 36 | } 37 | 38 | #tip{ 39 | text-align: left; 40 | color: #c0c9ce; 41 | font-size: 14px; 42 | } 43 | 44 | #hostname{ 45 | position: absolute; 46 | bottom: 100px; 47 | right: 0; 48 | left: 0; 49 | color: #8f9ea8; 50 | font-size: 24px; 51 | } 52 | 53 | #content-container{ 54 | z-index: 2; 55 | position: relative; 56 | margin: 0 auto; 57 | display: table; 58 | padding: 10px; 59 | max-width: 940px; 60 | height: 100%; 61 | } 62 | #content-container-center{ 63 | display: table-cell; 64 | text-align: center; 65 | } 66 | 67 | #content-container-center h3{ 68 | color: #254356; 69 | } 70 | 71 | #choice{ 72 | transition: all 300ms linear; 73 | line-height: 1.3em; 74 | display: inline; 75 | vertical-align: middle; 76 | font-size: 3em; 77 | } 78 | #choice a{ 79 | text-decoration:none; 80 | } 81 | #choice a:hover, #choice a:focus{ 82 | outline:0; 83 | text-decoration:underline; 84 | } 85 | 86 | #choice button{ 87 | display: block; 88 | height: 80px; 89 | width: 330px; 90 | border: none; 91 | color: white; 92 | text-transform: uppercase; 93 | font-size:18px; 94 | font-weight: 700; 95 | margin-top: 10px; 96 | margin-bottom: 10px; 97 | text-align: left; 98 | padding-left: 50px; 99 | } 100 | 101 | #choice button.a:hover{ 102 | background-color: #e00; 103 | } 104 | 105 | #choice button.b:hover{ 106 | background-color: #959595; 107 | } 108 | 109 | #choice button.a:focus{ 110 | background-color: #e00; 111 | } 112 | 113 | #choice button.b:focus{ 114 | background-color: #959595; 115 | } 116 | 117 | #background-stats{ 118 | z-index:1; 119 | height:100%; 120 | width:100%; 121 | position:absolute; 122 | } 123 | #background-stats div{ 124 | transition: width 400ms ease-in-out; 125 | display:inline-block; 126 | margin-bottom:-4px; 127 | width:50%; 128 | height:100%; 129 | } 130 | 131 | div#result { 132 | font-size: 261%; 133 | margin-top: 70px; 134 | } -------------------------------------------------------------------------------- /templates/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {{option_a}} vs {{option_b}}! 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 |
16 |

{{option_a}} vs {{option_b}}!

17 |
18 | 19 | 20 |
21 |
22 | (Tip: you can change your vote) 23 |
24 |
25 | 26 |
27 |
28 | Processed by container ID {{hostname}} 29 |
30 |
31 |
32 | 33 | 34 | 35 | {% if vote %} 36 | 52 | {% endif %} 53 | 54 | 55 | -------------------------------------------------------------------------------- /templates/result/app.js: -------------------------------------------------------------------------------- 1 | var app = angular.module('catsvsdogs', []); 2 | 3 | var bg1 = document.getElementById('background-stats-1'); 4 | var bg2 = document.getElementById('background-stats-2'); 5 | 6 | app.controller('statsCtrl', function($scope, $http, $interval){ 7 | $interval(function() { 8 | $http.get('/votes'). 9 | then(function(response) { 10 | d = response.data 11 | r = getPercentages(d.a, d.b) 12 | $scope.aPercent = r.a; 13 | $scope.bPercent = r.b; 14 | }, function(response) { 15 | console.log("error ", response) 16 | }); 17 | }, 3000) 18 | }); 19 | 20 | app.config(function($interpolateProvider) { 21 | console.log("changed interpolating") 22 | $interpolateProvider.startSymbol('[[').endSymbol(']]'); 23 | }); 24 | 25 | function getPercentages(a, b) { 26 | var result = {}; 27 | 28 | if (a + b > 0) { 29 | result.a = Math.round(a / (a + b) * 100); 30 | result.b = 100 - result.a; 31 | } else { 32 | result.a = result.b = 50; 33 | } 34 | 35 | return result; 36 | } -------------------------------------------------------------------------------- /templates/result/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 🐺 vs 🐶 -- Result 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
🐺
24 |
[[aPercent | number:1]]%
25 |
26 |
27 |
28 |
🐶
29 |
[[bPercent | number:1]]%
30 |
31 |
32 |
33 |
34 |
35 | No votes yet 36 | [[total]] vote 37 | [[total]] votes 38 |
39 | 40 | 41 | 42 | 43 | 44 | -------------------------------------------------------------------------------- /templates/result/stylesheets/style.css: -------------------------------------------------------------------------------- 1 | @import url(//fonts.googleapis.com/css?family=Open+Sans:400,700,600); 2 | 3 | *{ 4 | box-sizing:border-box; 5 | } 6 | html,body{ 7 | margin:0; 8 | padding:0; 9 | height:100%; 10 | font-family: 'Open Sans'; 11 | } 12 | body{ 13 | transition: all 1s linear; 14 | } 15 | 16 | .divider{ 17 | height: 150px; 18 | width:2px; 19 | background-color: #C0C9CE; 20 | position: relative; 21 | top: 50%; 22 | float: left; 23 | transform: translateY(-50%); 24 | } 25 | 26 | #background-stats-1{ 27 | background-color: #e00; 28 | } 29 | 30 | #background-stats-2{ 31 | background-color: #959595; 32 | } 33 | 34 | #content-container{ 35 | z-index:2; 36 | position:relative; 37 | margin:0 auto; 38 | display:table; 39 | padding:10px; 40 | max-width:940px; 41 | height:100%; 42 | } 43 | #content-container-center{ 44 | display:table-cell; 45 | text-align:center; 46 | vertical-align:middle; 47 | } 48 | #result{ 49 | z-index: 3; 50 | position: absolute; 51 | bottom: 40px; 52 | right: 20px; 53 | color: #fff; 54 | opacity: 0.5; 55 | font-size: 45px; 56 | font-weight: 600; 57 | } 58 | #choice{ 59 | transition: all 300ms linear; 60 | line-height:1.3em; 61 | background:#fff; 62 | box-shadow: 10px 0 0 #fff, -10px 0 0 #fff; 63 | vertical-align:middle; 64 | font-size:40px; 65 | font-weight: 600; 66 | width: 450px; 67 | height: 200px; 68 | } 69 | #choice a{ 70 | text-decoration:none; 71 | } 72 | #choice a:hover, #choice a:focus{ 73 | outline:0; 74 | text-decoration:underline; 75 | } 76 | 77 | #choice .choice{ 78 | width: 49%; 79 | position: relative; 80 | top: 50%; 81 | transform: translateY(-50%); 82 | text-align: left; 83 | padding-left: 50px; 84 | } 85 | 86 | #choice .choice .label{ 87 | text-transform: uppercase; 88 | } 89 | 90 | #choice .choice.dogs{ 91 | color: #959595; 92 | float: right; 93 | } 94 | 95 | #choice .choice.cats{ 96 | color: #e00; 97 | float: left; 98 | } 99 | #background-stats{ 100 | z-index:1; 101 | height:100%; 102 | width:100%; 103 | position:absolute; 104 | } 105 | #background-stats div{ 106 | transition: width 400ms ease-in-out; 107 | display:inline-block; 108 | margin-bottom:-4px; 109 | width:50%; 110 | height:100%; 111 | float: left; 112 | } 113 | --------------------------------------------------------------------------------