├── README.md ├── bin ├── .vimrc ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── cleanup-envs.sh ├── create-ose3-app-ab-deployment.sh ├── create-ose3-app-auto-cpu-scaling.sh ├── create-ose3-app-bluegreen-deployment.sh ├── create-ose3-app-from-source-mono.sh ├── create-ose3-app-mlbparks.sh ├── create-ose3-app-promo-envs.sh ├── create-ose3-cnv.sh ├── create-ose3-games.sh ├── create-ose3-jenkins-pipeline-example.sh ├── create-ose3-resource-quota-limits.sh ├── create-ose3-statefulset.sh ├── load_cpu.sh ├── pullimages.sh ├── setup-cluster-metrics.sh └── setup-efk-logging.sh ├── conf ├── README.md ├── Template_Example.json ├── hello-service.json ├── kibana.crt ├── kibana.csr ├── kibana.key ├── logging-deployer-service-account.yml ├── logging.yaml ├── metrics-deployer-service-account.yml ├── metrics.yaml ├── resource-limits.json ├── resource-quota.json ├── sample-jenkins-script └── scaler.yml ├── libs ├── README.md └── functions ├── openshift.yml └── playbooks ├── README.md ├── ansible_hosts └── ose3-master-scripts.yml /README.md: -------------------------------------------------------------------------------- 1 | # Openshift 2 | Scripts for stepping through OSE demo examples, showcasing various applications and scenarios. 3 | Based on the most excellent working demos done by Veer -> https://github.com/VeerMuchandi 4 | 5 | These are for Openshift Enterprise version 3.1.0 and aren't guaranteed to work on other versions. 6 | 7 | ### Setup 8 | 9 | git clone this repo: 10 | ``` 11 | cd /home/demo 12 | git clone https://github.com/ffirg/openshift.git 13 | cd openshift/bin 14 | ``` 15 | 16 | Using demobuilder all-in-one image as your base (https://github.com/RedHatEMEA/demobuilder), open up the console and fire up the Firefox browser and a Terminal. 17 | 18 | ### What They Demo 19 | 20 | #### MLB Parks 21 | Creates the visually appealing MLBParks example. Overlays baseball venues on to Google Maps. 22 | MongoDB is used for the back-end database, JBoss EAP for the front-end, so this demonstrates a multi-tiered application, wired together in stages. 23 | 24 | ``` 25 | $ ./create-ose3-app-mlbparks.sh 26 | ``` 27 | 28 | 29 | #### Code Promotion Between Environments 30 | Demonstrates how an application can be 'promoted' from one environment (namespace) to another. The example uses Development & Test/QA, to show how an application can be released in a manual and controlled manner, using image tagging, from one environment to another. See https://www.youtube.com/watch?v=Rzsa6VJRGDw for a demo. 31 | 32 | ``` 33 | $ ./create-ose3-app-promo-envs.sh 34 | ``` 35 | 36 | #### Horizontal CPU Auto Application Scaling 37 | Demonstrates how an application can use cluster metrics and horizontal pod scaling based on CPU load. Deploys a welcome-php application, setups up project quota and CPU scaling resource controls and generates some HTTP traffic to showcase auto pod scale up/down. 38 | 39 | ``` 40 | $ ./create-ose3-app-auto-cpu-scaling.sh 41 | ``` 42 | 43 | #### Create Application Just From Source Dockerfile, Using Mono 44 | Demonstrates how you can create an application just from a source Dockerfile. This is hosted on Github and builds a sample Mono demo framework application which you can access from the Openshift GUI. 45 | 46 | ``` 47 | $ ./create-ose3-app-from-source-mono.sh 48 | ``` 49 | 50 | 51 | #### Blue Green Deployment 52 | Demonstrates how you can deploy 2 versions of the same application, and quickly change the exposed route between them to allow one service or the other to be used. This example could be used in environments where there is still fairly rigid change control, who like a more 'big bang' release approach still. Could also be used for DR testing for the application on a regular basis! See https://www.youtube.com/watch?v=Rzsa6VJRGDw for a demo. 53 | 54 | ``` 55 | $ ./create-ose3-app-bluegreen-deployment.sh 56 | ``` 57 | 58 | ##### Demo steps 59 | 1. Please fork the project https://github.com/VeerMuchandi/bluegreen. 60 | 2. vi the create-ose3-app-bluegreen-deployment.sh script to reference the new forked project (SRC= line near the top) 61 | 3. ./create-ose3-app-bluegreen-deployment.sh Once you build the "blue" service, you need to pop over to your forked repo and do a code change to image.php (comment out blue and uncomment green). Run through the rest of the script. 62 | 63 | #### AB Deployment 64 | Demonstrates how to do rolling A-B or Canary style deployment. Bring application version 1 into service. Then change the code to make version 2 and deploy that into the service but in incremental stages. Turn off version 1, once everyones happy with version 2. Enables a lower risk application deployment strategy, with rollback capabilities. 65 | 66 | ##### Demo steps 67 | 1. Please fork the project https://github.com/VeerMuchandi/ab-deploy.git 68 | 2. vi create-ose3-app-ab-deployment.sh script to reference the new forked project (SRC= line near the top) 69 | 3. ./create-ose3-app-ab-deployment.sh (Once it builds "app-a", you need to pop over to your forked repo and do a code change to index.php - the script will tell you this). Run through the rest of the script. 70 | 71 | 72 | ### Running 73 | In the Terminal (as the demo user): 74 | ``` 75 | $ cd /home/demo 76 | $ git clone https://github.com/ffirg/openshift.git 77 | $ cd openshift/bin 78 | $ ./create-ose3-app-ab-deployment.sh 79 | ``` 80 | Follow the prompts! Some scripts need to be as run (for system:admin privileges) but the scripts check and advise :) 81 | 82 | ### Cleaning Up 83 | You can use this little utility to remove one or more of the demo project namespaces. 84 | If you want to cycle through and remove selective projects, then just run: 85 | ``` 86 | ./cleanup-envs.sh 87 | ``` 88 | If you want to remove all projects, use: 89 | ``` 90 | ./cleanup-envs.sh -p all 91 | ``` 92 | -------------------------------------------------------------------------------- /bin/.vimrc: -------------------------------------------------------------------------------- 1 | filetype on 2 | -------------------------------------------------------------------------------- /bin/LICENSE.txt: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright 2016-2018 The Apache Software Foundation 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /bin/NOTICE.txt: -------------------------------------------------------------------------------- 1 | Apache OpenWhisk CLI 2 | Copyright 2016-2018 The Apache Software Foundation 3 | 4 | This product includes software developed at 5 | The Apache Software Foundation (http://www.apache.org/). 6 | -------------------------------------------------------------------------------- /bin/README.md: -------------------------------------------------------------------------------- 1 | 19 | 20 | # OpenWhisk Command Line Interface `wsk` 21 | [![License](https://img.shields.io/badge/license-Apache--2.0-blue.svg)](http://www.apache.org/licenses/LICENSE-2.0) 22 | [![Build Status](https://travis-ci.org/apache/incubator-openwhisk-cli.svg?branch=master)](https://travis-ci.org/apache/incubator-openwhisk-cli) 23 | 24 | # Disclaimer 25 | 26 | This project is currently on an experimental stage. We periodically synchronize 27 | the source code and test cases of this repository with the [CLI 28 | folder](https://github.com/apache/incubator-openwhisk/tree/master/tools/cli/go-whisk-cli) 29 | and the [test 30 | folder](https://github.com/apache/incubator-openwhisk/tree/master/tests) in 31 | OpenWhisk. The framework of test cases is under construction for this 32 | repository. Please contribute to the [CLI 33 | folder](https://github.com/apache/incubator-openwhisk/tree/master/tools/cli/go-whisk-cli) 34 | in OpenWhisk for any CLI changes, before we officially announce the separation 35 | of OpenWhisk CLI from OpenWhisk. 36 | 37 | The OpenWhisk Command Line Interface (OpenWhisk CLI) is a unified tool that 38 | provides a consistent interface to interact with OpenWhisk services. With this 39 | tool to download and configure, you are able to manage OpenWhisk services from 40 | the command line and automate them through scripts. 41 | 42 | # Where to download the binary of OpenWhisk CLI 43 | 44 | The OpenWhisk CLI is available on the release page: [click here to 45 | download](https://github.com/apache/incubator-openwhisk-cli/releases). We 46 | currently have binaries available for Linux, Mac OS and Windows under i386 and 47 | amd64 architectures. Linux versions are also available under Linux on Z, Power 48 | and 64-bit ARM architectures. You can download the binary, which fits your 49 | local environment. 50 | 51 | # How to build the binary locally 52 | 53 | The OpenWhisk CLI is written in the Go language. You have two options to build 54 | the binary locally: 55 | 56 | 1. Build using the packaged Gradle scripts (including the 'gogradle' plugin), 57 | now the preferred build method. 58 | 2. Compile in your local Go environment, 59 | 60 | ## Build the binary with Gradle 61 | 62 | **Note:** For those who may have used the Gradle build previously, it has been 63 | re-engineered to no longer required Docker or Go to be pre-installed on your 64 | system. Using the [gogradle](https://github.com/gogradle/gogradle) plugin, 65 | Gradle now uses a prexisting Go environment to build if it can be located, or 66 | downloads and installs an environment within the build directory. 67 | 68 | To build with Gradle, open an terminal, go to the directory of OpenWhisk CLI 69 | home directory, and build the binary via the following command under Linux or 70 | Mac: 71 | 72 | ``` 73 | $ ./gradlew compile -PnativeCompile 74 | ``` 75 | 76 | or run the following command for Windows: 77 | 78 | ``` 79 | $ ./gradlew.bat compile -PnativeCompile 80 | ``` 81 | 82 | After the build, you can find the binary `wsk` or `wsk.exe` in the build folder 83 | under the OpenWhisk CLI home directory. In addition, it is also available under 84 | the folder `build/-/`. For example, if your local operating 85 | system is Mac, and the CPU architecture is amd64, the binary can be found at 86 | `build/mac-amd64/wsk` and `build/mac`. 87 | 88 | If you would like to build the binaries available for all the operating systems 89 | and architectures, run the following command: 90 | 91 | ``` 92 | $ ./gradlew compile 93 | ``` 94 | 95 | The build script will place the binaries into the folder `build/-/` 96 | for each operating system and CPU architecture pair. The build supports both 97 | amd64 and 386 for Linux, Mac and Windows operating systems, as well as Power, 98 | 64-bit ARM, and S390X architectures for Linux. 99 | 100 | A binary compatible with the local architecture will be placed at `build/wsk` 101 | (`build\wsk.exe` on Windows). 102 | 103 | To specify a build for specific architectures, you can provide a comma or 104 | space-delimited list of hyphenated os-architecture pairs, like this: 105 | 106 | ``` 107 | $ ./gradlew compile -PbuildPlatforms=linux-amd64,mac-amd64,windows-amd64 108 | ``` 109 | 110 | The build library understands most representations of most Operating Systems. 111 | 112 | Tests can be run using the Gradle script as well: 113 | 114 | ``` 115 | $ ./gradlew goTest -PgoTags=unit 116 | $ ./gradlew goTest -PgoTags=native 117 | ``` 118 | 119 | Integration tests are best left to the Travis build as they depend on a fully 120 | functional OpenWhisk environment. 121 | 122 | ## Compile the binary using your local Go environment 123 | 124 | Make sure that you have Go installed [installing 125 | Go](https://golang.org/doc/install), and `$GOPATH` is defined [Go development 126 | environment](https://golang.org/doc/code.html). 127 | 128 | Then download the source code of the OpenWhisk CLI and the dependencies by 129 | typing: 130 | 131 | ``` 132 | $ cd $GOPATH 133 | $ go get github.com/apache/incubator-openwhisk-cli 134 | $ cd $GOPATH/src/github.com/apache/incubator-openwhisk-cli 135 | ``` 136 | 137 | The CLI internationalization should be generated dynamically using the 138 | bindata tool: 139 | 140 | ``` 141 | $ go get -u github.com/jteeuwen/go-bindata/... 142 | $ go-bindata -pkg wski18n -o wski18n/i18n_resources.go wski18n/resources 143 | ``` 144 | 145 | Unfortunately, it has become necessary to lock dependencies versions to obtain a 146 | clean build of wsk. To that end, it's now necessary to populate the `vendors` 147 | folder using the versions selected in the `build.gradle`: 148 | 149 | ``` 150 | $ ./gradlew goVendor 151 | ``` 152 | 153 | Once vendor is populated, it's possible to build the binary: 154 | 155 | ``` 156 | $ go build -o wsk 157 | ``` 158 | 159 | If you would like to build the binary for a specific operating system, you may 160 | add the arguments GOOS and GOARCH into the Go build command. GOOS can 161 | be set to "linux" "darwin" or "windows". 162 | 163 | For example, run the following command to build the binary for Linux: 164 | 165 | ``` 166 | $ GOOS=linux GOARCH=amd64 go build -o wsk-$GOOS-$GOARCH 167 | ``` 168 | 169 | If it is executed successfully, you can find your binary `wsk` directly under 170 | OpenWhisk CLI home directory. 171 | 172 | # How to use the binary 173 | 174 | When you have the binary, you can copy the binary to any folder, and add folder 175 | into the system PATH in order to run the OpenWhisk CLI command. To get the CLI 176 | command help, execute the following command: 177 | 178 | ``` 179 | $ wsk --help 180 | ``` 181 | 182 | To get CLI command debug information, include the -d, or --debug flag when 183 | executing this command. 184 | 185 | # Continuous Integration 186 | 187 | In order to build OpenWhisk CLI binaries with good quality, OpenWhisk CLI uses 188 | Travis CI as the continuous delivery service for Linux and Mac. OpenWhisk CLI is 189 | a Go project. Currently Travis CI supports the environments of Linux and Mac, 190 | but it is not available for Windows. We will add support of AppVeyor CI in 191 | future to run the test cases and build the binary for Windows. 192 | -------------------------------------------------------------------------------- /bin/cleanup-envs.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | PROJECT="_null_" 4 | PROJECTS="`oc get projects -o name | sed -e 's/project\///'`" 5 | DEMO_USER="developer" 6 | 7 | . ../libs/functions 8 | 9 | # HOW TO USE THIS SCRIPT... 10 | usage() { 11 | echo "${0} -p [ project_name | all ]" 12 | exit 13 | } 14 | 15 | # No point doing anything if we don't have any projects! 16 | if [ `echo ${PROJECTS} | wc -w` -eq 0 ] 17 | then 18 | echo "No projects to delete here!" 19 | exit 20 | fi 21 | 22 | #echo "Existing projects:" 23 | #echo "${PROJECTS}" 24 | 25 | # parse arguments 26 | while getopts ":p:" opt 27 | do 28 | case ${opt} in 29 | p) 30 | if [ "${OPTARG}" = "all" ] 31 | then 32 | PROJECT=$PROJECTS 33 | else 34 | PROJECT="${OPTARG}" 35 | fi 36 | ;; 37 | \?) 38 | echo "Invalid option: -${OPTARG}" 39 | usage 40 | exit 1 41 | ;; 42 | :) 43 | echo "Option -${OPTARG} requires an argument" 44 | usage 45 | exit 1 46 | ;; 47 | esac 48 | done 49 | 50 | # ask for project if none passed as args and we have something to delete! 51 | if [ "${PROJECT}" = "_null_" ] 52 | then 53 | echo "Choose project to delete:" 54 | select PROJECT in ${PROJECTS} 55 | do 56 | break 57 | done 58 | fi 59 | 60 | # START 61 | echo 62 | echo "REMOVE PROJECT(S)..." 63 | echo 64 | 65 | # Need to login into demo namespace... 66 | echo "Logging in as ${DEMO_USER} user..." 67 | oc login -u ${DEMO_USER} 68 | 69 | # Finally, do the dirty work 70 | if [ "${PROJECT}" != "_null_" -a "${PROJECT}" != "" ] 71 | then 72 | for p in ${PROJECT} 73 | do 74 | echo "Deleting project \"${p}\"..." 75 | oc delete project ${p} 2>/dev/null 76 | done 77 | else 78 | exit 79 | fi 80 | -------------------------------------------------------------------------------- /bin/create-ose3-app-ab-deployment.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | export APPNAME="ab-demo-app" 4 | APPv1="version=1" 5 | APPv2="version=2" 6 | DEMO_USER="developer" 7 | PROJECT="abdeployment" 8 | SRC="https://github.com/ffirg/ab-deploy.git" 9 | NAME="abdeploy.192.168.99.100.xip.io" 10 | LABELS="versioning=true" 11 | build_status="NULL" 12 | pods=4 13 | 14 | # include all our functions... 15 | . ../libs/functions 16 | 17 | # START 18 | echo 19 | echo "EXAMPLE OPENSHIFT v3 APP A-B ROLLING DEPLOYMENT" 20 | echo "*** BEFORE STARTING ENSURE APP IS VERSION ONE on $SRC ***" 21 | echo 22 | 23 | run_cmd echo "First login into OSE (as $DEMO_USER user)..." 24 | run_cmd run "oc login -u $DEMO_USER" 25 | 26 | # setup project 27 | run_cmd echo "Setup the $PROJECT project" 28 | run_cmd run "oc new-project $PROJECT --description \"Rolling A-B Deployment Example\"" 29 | run_cmd run "oc project $PROJECT" 30 | 31 | # do some dev work! 32 | run_cmd echo "Create new app - let's call it \"$APPNAME\"" 33 | run_cmd run "oc new-app $SRC --name=${APPNAME} --labels=$APPv1" 34 | 35 | # wait until the build is finished before going on... 36 | check_build ${APPNAME} 37 | 38 | run_cmd echo "Let's expose a route for the new service:" 39 | VERSION="v1" 40 | run_cmd run "oc expose service ${APPNAME} --name=${APPNAME}-${VERSION}" 41 | 42 | run_cmd echo "Let's now scale up the service, to cope with more incoming load..." 43 | oc scale dc/${APPNAME} --replicas=$pods 44 | 45 | run_cmd echo "We should now have $pods pods running..." 46 | run_cmd run "oc get pods" 47 | 48 | run_cmd echo "We can check what we're hitting with a simple curl test:" 49 | for i in {1..10}; do curl `oc get route|grep "${APPNAME}-${VERSION}"|awk '{print $2}'`; echo " "; done 50 | 51 | # Make change to source code... 52 | echo 53 | run_cmd echo "GO MAKE A CHANGE TO THE SOURCE CODE @ ${SRC} and change VERSION 1 to VERSION 2 in index.php" 54 | 55 | #run_cmd echo "Create a new version of our app..." 56 | VERSION="v2" 57 | run_cmd run "oc new-app $SRC --name=${APPNAME}-${VERSION} --labels=$APPv2" 58 | 59 | # wait until the build is finished before going on... 60 | check_build ${APPNAME}-${VERSION} 61 | 62 | run_cmd echo "Check again the number of pods running..." 63 | run_cmd run "oc get pods" 64 | 65 | run_cmd echo "Let's expose a second route for the new version:" 66 | #run_cmd run "oc expose service ${APPNAME}-v2 --name=${APPNAME}-v2 --hostname=v2.${NAME}" 67 | run_cmd run "oc expose service ${APPNAME}-${VERSION} --name=${APPNAME}-${VERSION}" 68 | 69 | run_cmd echo "and do the curl test again:" 70 | #for i in {1..10}; do curl v2.${NAME}; echo " "; done 71 | for i in {1..10}; do curl `oc get route|grep "${APPNAME}-${VERSION}"|awk '{print $2}'`; echo " "; done 72 | 73 | run_cmd echo "Now let's scale down $APPv1 and $APPv2 up..." 74 | run_cmd run "oc scale dc/${APPNAME} --replicas=2" 75 | run_cmd run "oc scale dc/${APPNAME}-v2 --replicas=2" 76 | 77 | run_cmd echo "The curl test again:" 78 | #for i in {1..10}; do curl v1.${NAME}; echo " "; done 79 | #for i in {1..10}; do curl v2.${NAME}; echo " "; done 80 | for i in {1..10}; do curl `oc get route|grep "${APPNAME}"|awk '{print $2}'`; echo " "; done 81 | 82 | run_cmd echo "Version 2 looks great, so let's rolls that out and retire version 1..." 83 | run_cmd run "oc scale dc/${APPNAME} --replicas=0" 84 | run_cmd run "oc scale dc/${APPNAME}-v2 --replicas=4" 85 | 86 | run_cmd echo "We're now running only VERSION 2:" 87 | #for i in {1..10}; do curl v2.${NAME}; echo " "; done 88 | for i in {1..10}; do curl `oc get route|grep "${APPNAME}"|awk '{print $2}'`; echo " "; done 89 | 90 | # THE END 91 | -------------------------------------------------------------------------------- /bin/create-ose3-app-auto-cpu-scaling.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | export APP="welcome-php" 4 | DEMO_USER="demo" 5 | PROJECT="auto-cpu-scaling" 6 | SRC="https://github.com/RedHatWorkshops/${APP}.git" 7 | RESOURCE_LIMITS="../conf/resource-limits.yml" 8 | SCALAR="../conf/scaler.yml" 9 | TEMPLATE="openshift/php" 10 | build_status="NULL" 11 | 12 | # include all our functions... 13 | . ../libs/functions 14 | 15 | # START 16 | echo 17 | echo "EXAMPLE OPENSHIFT v3 HORIZONTAL AUTO CPU APP SCALING" 18 | echo 19 | 20 | run_cmd echo "First login into OSE (as $DEMO_USER user)..." 21 | run_cmd run "oc login -u $DEMO_USER" 22 | 23 | # setup project 24 | run_cmd echo "Setup the $PROJECT project" 25 | run_cmd run "oc new-project $PROJECT --description \"Example of Horizontal Auto CPU scaling\"" 26 | run_cmd run "oc project $PROJECT" 27 | 28 | # need to setup resource limits on the project first... 29 | run_cmd echo "Creating Resource Limits for this project..." 30 | run_cmd run "sudo -s oc create -f ${RESOURCE_LIMITS} -n ${PROJECT}" 31 | 32 | # Create the application... 33 | run_cmd echo "Create a new application - ${APP}" 34 | run_cmd run "oc new-app ${TEMPLATE}~${SRC}" 35 | 36 | # wait until the build is finished before going on... 37 | check_build ${APP} 38 | 39 | run_cmd echo "Expose a route to the service..." 40 | run_cmd run "oc expose svc ${APP}" 41 | 42 | run_cmd echo "Setup the auto scaling metrics..." 43 | run_cmd run "oc create -f ${SCALAR} -n ${PROJECT}" 44 | 45 | # Initiate and wait for HPA setup to complete... 46 | check_hpa 47 | 48 | # Now let's generate some web load so we can test the metrics 49 | # we'll use ab for that... 50 | run_cmd echo "Now we'll generate some web traffic/load to test..." 51 | run_cmd run "sudo yum -y install httpd-tools >/dev/null 2>&1" 52 | run_cmd run "nohup ab -n 100000000 -c 75 http://${APP}-${PROJECT}.apps.example.com/ >/dev/null 2>&1 &" 53 | 54 | # Now just watch until CPU load goes above target and back down again 55 | run_cmd echo "Now let's watch the CPU load and see what happens in the GUI when load goes above target (more pods created)...ctrl-C to end..." 56 | run_cmd run "oc get hpa --watch" 57 | 58 | # THE END 59 | -------------------------------------------------------------------------------- /bin/create-ose3-app-bluegreen-deployment.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | RED='\033[0;31m' 4 | GREEN='\033[0;32m' 5 | BLUE='\033[0;34m' 6 | NC='\033[0m' # No Color 7 | export EDITOR=vim # needed on Mac for a workaround to using vi! 8 | 9 | export BLUE_APP="blue" 10 | export GREEN_APP="green" 11 | USER="developer" 12 | PROJECT="bluegreen" 13 | SRC="https://github.com/ffirg/bluegreen.git" 14 | build_status="NULL" 15 | 16 | # include all our functions... 17 | . ../libs/functions 18 | 19 | # START 20 | echo 21 | echo "EXAMPLE OPENSHIFT v3 APP BLUE/GREEN DEPLOYMENT" 22 | echo -e "*** ENSURE color is set to ${BLUE}${BLUE_APP}${NC} first in $SRC image.php ***" 23 | echo 24 | 25 | run_cmd echo -e "${RED}First login into OSE (as $USER user)...${NC}" 26 | run_cmd run "oc login -u $USER" 27 | 28 | # setup project 29 | run_cmd echo -e "${RED}Create the $PROJECT project${NC}" 30 | run_cmd run "oc new-project $PROJECT --description \"BlueGreen Deployment\"" 31 | run_cmd run "oc project $PROJECT" 32 | 33 | # do some dev work! 34 | run_cmd echo -e "${RED}Create new app - call it the \"$BLUE_APP\" service${NC}" 35 | run_cmd run "oc new-app $SRC --name=$BLUE_APP" 36 | 37 | # wait until the build is finished before going on... 38 | check_build $BLUE_APP 39 | 40 | run_cmd echo -e "${RED}Let's take a look at the build log...${NC}" 41 | run_cmd run "oc logs build/${BLUE_APP}-1" 42 | 43 | run_cmd echo -e "${RED}Check out the service name:${NC}" 44 | run_cmd run "oc get svc" 45 | 46 | run_cmd echo -e "${RED}We have no route, so the service isn't exposed:${NC}" 47 | run_cmd run "oc get route" 48 | 49 | run_cmd echo -e "${RED}Let's expose the service now...${NC}" 50 | #run_cmd run "oc expose svc blue --name=bluegreen --hostname=bluegreen.192.168.99.100.xip.io" 51 | run_cmd run "oc expose svc blue --name=bluegreen" 52 | 53 | run_cmd echo "NOW CHANGE THE SOURCE CODE @ ${SRC} . Change image.php from ${BLUE}${BLUE_APP}${NC} to ${GREEN}${GREEN_APP}${NC}." 54 | 55 | run_cmd echo -e "${RED}Create new app - call it the \"$GREEN_APP\" service${NC}" 56 | run_cmd run "oc new-app $SRC --name=$GREEN_APP" 57 | 58 | # wait until the build is finished before going on... 59 | check_build $GREEN_APP 60 | 61 | run_cmd echo -e "${RED}Check out the service names again:${NC}" 62 | run_cmd run "oc get svc" 63 | 64 | run_cmd echo -e "${RED}Now let's change the route to expose the new service:${NC}" 65 | run_cmd echo "You can edit the route directly using: oc edit route $PROJECT" 66 | run_cmd echo "Or even directly with oc patch" 67 | run_cmd echo "But we'll do this using good old sed :)" 68 | run_cmd run "oc get route/bluegreen -o yaml | sed -e 's/name: blue$/name: green/' | oc replace -f -" 69 | # can also now use 'oc patch' directly 70 | # oc patch route/bluegreen -p '{"spec":{"to":{"name":"blue"}}}' 71 | 72 | run_cmd echo -e "${RED}DANGER! DANGER! Code is broken, switch back quick!!!${NC}" 73 | run_cmd run "oc get route/bluegreen -o yaml | sed -e 's/name: green$/name: blue/' | oc replace -f -" 74 | 75 | # THE END 76 | -------------------------------------------------------------------------------- /bin/create-ose3-app-from-source-mono.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP="mono" 4 | SRC="https://github.com/ffirg/mono.git" 5 | DEMO_USER="developer" 6 | PROJECT="mono" 7 | build_status="NULL" 8 | 9 | # include all our functions... 10 | . ../libs/functions 11 | 12 | # START 13 | echo 14 | echo "HOW TO BUILD AN APP CONTAINER FROM SOURCE USING MONO AS AN EXAMPLE" 15 | echo 16 | 17 | run_cmd echo "First login into OSE (as $DEMO_USER user)..." 18 | run_cmd run "oc login -u $DEMO_USER" 19 | 20 | # setup project 21 | run_cmd echo "Setup the $PROJECT project" 22 | run_cmd run "oc new-project $PROJECT --description \"Mono Example App\"" 23 | run_cmd run "oc project $PROJECT" 24 | 25 | # create the new app 26 | run_cmd echo "Create a new Mono app from source..." 27 | run_cmd run "oc new-app ${SRC}" 28 | 29 | # wait until the build is finished before going on... 30 | sleep 10 && check_build ${APP} 31 | 32 | run_cmd echo "Let's expose the service so it's accessible..." 33 | run_cmd run "oc expose service $APP" 34 | 35 | run_cmd echo "Go check the console and access the app" 36 | -------------------------------------------------------------------------------- /bin/create-ose3-app-mlbparks.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | RED='\033[0;31m' 4 | NC='\033[0m' # No Color 5 | 6 | APP="mlbparks-wildfly" 7 | TEMPLATE="https://raw.githubusercontent.com/gshipley/openshift3mlbparks/master/mlbparks-template-wildfly.json" 8 | USER="developer" 9 | PROJECT="mlbparks" 10 | build_status="NULL" 11 | 12 | # include all our functions... 13 | . ../libs/functions 14 | 15 | # START 16 | echo 17 | echo "HOW TO WIRE UP A MULTI-TIERED OPENSHIFT v3 MICROSERVICE - MLBPARKS JBOSS/MONGO EXAMPLE" 18 | echo 19 | 20 | run_cmd echo "${RED}First login into OSE (as $USER user)...${NC}" 21 | run_cmd run "oc login -u $USER" 22 | 23 | # setup project 24 | run_cmd echo "${RED}Create the $PROJECT project${NC}" 25 | run_cmd run "oc new-project $PROJECT --description \"MLBParks Demo App\"" 26 | run_cmd run "oc project $PROJECT" 27 | 28 | # create the new front-end app 29 | run_cmd echo "${RED}Create a new ${APP} template...${NC}" 30 | run_cmd run "oc create -f ${TEMPLATE}" 31 | 32 | run_cmd echo "${RED}Create a new ${APP} app...${NC}" 33 | run_cmd run "oc new-app ${APP}" 34 | 35 | run_cmd echo "${RED}Go to openshift console and review builds etc...${NC}" 36 | -------------------------------------------------------------------------------- /bin/create-ose3-app-promo-envs.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | export APP="myapp" 4 | DEMO_USER="demo" 5 | DEV_USER="dev1" 6 | TEST_USER="test1" 7 | DEV_ENV="development" 8 | TEST_ENV="testing" 9 | build_status="NULL" 10 | 11 | . ../libs/functions 12 | 13 | # START 14 | echo 15 | echo "WE'LL CREATE A DEV OPENSHIFT v3 APP + PROMOTE TO THE TEST (QA) ENV" 16 | echo 17 | 18 | # pre-reqs - local user accounts: 19 | sudo useradd dev1 >/dev/null 2>&1 20 | sudo passwd -f -u dev1 >/dev/null 2>&1 21 | sudo useradd test1 >/dev/null 2>&1 22 | sudo passwd -f -u test1 >/dev/null 2>&1 23 | 24 | 25 | run_cmd echo "First login into OSE (as $DEMO_USER user)..." 26 | run_cmd run "oc login -u $DEMO_USER" 27 | 28 | # setup dev project and permissions 29 | run_cmd echo "Setup the DEVELOPMENT Environment and permissions" 30 | run_cmd run "oc new-project $DEV_ENV --description \"Development Env\"" 31 | run_cmd run "oc policy add-role-to-user edit dev1" 32 | run_cmd run "oc policy add-role-to-user view test1" 33 | 34 | # setup test/QA project and setup permissions 35 | run_cmd echo "Now setup the TEST Environment and permissions" 36 | run_cmd run "oc new-project $TEST_ENV --description=\"Test Env\"" 37 | run_cmd run "oc policy add-role-to-user edit test1" 38 | run_cmd run "oc policy add-role-to-group system:image-puller system:serviceaccounts:testing -n development" 39 | 40 | # do some dev work! 41 | run_cmd echo "Do some DEV work!! Deploy the \"$APP\" application" 42 | run_cmd run "oc login -u dev1 -p ''" 43 | run_cmd run "oc get projects" 44 | run_cmd run "oc project development" 45 | # run_cmd run "oc new-app --template=eap64-basic-s2i https://github.com/VeerMuchandi/kitchensink.git name=$APP" 46 | run_cmd run "oc new-app openshift/ruby-20-centos7~https://github.com/openshift/ruby-hello-world.git --name=$APP" 47 | 48 | # force the build to start else there may be an variant timeout! 49 | run_cmd echo "Start an image build for $APP" 50 | run_cmd run "oc start-build $APP" 51 | run_cmd echo "The build is now going - watch until it completes to ensure there's an image available..." 52 | build_status="`oc get builds | grep ${APP}-1 | awk '{print $4}'`" 53 | while true 54 | do 55 | if [ -z $build_status ] 56 | then 57 | echo "Whoops! There is no build image, something went wrong :(" 58 | exit 99 59 | else 60 | until [ $build_status = "Complete" ] 61 | do 62 | echo "$APP build is still $build_status..." 63 | sleep 10 64 | build_status="`oc get builds | grep ${APP}-1 | awk '{print $4}'`" 65 | done 66 | fi 67 | echo "$APP build is DONE!" 68 | echo 69 | break 70 | done 71 | 72 | run_cmd echo "This is the build log..." 73 | run_cmd run "oc build-logs $APP-1" 74 | 75 | oc expose service myapp 76 | 77 | run_cmd echo "Check out the image stream:" 78 | run_cmd run "oc get is -n ${DEV_ENV}" 79 | 80 | # *this is messy, really quick and dirty!* 81 | #image_ref="`oc get is $APP -o json | grep dockerImageReference | awk -F\\" '{print $4}' | tail -1`" 82 | image_ref="latest" 83 | version="v1" 84 | 85 | run_cmd echo "We now tag the image with a \"VERSION 1\" label..." 86 | run_cmd run "oc tag ${DEV_ENV}/${APP}:${image_ref} ${DEV_ENV}/${APP}:${version}" 87 | run_cmd run "oc get is -n ${DEV_ENV}" 88 | 89 | # now promote image into test env 90 | run_cmd echo "Now login to the TEST Environment and 'PROMOTE' the application..." 91 | run_cmd run "oc login -u test1 -p ''" 92 | run_cmd run "oc project testing" 93 | run_cmd run "oc new-app ${DEV_ENV}/${APP}:${version} -n ${TEST_ENV}" 94 | 95 | run_cmd echo "There is no external access so we setup a route to expose the service..." 96 | run_cmd run "oc expose service myapp" 97 | 98 | # make change to source code... 99 | run_cmd echo "NOW SOMEONE MAKES CHANGES TO THE DEV CODE...TIME PASSES..." 100 | run_cmd run "oc login -u dev1 -p ''" 101 | run_cmd run "oc start-build myapp" 102 | run_cmd run "oc get builds" 103 | 104 | run_cmd echo "The DEV environment will be on a new release, but TEST remains on the old one still" 105 | run_cmd echo "Use the same 'oc tag' command as before to promote the latest image into the TEST environment" 106 | 107 | # THE END 108 | -------------------------------------------------------------------------------- /bin/create-ose3-cnv.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | export PATH=$PATH:. 4 | 5 | APP="" 6 | SRC="" 7 | DEMO_USER="system" 8 | DEMO_USER_PW="admin" 9 | PROJECT="container-vm" 10 | IMAGE="centos/httpd-24-centos7" 11 | DESC="Container Native Virtualisation" 12 | VERSION="v0.4.1" 13 | OS="`uname -s | tr '[A-Z]' '[a-z]'`" 14 | ARCH="`uname -p | tr '[A-Z]' '[a-z]'`" 15 | KUBECTL_URL="https://storage.googleapis.com/kubernetes-release/release/v1.10.3/bin/${OS}/${ARCH}/kubectl" 16 | VIRTCTL_URL="https://github.com/kubevirt/kubevirt/releases/download/$VERSION/virtctl-$VERSION-${OS}-amd64" 17 | KUBECTL="kubectl" 18 | VIRTCTL="virtctl" 19 | build_status="NULL" 20 | 21 | # include all our functions... 22 | . ../libs/functions 23 | 24 | # START 25 | echo 26 | echo "EXAMPLE VM RUN INSIDE AN OPENSHIFT CONTAINER!!!" 27 | echo 28 | 29 | run_cmd echo "First login into OSE..." 30 | run_cmd run "oc login -u $DEMO_USER -p $DEMO_USER_PW" 31 | 32 | 33 | # need kubectl CLI binary 34 | if [ ! -x $KUBECTL ] 35 | then 36 | curl -Lk -o $KUBECTL https://storage.googleapis.com/kubernetes-release/release/v1.10.3/bin/linux/amd64/kubectl && chmod +x $KUBECTL 37 | fi 38 | 39 | kubectl create -f https://github.com/kubevirt/kubevirt/releases/download/$VERSION/kubevirt.yaml 40 | oc adm policy add-scc-to-user privileged system:serviceaccount:kube-system:kubevirt-privileged 41 | oc adm policy add-scc-to-user privileged system:serviceaccount:kube-system:kubevirt-controller 42 | oc adm policy add-scc-to-user privileged system:serviceaccount:kube-system:kubevirt-infra 43 | oc apply -f https://github.com/kubevirt/kubevirt/releases/download/${VERSION}/kubevirt.yaml 44 | 45 | # need virtclt CLI binary 46 | if [ ! -x $VIRTCTL ] 47 | then 48 | curl -Lk -o $VIRTCTL https://github.com/kubevirt/kubevirt/releases/download/$VERSION/virtctl-$VERSION-linux-amd64 && chmod +x $VIRTCTL 49 | fi 50 | 51 | # setup project 52 | run_cmd echo "Setup the $PROJECT project" 53 | run_cmd run "oc new-project $PROJECT --description \"$DESC\"" 54 | run_cmd run "oc project $PROJECT" 55 | 56 | kubectl apply -f https://raw.githubusercontent.com/kubevirt/demo/master/manifests/vm.yaml 57 | kubectl get vms testvm -o yaml | grep "phase:" 58 | virtctl start testvm 59 | kubectl get vms 60 | virtctl console testvm 61 | 62 | -------------------------------------------------------------------------------- /bin/create-ose3-games.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | APP="" 4 | SRC="" 5 | DEMO_USER="developer" 6 | PROJECT="games" 7 | IMAGE="centos/httpd-24-centos7" 8 | build_status="NULL" 9 | 10 | # include all our functions... 11 | . ../libs/functions 12 | 13 | # START 14 | echo 15 | echo "EXAMPLE HTML5 GAMES RUN ON OPENSHIFT" 16 | echo 17 | 18 | run_cmd echo "First login into OSE (as $DEMO_USER user)..." 19 | run_cmd run "oc login -u $DEMO_USER" 20 | 21 | # setup project 22 | run_cmd echo "Setup the $PROJECT project" 23 | run_cmd run "oc new-project $PROJECT --description \"HTML5 Based Games\"" 24 | run_cmd run "oc project $PROJECT" 25 | 26 | # choose a game! 27 | echo "Which game would you like?" 28 | echo "" 29 | echo "1 Flappy Birds" 30 | echo "2 Arena5" 31 | echo "3 Pixel Race" 32 | echo "4 2048" 33 | echo "5 Pacman" 34 | echo "6 Hextris" 35 | echo "7 Pool" 36 | echo "8 Battleships (2 Player)" 37 | echo "" 38 | read ans 39 | 40 | case "$ans" in 41 | 1 ) 42 | export APP="flappy" 43 | export SRC="https://github.com/hyspace/flappy" 44 | ;; 45 | 2 ) 46 | export APP="arena5" 47 | export SRC="https://github.com/kevinroast/arena5" 48 | ;; 49 | 3 ) 50 | export APP="pixel-race" 51 | export SRC="https://github.com/needim/pixel-race-game" 52 | ;; 53 | 4 ) 54 | export APP="game-2048" 55 | export SRC="https://github.com/gabrielecirulli/2048" 56 | ;; 57 | 5 ) 58 | export APP="pacman" 59 | export SRC="https://github.com/daleharvey/pacman" 60 | ;; 61 | 6 ) 62 | export APP="hextris" 63 | export SRC="https://github.com/Hextris/hextris" 64 | ;; 65 | 7 ) 66 | export APP="pool" 67 | export SRC="https://github.com/henshmi/Classic-Pool-Game" 68 | ;; 69 | 8 ) 70 | export APP="battleships" 71 | export SRC="https://github.com/nixsolutions/demo-phaser-battleship" 72 | ;; 73 | esac 74 | 75 | run_cmd run "oc new-app ${IMAGE}~${SRC} --name=\"${APP}\"" 76 | 77 | # wait until the build is finished before going on... 78 | sleep 10 && check_build ${APP} 79 | 80 | run_cmd echo "Let's expose the service so it's accessible..." 81 | run_cmd run "oc expose service $APP" 82 | 83 | run_cmd echo "Go check the console and access the app" 84 | -------------------------------------------------------------------------------- /bin/create-ose3-jenkins-pipeline-example.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | RED='\033[0;31m' 4 | GREEN='\033[0;32m' 5 | BLUE='\033[0;34m' 6 | NC='\033[0m' # No Color 7 | export EDITOR=vim # needed on Mac for a workaround to using vi! 8 | export APP="jenkins" 9 | USER="developer" 10 | PROJECT="pipeline-example" 11 | build_status="NULL" 12 | 13 | # include all our functions... 14 | . ../libs/functions 15 | 16 | # START 17 | echo 18 | echo "EXAMPLE OPENSHIFT v3 JENKINS PIPELINE-AS-CODE EXAMPLE" 19 | echo -e "*** ENSURE color is set to ${BLUE}${BLUE_APP}${NC} first in $SRC image.php ***" 20 | echo 21 | 22 | run_cmd echo -e "${RED}First login into OSE (as $USER user)...${NC}" 23 | run_cmd run "oc login -u $USER" 24 | 25 | # setup project 26 | run_cmd echo -e "${RED}Create the $PROJECT project${NC}" 27 | run_cmd run "oc new-project $PROJECT --description \"Jenkins Pipeline-As-Code Example\"" 28 | run_cmd run "oc project $PROJECT" 29 | 30 | # do some dev work! 31 | run_cmd echo -e "${RED}Create new app..." 32 | run_cmd run "oc new-app jenkins-pipeline-example" 33 | 34 | # start a pipeline build/deploy 35 | run_cmd echo -e "${RED}Start Pipeline build/deployment..." 36 | run_cmd run "oc start-build sample-pipeline" 37 | 38 | # THE END 39 | -------------------------------------------------------------------------------- /bin/create-ose3-resource-quota-limits.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | ADMIN_USER="system:admin" 4 | build_status="NULL" 5 | LIBDIR="../libs" 6 | CONFDIR="../conf" 7 | QUOTA="resource-quota.json" 8 | LIMITS="resource-limits.json" 9 | USER="developer" 10 | 11 | . ${LIBDIR}/functions 12 | 13 | # START 14 | echo 15 | echo "*** APPLY A RESOURCE QUOTA AND LIMITS TO A PROJECT ***" 16 | echo 17 | 18 | # Need to run as root so we are SYSTEM:ADMIN 19 | if [ ${MY_UID} -ne 0 ] 20 | then 21 | echo "Need to be root for this one!" 22 | exit 1 23 | fi 24 | 25 | # Login as a user with cluster admin rights 26 | run_cmd echo "Login as a system admin user..." 27 | run_cmd run "oc login -u ${ADMIN_USER}" 28 | echo 29 | echo "Choose a project to assign the quotas to: " 30 | echo "${OC_PROJECTS}" 31 | echo 32 | echo -n "Enter project name: " 33 | read PROJECT 34 | 35 | run_cmd echo "Log in to project..." 36 | run_cmd run "oc project ${PROJECT}" 37 | 38 | run_cmd echo "Apply resource quota for the PROJECT..." 39 | run_cmd run "oc create -f ${CONFDIR}/${QUOTA}" 40 | 41 | # Show quotas applied 42 | run_cmd echo "Here's the quota applied:" 43 | run_cmd run "oc get quota" 44 | 45 | run_cmd echo "Now apply resource limits for PODS/CONTAINERS..." 46 | run_cmd run "oc create -f ${CONFDIR}/${QUOTA}" 47 | 48 | run_cmd echo "You can see the quotas and limits set under Resources->Quota in the GUI" 49 | 50 | run_cmd echo "Now let's remove them..." 51 | run_cmd run "oc delete -f ${CONFDIR}/${QUOTA}" 52 | -------------------------------------------------------------------------------- /bin/create-ose3-statefulset.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # example coded the most excellent blog by Michael Hausenblas https://goo.gl/C9g356 4 | 5 | APP="mehdb" 6 | STS="mehdb" 7 | PROJECT="mehdb" 8 | DEMO_USER="developer" 9 | build_status="NULL" 10 | 11 | # include all our functions... 12 | . ../libs/functions 13 | 14 | cleanup () { 15 | oc delete sts ${STS} -n ${PROJECT} 2>/dev/null 16 | oc delete pvc -n ${PROJECT} --all 2>/dev/null 17 | oc delete svc ${APP} -n ${PROJECT} 2>/dev/null 18 | oc delete route ${APP} -n ${PROJECT} 2>/dev/null 19 | oc delete project ${PROJECT} 2>/dev/null 20 | rm -rf ${APP} 2>/dev/null 21 | exit 22 | } 23 | 24 | if [ "$1" = "cleanup" ] 25 | then 26 | cleanup 27 | fi 28 | 29 | # START 30 | echo 31 | echo "KUBERNETES STATEFULSET EXAMPLE FOR USE WITH MINISHIFT" 32 | echo 33 | 34 | run_cmd echo "First login into OSE (as $DEMO_USER user)..." 35 | run_cmd run "oc login -u $DEMO_USER" 36 | 37 | # setup project 38 | run_cmd echo "Setup the $PROJECT project" 39 | run_cmd run "oc new-project $PROJECT --description \"Statefulset Example\"" 40 | run_cmd run "oc project $PROJECT" 41 | 42 | run_cmd echo "Git clone from the example repo..." 43 | git clone https://github.com/ffirg/mehdb.git && cd mehdb 44 | 45 | run_cmd echo "Insert the config using oc apply..." 46 | run_cmd run "oc apply -f app.yaml -n ${PROJECT}" 47 | 48 | run_cmd echo "Let's expose the service so it's accessible..." 49 | run_cmd run "oc expose service $APP" 50 | 51 | pod_status="`oc get pods -n mehdb | grep ${APP}-0 | awk '{print $3}'`" 52 | until [ $pod_status = "Running" ] 53 | do 54 | echo "Waiting for pod to be running..." 55 | sleep 5 56 | pod_status="`oc get pods -n mehdb | grep ${APP}-0 | awk '{print $3}'`" 57 | done 58 | 59 | run_cmd echo "Let's log into a container and inject some sample data..." 60 | oc rsh mehdb-0 < /tmp/test 62 | curl -L -XPUT -T /tmp/test mehdb:9876/set/test 63 | EOF 64 | 65 | run_cmd echo "We can scale up (& down) the service..." 66 | run_cmd run "oc scale -n ${PROJECT} sts ${STS} --replicas=4" 67 | -------------------------------------------------------------------------------- /bin/load_cpu.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | # 4 | # load_cpu.sh: artificial CPU load generator 5 | # 6 | 7 | # Usage: lc [number_of_cpus_to_load [number_of_seconds] ] 8 | 9 | lc() { 10 | ( 11 | pids="" 12 | cpus=${1:-1} 13 | seconds=${2:-60} 14 | echo loading $cpus CPUs for $seconds seconds 15 | trap 'for p in $pids; do kill $p; done' 0 16 | for ((i=0;i/dev/null 2>&1 40 | cat > ${CONFDIR}/${MDSA} </dev/null 2>&1 49 | chmod 755 ${CONFDIR} >/dev/null 2>&1 50 | chmod 644 ${CONFDIR}/${MDSA} >/dev/null 2>&1 51 | fi 52 | 53 | run_cmd echo "Creating Metrics Deployer Service Account..." 54 | run_cmd run "oc create -f ${CONFDIR}/${MDSA}" 55 | 56 | run_cmd echo "Grant correct permissions to accounts..." 57 | run_cmd run "oadm policy add-role-to-user edit system:serviceaccount:openshift-infra:metrics-deployer" 58 | run_cmd run "oadm policy add-cluster-role-to-user cluster-reader system:serviceaccount:openshift-infra:heapster" 59 | 60 | # uncomment the following to use your own certs 61 | #oc secrets new metrics-deployer hawkular-metrics.pem=/home/openshift/metrics/hm.pem \ 62 | #hawkular-metrics-ca.cert=/home/openshift/metrics/hm-ca.cert 63 | 64 | # else you can use the default auto-generated certs... 65 | run_cmd echo "Use auto-generated certs for trust..." 66 | run_cmd run "oc secrets new metrics-deployer nothing=/dev/null" 67 | 68 | METRICS="metrics.yaml" 69 | METRICS_TEMPLATE="/usr/share/ansible/openshift-ansible/roles/openshift_examples/files/examples/infrastructure-templates/enterprise/metrics-deployer.yaml" 70 | 71 | echo "Ensuring we have a metrics config file..." 72 | if [ ! -r ${CONFDIR}/{METRICS} ] 73 | then 74 | if [ -r ${METRICS_TEMPLATE} ] 75 | then 76 | cp ${METRICS_TEMPLATE} ${CONFDIR}/${METRICS} 77 | fi 78 | fi 79 | 80 | run_cmd echo "Setting up Hawkular metrics...this will run for some time in the background..." 81 | run_cmd run "oc process -f ${CONFDIR}/${METRICS} -v IMAGE_PREFIX=openshift3/,IMAGE_VERSION=latest,HAWKULAR_METRICS_HOSTNAME=${OSE_MASTER},USE_PERSISTENT_STORAGE=false | oc create -f -" 82 | 83 | OSE_MASTER_CONFIG=/etc/origin/master/master-config.yaml 84 | TIMESTAMP="`date +%d%m%y_%m%S`" 85 | 86 | echo "Updating OSE Master Config (adding Metrics URL...)" 87 | if [ -r ${OSE_MASTER_CONFIG} ] 88 | then 89 | grep "metricsPublicURL:" ${OSE_MASTER_CONFIG} >/dev/null 2>&1 || \ 90 | ( cp ${OSE_MASTER_CONFIG} ${OSE_MASTER_CONFIG}.${TIMESTAMP} && \ 91 | echo "Made a copy of master file - ${OSE_MASTER_CONFIG}.${TIMESTAMP}" && \ 92 | sed -i '/assetConfig:/a\ \ metricsPublicURL: https://'"${OSE_MASTER}"'/hawkular/metrics' ${OSE_MASTER_CONFIG} ) 93 | fi 94 | 95 | echo "Restating Openshift Master..." 96 | systemctl restart atomic-openshift-master 97 | 98 | echo "WE SHOULD BE DONE HERE!" 99 | -------------------------------------------------------------------------------- /bin/setup-efk-logging.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/bash 2 | 3 | # 4 | # Setup OSE centralised container logs using EFK 5 | # 6 | 7 | OSE_MASTER="openshift.example.com" 8 | LIBDIR="../libs" 9 | CONFDIR="../conf" 10 | USER="demo" 11 | LDSA="logging-deployer-service-account.yml" 12 | PROJECT="logging" 13 | 14 | . ${LIBDIR}/functions 15 | 16 | # START 17 | echo 18 | echo "*** SETUP CENTRALISED OPENSHIFT EFK LOGGING ***" 19 | echo 20 | 21 | # Need to run as root so we are SYSTEM:ADMIN 22 | if [ ${MY_UID} -ne 0 ] 23 | then 24 | echo "Need to be root for this one!" 25 | exit 1 26 | fi 27 | 28 | run_cmd echo "Creating ${PROJECT} project..." 29 | run_cmd run "oc new-project ${PROJECT}" 30 | run_cmd echo "Log in to the ${PROJECT} project..." 31 | run_cmd run "oc project ${PROJECT}" 32 | 33 | run_cmd echo "Setting up deployer secrets (ssshhhh...)" 34 | run_cmd run "oc secrets new logging-deployer kibana.crt=../conf/kibana.crt kibana.key=../conf/kibana.key" 35 | 36 | if [ ! -r ${CONFDIR}/${LDSA} ] 37 | then 38 | echo "Whoops! ${LDSA} is missing :(" 39 | echo "Creating a sample one ..." 40 | mkdir ${CONFDIR} >/dev/null 2>&1 41 | cat > ${CONFDIR}/${LDSA} </dev/null 2>&1 50 | chmod 755 ${CONFDIR} >/dev/null 2>&1 51 | chmod 644 ${CONFDIR}/${LDSA} >/dev/null 2>&1 52 | fi 53 | 54 | run_cmd echo "Creating Logging Deployer Service Account..." 55 | run_cmd run "oc create -f ${CONFDIR}/${LDSA}" 56 | 57 | run_cmd echo "Grant correct permissions to accounts..." 58 | run_cmd run "oc policy add-role-to-user edit system:serviceaccount:logging:logging-deployer" 59 | 60 | echo "Run use command -> oc edit scc/privileged" 61 | echo "And add this line to the service accounts:" 62 | echo "- system:serviceaccount:logging:aggregated-logging-fluentd" 63 | read x 64 | 65 | run_cmd run "oadm policy add-cluster-role-to-user cluster-reader system:serviceaccount:logging:aggregated-logging-fluentd" 66 | 67 | 68 | LOGGING="logging.yaml" 69 | LOGGING_TEMPLATE="/usr/share/ansible/openshift-ansible/roles/openshift_examples/files/examples/infrastructure-templates/enterprise/logging-deployer.yaml" 70 | 71 | echo "Ensuring we have a logging config file..." 72 | if [ ! -r ${CONFDIR}/{LOGGING} ] 73 | then 74 | if [ -r ${LOGGING_TEMPLATE} ] 75 | then 76 | cp ${LOGGING_TEMPLATE} ${CONFDIR}/${LOGGING} 77 | fi 78 | fi 79 | 80 | run_cmd echo "Setting up logging deployer using a template..." 81 | run_cmd run "oc create -n openshift -f ${CONFDIR}/${LOGGING}" 82 | 83 | run_cmd echo "Run the deployer (this will take some time to complete in the background)..." 84 | run_cmd run "oc process logging-deployer-template -n openshift -v KIBANA_HOSTNAME=kibana.example.com,ES_CLUSTER_SIZE=1,PUBLIC_MASTER_URL=https://localhost:8443 | oc create -f -" 85 | 86 | echo "Once the deployer completes, run this command:" 87 | echo "oc process logging-support-template | oc create -f -" 88 | -------------------------------------------------------------------------------- /conf/README.md: -------------------------------------------------------------------------------- 1 | # Openshift 2 | Scripts in here are used by the ~bin shell scripts 3 | They include yaml and json based config files used for Openshift demos. 4 | -------------------------------------------------------------------------------- /conf/Template_Example.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "Template", 3 | "apiVersion": "v1", 4 | "metadata": { 5 | "name": "a-quickstart-keyvalue-application", 6 | "creationTimestamp": null, 7 | "annotations": { 8 | "description": "This is an example of a Ruby and MySQL application on OpenShift 3", 9 | "iconClass": "icon-ruby", 10 | "tags": "instant-app,ruby,mysql" 11 | } 12 | }, 13 | "objects": [ 14 | { 15 | "kind": "Service", 16 | "apiVersion": "v1", 17 | "metadata": { 18 | "name": "frontend", 19 | "creationTimestamp": null 20 | }, 21 | "spec": { 22 | "ports": [ 23 | { 24 | "name": "web", 25 | "protocol": "TCP", 26 | "port": 5432, 27 | "targetPort": 8080, 28 | "nodePort": 0 29 | } 30 | ], 31 | "selector": { 32 | "name": "frontend" 33 | }, 34 | "portalIP": "", 35 | "type": "ClusterIP", 36 | "sessionAffinity": "None" 37 | }, 38 | "status": { 39 | "loadBalancer": {} 40 | } 41 | }, 42 | { 43 | "kind": "Route", 44 | "apiVersion": "v1", 45 | "metadata": { 46 | "name": "example-route", 47 | "creationTimestamp": null 48 | }, 49 | "spec": { 50 | "host": "REPLACEME.com", 51 | "to": { 52 | "kind": "Service", 53 | "name": "frontend" 54 | } 55 | }, 56 | "spec": { 57 | "to": { 58 | "kind": "Service", 59 | "name": "frontend" 60 | } 61 | }, 62 | "status": {} 63 | }, 64 | { 65 | "kind": "ImageStream", 66 | "apiVersion": "v1", 67 | "metadata": { 68 | "name": "ruby-sample", 69 | "creationTimestamp": null 70 | }, 71 | "spec": {}, 72 | "status": { 73 | "dockerImageRepository": "" 74 | } 75 | }, 76 | { 77 | "kind": "ImageStream", 78 | "apiVersion": "v1", 79 | "metadata": { 80 | "name": "ruby-20-rhel7", 81 | "creationTimestamp": null 82 | }, 83 | "spec": { 84 | "dockerImageRepository": "registry.access.redhat.com/openshift3/ruby-20-rhel7" 85 | }, 86 | "status": { 87 | "dockerImageRepository": "" 88 | } 89 | }, 90 | { 91 | "kind": "BuildConfig", 92 | "apiVersion": "v1", 93 | "metadata": { 94 | "name": "ruby-sample-build", 95 | "creationTimestamp": null, 96 | "labels": { 97 | "name": "ruby-sample-build" 98 | } 99 | }, 100 | "spec": { 101 | "triggers": [ 102 | { 103 | "type": "github", 104 | "github": { 105 | "secret": "secret101" 106 | } 107 | }, 108 | { 109 | "type": "generic", 110 | "generic": { 111 | "secret": "secret101" 112 | } 113 | }, 114 | { 115 | "type": "imageChange", 116 | "imageChange": {} 117 | } 118 | ], 119 | "source": { 120 | "type": "Git", 121 | "git": { 122 | "uri": "git://github.com/openshift/ruby-hello-world.git", 123 | "ref": "master" 124 | } 125 | }, 126 | "strategy": { 127 | "type": "Source", 128 | "sourceStrategy": { 129 | "from": { 130 | "kind": "ImageStreamTag", 131 | "name": "ruby:latest", 132 | "namespace": "openshift" 133 | }, 134 | "incremental": true 135 | } 136 | }, 137 | "output": { 138 | "to": { 139 | "kind": "ImageStreamTag", 140 | "name": "ruby-sample:latest" 141 | } 142 | }, 143 | "resources": {} 144 | }, 145 | "status": { 146 | "lastVersion": 0 147 | } 148 | }, 149 | { 150 | "kind": "DeploymentConfig", 151 | "apiVersion": "v1", 152 | "metadata": { 153 | "name": "frontend", 154 | "creationTimestamp": null 155 | }, 156 | "spec": { 157 | "strategy": { 158 | "type": "Recreate" 159 | }, 160 | "triggers": [ 161 | { 162 | "type": "ImageChange", 163 | "imageChangeParams": { 164 | "automatic": true, 165 | "containerNames": [ 166 | "ruby-helloworld" 167 | ], 168 | "from": { 169 | "kind": "ImageStreamTag", 170 | "name": "ruby-sample:latest" 171 | }, 172 | "lastTriggeredImage": "" 173 | } 174 | }, 175 | { 176 | "type": "ConfigChange" 177 | } 178 | ], 179 | "replicas": 2, 180 | "selector": { 181 | "name": "frontend" 182 | }, 183 | "template": { 184 | "metadata": { 185 | "creationTimestamp": null, 186 | "labels": { 187 | "name": "frontend" 188 | } 189 | }, 190 | "nodeSelector": { 191 | "region": "primary" 192 | }, 193 | "spec": { 194 | "containers": [ 195 | { 196 | "name": "ruby-helloworld", 197 | "image": "ruby-sample", 198 | "ports": [ 199 | { 200 | "containerPort": 8080, 201 | "protocol": "TCP" 202 | } 203 | ], 204 | "env": [ 205 | { 206 | "name": "ADMIN_USERNAME", 207 | "value": "${ADMIN_USERNAME}" 208 | }, 209 | { 210 | "name": "ADMIN_PASSWORD", 211 | "value": "${ADMIN_PASSWORD}" 212 | }, 213 | { 214 | "name": "MYSQL_USER", 215 | "value": "${MYSQL_USER}" 216 | }, 217 | { 218 | "name": "MYSQL_PASSWORD", 219 | "value": "${MYSQL_PASSWORD}" 220 | }, 221 | { 222 | "name": "MYSQL_DATABASE", 223 | "value": "${MYSQL_DATABASE}" 224 | } 225 | ], 226 | "resources": {}, 227 | "terminationMessagePath": "/dev/termination-log", 228 | "imagePullPolicy": "IfNotPresent", 229 | "capabilities": {}, 230 | "securityContext": { 231 | "capabilities": {}, 232 | "privileged": false 233 | } 234 | } 235 | ], 236 | "restartPolicy": "Always", 237 | "dnsPolicy": "ClusterFirst", 238 | "serviceAccount": "" 239 | } 240 | } 241 | }, 242 | "status": {} 243 | }, 244 | { 245 | "kind": "Service", 246 | "apiVersion": "v1", 247 | "metadata": { 248 | "name": "database", 249 | "creationTimestamp": null 250 | }, 251 | "spec": { 252 | "ports": [ 253 | { 254 | "name": "db", 255 | "protocol": "TCP", 256 | "port": 5434, 257 | "targetPort": 3306, 258 | "nodePort": 0 259 | } 260 | ], 261 | "selector": { 262 | "name": "database" 263 | }, 264 | "portalIP": "", 265 | "type": "ClusterIP", 266 | "sessionAffinity": "None" 267 | }, 268 | "status": { 269 | "loadBalancer": {} 270 | } 271 | }, 272 | { 273 | "kind": "DeploymentConfig", 274 | "apiVersion": "v1", 275 | "metadata": { 276 | "name": "database", 277 | "creationTimestamp": null 278 | }, 279 | "spec": { 280 | "strategy": { 281 | "type": "Recreate" 282 | }, 283 | "triggers": [ 284 | { 285 | "type": "ConfigChange" 286 | } 287 | ], 288 | "replicas": 1, 289 | "selector": { 290 | "name": "database" 291 | }, 292 | "template": { 293 | "metadata": { 294 | "creationTimestamp": null, 295 | "labels": { 296 | "name": "database" 297 | } 298 | }, 299 | "nodeSelector": { 300 | "region": "primary" 301 | }, 302 | "spec": { 303 | "containers": [ 304 | { 305 | "name": "ruby-helloworld-database", 306 | "image": "registry.access.redhat.com/openshift3/mysql-55-rhel7:latest", 307 | "ports": [ 308 | { 309 | "containerPort": 3306, 310 | "protocol": "TCP" 311 | } 312 | ], 313 | "env": [ 314 | { 315 | "name": "MYSQL_USER", 316 | "value": "${MYSQL_USER}" 317 | }, 318 | { 319 | "name": "MYSQL_PASSWORD", 320 | "value": "${MYSQL_PASSWORD}" 321 | }, 322 | { 323 | "name": "MYSQL_DATABASE", 324 | "value": "${MYSQL_DATABASE}" 325 | } 326 | ], 327 | "resources": {}, 328 | "terminationMessagePath": "/dev/termination-log", 329 | "imagePullPolicy": "Always", 330 | "capabilities": {}, 331 | "securityContext": { 332 | "capabilities": {}, 333 | "privileged": false 334 | } 335 | } 336 | ], 337 | "restartPolicy": "Always", 338 | "dnsPolicy": "ClusterFirst", 339 | "serviceAccount": "" 340 | } 341 | } 342 | }, 343 | "status": {} 344 | } 345 | ], 346 | "parameters": [ 347 | { 348 | "name": "ADMIN_USERNAME", 349 | "description": "administrator username", 350 | "generate": "expression", 351 | "from": "admin[A-Z0-9]{3}" 352 | }, 353 | { 354 | "name": "ADMIN_PASSWORD", 355 | "description": "administrator password", 356 | "generate": "expression", 357 | "from": "[a-zA-Z0-9]{8}" 358 | }, 359 | { 360 | "name": "MYSQL_USER", 361 | "description": "database username", 362 | "generate": "expression", 363 | "from": "user[A-Z0-9]{3}" 364 | }, 365 | { 366 | "name": "MYSQL_PASSWORD", 367 | "description": "database password", 368 | "generate": "expression", 369 | "from": "[a-zA-Z0-9]{8}" 370 | }, 371 | { 372 | "name": "MYSQL_DATABASE", 373 | "description": "database name", 374 | "value": "root" 375 | } 376 | ], 377 | "labels": { 378 | "template": "application-template-stibuild" 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /conf/hello-service.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "Service", 3 | "apiVersion": "v1", 4 | "metadata": { 5 | "name": "hello-service", 6 | "labels": { 7 | "name": "hello-openshift" 8 | } 9 | }, 10 | "spec": { 11 | "selector": { 12 | "name":"hello-openshift" 13 | }, 14 | "ports": [ 15 | { 16 | "protocol": "TCP", 17 | "port": 8888, 18 | "targetPort": 8080 19 | } 20 | ] 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /conf/kibana.crt: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE----- 2 | MIIB+zCCAWQCCQDG/AgRV0uc4zANBgkqhkiG9w0BAQUFADBCMQswCQYDVQQGEwJY 3 | WDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBh 4 | bnkgTHRkMB4XDTE1MTIwMjIwMzMxM1oXDTE2MDEwMTIwMzMxM1owQjELMAkGA1UE 5 | BhMCWFgxFTATBgNVBAcMDERlZmF1bHQgQ2l0eTEcMBoGA1UECgwTRGVmYXVsdCBD 6 | b21wYW55IEx0ZDCBnzANBgkqhkiG9w0BAQEFAAOBjQAwgYkCgYEA1+S9ZRvX0N8C 7 | 4EMiir+e/0X35H1PDEpeJ/qf+JSMF8nEG8xzCtlQiXq/XBX5EyXo1+vLV7kOXJXV 8 | QuV3UbqPtZ7sbC/EFw6jicNFzMDpBO64Yt2V4qGpCw05NlQLM1VAnmRRxUU48Aqj 9 | 0hUuQ01iVJ/F9TvdR5Hkio4sZp+Y+tECAwEAATANBgkqhkiG9w0BAQUFAAOBgQBu 10 | YMVPIEUAHSaDa1QiazYAZF7UWsn4mJKbC04ZWumxkxoDr3Gj9fQzVKXbDep+ujP8 11 | NPfJF/X7Eib4aCdlkAFi3cUyTwPU00QnKO3tIEoVD5wR98iH8t2z6WCjaEsKLNg0 12 | +FssywBv838uyaBLvWYXIRNT4JdqRKArGUjOFttrlQ== 13 | -----END CERTIFICATE----- 14 | -------------------------------------------------------------------------------- /conf/kibana.csr: -------------------------------------------------------------------------------- 1 | -----BEGIN CERTIFICATE REQUEST----- 2 | MIIBgTCB6wIBADBCMQswCQYDVQQGEwJYWDEVMBMGA1UEBwwMRGVmYXVsdCBDaXR5 3 | MRwwGgYDVQQKDBNEZWZhdWx0IENvbXBhbnkgTHRkMIGfMA0GCSqGSIb3DQEBAQUA 4 | A4GNADCBiQKBgQDX5L1lG9fQ3wLgQyKKv57/RffkfU8MSl4n+p/4lIwXycQbzHMK 5 | 2VCJer9cFfkTJejX68tXuQ5cldVC5XdRuo+1nuxsL8QXDqOJw0XMwOkE7rhi3ZXi 6 | oakLDTk2VAszVUCeZFHFRTjwCqPSFS5DTWJUn8X1O91HkeSKjixmn5j60QIDAQAB 7 | oAAwDQYJKoZIhvcNAQELBQADgYEAkmaRyrtxqA7lJmotCmQUIZp0igS+iA1cE6i8 8 | 8HdrerYODluiCbjpQ4mlh04EGu8AXVltMNbsC4rIqetyeoYpbbrKc0ON6vXffAf/ 9 | uM8FOqqgsW1OR2JoB89gr873kdYRO1BoZscMiqkcsA3P996aU9qJJVHytjkpLpqo 10 | ee8qvTc= 11 | -----END CERTIFICATE REQUEST----- 12 | -------------------------------------------------------------------------------- /conf/kibana.key: -------------------------------------------------------------------------------- 1 | -----BEGIN RSA PRIVATE KEY----- 2 | Proc-Type: 4,ENCRYPTED 3 | DEK-Info: DES-EDE3-CBC,6618A573A54F8B75 4 | 5 | VphPBABQfWbgCxaclcVl1DjqnMhYoIVlYtpj5xnrIMhdIqCENJFNQoi0mtx/R8oN 6 | YAu02FxmWxAV9CW+3oNkfVKEIy+ErZMSym8171ltrM69f6e4BzSY2TfbxTEyRdzo 7 | t/zy4c4L8GUlvMBhVaf5jZ0lFYxvFuqBrdL5IdrppSNnRuX2w7W0QeLa4mBcgln4 8 | BYq3yE2s1cfj6GfsLPRb74x5v5e3EXdu1sz8+0iX1h57Cd7jH5qzP9jTDofjemG3 9 | EL7FPuvC0eeD4jCL7jwQVYnERM/YORzy+hubmv5KOO+RHsEcmAvacKF1pcCdVo+1 10 | xBZJDHtKQ6P+esHM6GLnkjRZrMrQUZTDsgyh9Fv7wo7cS7KDOdSuZJYmxs5ljOOK 11 | ayCd6aQnZO2rmXWDjtWgEy+gEATi069hOVzqgQvplPyJTfd1vnKU5Y+arQ9j+efv 12 | kjj6onXwU1fKQt4DL6+b894DqELJnk/Mx3RgnhwGbVrHeWTMhz2l3PU9frmYNX7f 13 | ShwGpnT7v7Xraj74C+RjwBzkxeNaiAbeLHzl8AtgtOY+Sgrtjh1zJR5HTGiSoyn/ 14 | nvwjGysWTTXLLsJ/7TKRNBdgRHFdVRps507PcmV6BIRcoL2NkWGbY6kI0A5T148s 15 | Bkn72QRK10LOjnAwkBVmHNdS2G2W5eCG3ZNHN26X4CtJ8+dFvI4YH4x35UxL2TkO 16 | yBYoYdul6tFymFbXyQ+uQNgfnNME0iXvB+uLBC5wsHZQqd2x2BY+xrkUZ28j2YjF 17 | v8hSGeRzBl3Es6Exfqn27LW6P9hRXAd1z7DN/kcavIgCSRSQFQD3eQ== 18 | -----END RSA PRIVATE KEY----- 19 | -------------------------------------------------------------------------------- /conf/logging-deployer-service-account.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: logging-deployer 5 | secrets: 6 | - name: logging-deployer 7 | -------------------------------------------------------------------------------- /conf/logging.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: "v1" 2 | kind: "Template" 3 | metadata: 4 | name: logging-deployer-template 5 | annotations: 6 | description: "Template for deploying everything needed for aggregated logging. Requires cluster-admin 'logging-deployer' service account and 'logging-deployer' secret." 7 | tags: "infrastructure" 8 | labels: 9 | logging-infra: deployer 10 | provider: openshift 11 | component: deployer 12 | objects: 13 | - 14 | apiVersion: v1 15 | kind: Pod 16 | metadata: 17 | generateName: logging-deployer- 18 | spec: 19 | containers: 20 | - image: ${IMAGE_PREFIX}logging-deployment:${IMAGE_VERSION} 21 | imagePullPolicy: Always 22 | name: deployer 23 | volumeMounts: 24 | - name: secret 25 | mountPath: /secret 26 | readOnly: true 27 | - name: empty 28 | mountPath: /etc/deploy 29 | env: 30 | - name: PROJECT 31 | valueFrom: 32 | fieldRef: 33 | fieldPath: metadata.namespace 34 | - name: IMAGE_PREFIX 35 | value: ${IMAGE_PREFIX} 36 | - name: IMAGE_VERSION 37 | value: ${IMAGE_VERSION} 38 | - name: ENABLE_OPS_CLUSTER 39 | value: ${ENABLE_OPS_CLUSTER} 40 | - name: KIBANA_HOSTNAME 41 | value: ${KIBANA_HOSTNAME} 42 | - name: KIBANA_OPS_HOSTNAME 43 | value: ${KIBANA_OPS_HOSTNAME} 44 | - name: PUBLIC_MASTER_URL 45 | value: ${PUBLIC_MASTER_URL} 46 | - name: MASTER_URL 47 | value: ${MASTER_URL} 48 | - name: ES_INSTANCE_RAM 49 | value: ${ES_INSTANCE_RAM} 50 | - name: ES_CLUSTER_SIZE 51 | value: ${ES_CLUSTER_SIZE} 52 | - name: ES_NODE_QUORUM 53 | value: ${ES_NODE_QUORUM} 54 | - name: ES_RECOVER_AFTER_NODES 55 | value: ${ES_RECOVER_AFTER_NODES} 56 | - name: ES_RECOVER_EXPECTED_NODES 57 | value: ${ES_RECOVER_EXPECTED_NODES} 58 | - name: ES_RECOVER_AFTER_TIME 59 | value: ${ES_RECOVER_AFTER_TIME} 60 | - name: ES_OPS_INSTANCE_RAM 61 | value: ${ES_OPS_INSTANCE_RAM} 62 | - name: ES_OPS_CLUSTER_SIZE 63 | value: ${ES_OPS_CLUSTER_SIZE} 64 | - name: ES_OPS_NODE_QUORUM 65 | value: ${ES_OPS_NODE_QUORUM} 66 | - name: ES_OPS_RECOVER_AFTER_NODES 67 | value: ${ES_OPS_RECOVER_AFTER_NODES} 68 | - name: ES_OPS_RECOVER_EXPECTED_NODES 69 | value: ${ES_OPS_RECOVER_EXPECTED_NODES} 70 | - name: ES_OPS_RECOVER_AFTER_TIME 71 | value: ${ES_OPS_RECOVER_AFTER_TIME} 72 | dnsPolicy: ClusterFirst 73 | restartPolicy: Never 74 | serviceAccount: logging-deployer 75 | volumes: 76 | - name: empty 77 | emptyDir: {} 78 | - name: secret 79 | secret: 80 | secretName: logging-deployer 81 | parameters: 82 | - 83 | description: 'Specify prefix for logging components; e.g. for "openshift/origin-logging-deployer:v1.1", set prefix "openshift/origin-"' 84 | name: IMAGE_PREFIX 85 | value: "registry.access.redhat.com/openshift3/" 86 | - 87 | description: 'Specify version for logging components; e.g. for "openshift/origin-logging-deployer:v1.1", set version "v1.1"' 88 | name: IMAGE_VERSION 89 | value: "3.1.0" 90 | - 91 | description: "If true, set up to use a second ES cluster for ops logs." 92 | name: ENABLE_OPS_CLUSTER 93 | value: "false" 94 | - 95 | description: "External hostname where clients will reach kibana" 96 | name: KIBANA_HOSTNAME 97 | required: true 98 | - 99 | description: "External hostname at which admins will visit the ops Kibana." 100 | name: KIBANA_OPS_HOSTNAME 101 | value: kibana-ops.example.com 102 | - 103 | description: "External URL for the master, for OAuth purposes" 104 | name: PUBLIC_MASTER_URL 105 | required: true 106 | - 107 | description: "Internal URL for the master, for authentication retrieval" 108 | name: MASTER_URL 109 | value: "https://kubernetes.default.svc.cluster.local" 110 | - 111 | description: "Amount of RAM to reserve per ElasticSearch instance." 112 | name: ES_INSTANCE_RAM 113 | value: "8G" 114 | - 115 | description: "How many instances of ElasticSearch to deploy." 116 | name: ES_CLUSTER_SIZE 117 | required: true 118 | - 119 | description: "Number of nodes required to elect a master (ES minimum_master_nodes). By default, derived from ES_CLUSTER_SIZE / 2 + 1." 120 | name: ES_NODE_QUORUM 121 | - 122 | description: "Number of nodes required to be present before the cluster will recover from a full restart. By default, one fewer than ES_CLUSTER_SIZE." 123 | name: ES_RECOVER_AFTER_NODES 124 | - 125 | description: "Number of nodes desired to be present before the cluster will recover from a full restart. By default, ES_CLUSTER_SIZE." 126 | name: ES_RECOVER_EXPECTED_NODES 127 | - 128 | description: "Timeout for *expected* nodes to be present when cluster is recovering from a full restart." 129 | name: ES_RECOVER_AFTER_TIME 130 | value: "5m" 131 | - 132 | description: "Amount of RAM to reserve per ops ElasticSearch instance." 133 | name: ES_OPS_INSTANCE_RAM 134 | value: "8G" 135 | - 136 | description: "How many ops instances of ElasticSearch to deploy. By default, ES_CLUSTER_SIZE." 137 | name: ES_OPS_CLUSTER_SIZE 138 | - 139 | description: "Number of ops nodes required to elect a master (ES minimum_master_nodes). By default, derived from ES_CLUSTER_SIZE / 2 + 1." 140 | name: ES_OPS_NODE_QUORUM 141 | - 142 | description: "Number of ops nodes required to be present before the cluster will recover from a full restart. By default, one fewer than ES_OPS_CLUSTER_SIZE." 143 | name: ES_OPS_RECOVER_AFTER_NODES 144 | - 145 | description: "Number of ops nodes desired to be present before the cluster will recover from a full restart. By default, ES_OPS_CLUSTER_SIZE." 146 | name: ES_OPS_RECOVER_EXPECTED_NODES 147 | - 148 | description: "Timeout for *expected* ops nodes to be present when cluster is recovering from a full restart." 149 | name: ES_OPS_RECOVER_AFTER_TIME 150 | value: "5m" 151 | 152 | -------------------------------------------------------------------------------- /conf/metrics-deployer-service-account.yml: -------------------------------------------------------------------------------- 1 | apiVersion: v1 2 | kind: ServiceAccount 3 | metadata: 4 | name: metrics-deployer 5 | secrets: 6 | - name: metrics-deployer 7 | -------------------------------------------------------------------------------- /conf/metrics.yaml: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # 3 | # Copyright 2014-2015 Red Hat, Inc. and/or its affiliates 4 | # and other contributors as indicated by the @author tags. 5 | # 6 | # Licensed under the Apache License, Version 2.0 (the "License"); 7 | # you may not use this file except in compliance with the License. 8 | # You may obtain a copy of the License at 9 | # 10 | # http://www.apache.org/licenses/LICENSE-2.0 11 | # 12 | # Unless required by applicable law or agreed to in writing, software 13 | # distributed under the License is distributed on an "AS IS" BASIS, 14 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 | # See the License for the specific language governing permissions and 16 | # limitations under the License. 17 | # 18 | 19 | apiVersion: "v1" 20 | kind: "Template" 21 | metadata: 22 | name: metrics-deployer-template 23 | annotations: 24 | description: "Template for deploying the required Metrics integration. Requires cluster-admin 'metrics-deployer' service account and 'metrics-deployer' secret." 25 | tags: "infrastructure" 26 | labels: 27 | metrics-infra: deployer 28 | provider: openshift 29 | component: deployer 30 | objects: 31 | - 32 | apiVersion: v1 33 | kind: Pod 34 | metadata: 35 | generateName: metrics-deployer- 36 | spec: 37 | containers: 38 | - image: ${IMAGE_PREFIX}metrics-deployer:${IMAGE_VERSION} 39 | name: deployer 40 | volumeMounts: 41 | - name: secret 42 | mountPath: /secret 43 | readOnly: true 44 | - name: empty 45 | mountPath: /etc/deploy 46 | env: 47 | - name: PROJECT 48 | valueFrom: 49 | fieldRef: 50 | fieldPath: metadata.namespace 51 | - name: IMAGE_PREFIX 52 | value: ${IMAGE_PREFIX} 53 | - name: IMAGE_VERSION 54 | value: ${IMAGE_VERSION} 55 | - name: PUBLIC_MASTER_URL 56 | value: ${PUBLIC_MASTER_URL} 57 | - name: MASTER_URL 58 | value: ${MASTER_URL} 59 | - name: REDEPLOY 60 | value: ${REDEPLOY} 61 | - name: USE_PERSISTENT_STORAGE 62 | value: ${USE_PERSISTENT_STORAGE} 63 | - name: HAWKULAR_METRICS_HOSTNAME 64 | value: ${HAWKULAR_METRICS_HOSTNAME} 65 | - name: CASSANDRA_NODES 66 | value: ${CASSANDRA_NODES} 67 | - name: CASSANDRA_PV_SIZE 68 | value: ${CASSANDRA_PV_SIZE} 69 | - name: METRIC_DURATION 70 | value: ${METRIC_DURATION} 71 | dnsPolicy: ClusterFirst 72 | restartPolicy: Never 73 | serviceAccount: metrics-deployer 74 | volumes: 75 | - name: empty 76 | emptyDir: {} 77 | - name: secret 78 | secret: 79 | secretName: metrics-deployer 80 | parameters: 81 | - 82 | description: 'Specify prefix for metrics components; e.g. for "openshift/origin-metrics-deployer:v1.1", set prefix "openshift/origin-"' 83 | name: IMAGE_PREFIX 84 | value: "hawkular/" 85 | - 86 | description: 'Specify version for metrics components; e.g. for "openshift/origin-metrics-deployer:v1.1", set version "v1.1"' 87 | name: IMAGE_VERSION 88 | value: "0.7.0-SNAPSHOT" 89 | - 90 | description: "Internal URL for the master, for authentication retrieval" 91 | name: MASTER_URL 92 | value: "https://kubernetes.default.svc:443" 93 | - 94 | description: "External hostname where clients will reach Hawkular Metrics" 95 | name: HAWKULAR_METRICS_HOSTNAME 96 | required: true 97 | - 98 | description: "If set to true the deployer will try and delete all the existing components before trying to redeploy." 99 | name: REDEPLOY 100 | value: "false" 101 | - 102 | description: "Set to true for persistent storage, set to false to use non persistent storage" 103 | name: USE_PERSISTENT_STORAGE 104 | value: "false" 105 | - 106 | description: "The number of Cassandra Nodes to deploy for the initial cluster" 107 | name: CASSANDRA_NODES 108 | value: "1" 109 | - 110 | description: "The persistent volume size for each of the Cassandra nodes" 111 | name: CASSANDRA_PV_SIZE 112 | value: "1Gi" 113 | - 114 | description: "How many days metrics should be stored for." 115 | name: METRIC_DURATION 116 | value: "7" 117 | -------------------------------------------------------------------------------- /conf/resource-limits.json: -------------------------------------------------------------------------------- 1 | { 2 | "kind": "LimitRange", 3 | "apiVersion": "v1", 4 | "metadata": { 5 | "name": "limits", 6 | "creationTimestamp": null 7 | }, 8 | "spec": { 9 | "limits": [ 10 | { 11 | "type": "Pod", 12 | "max": { 13 | "cpu": "500m", 14 | "memory": "750Mi" 15 | }, 16 | "min": { 17 | "cpu": "10m", 18 | "memory": "5Mi" 19 | } 20 | }, 21 | { 22 | "type": "Container", 23 | "max": { 24 | "cpu": "500m", 25 | "memory": "750Mi" 26 | }, 27 | "min": { 28 | "cpu": "10m", 29 | "memory": "5Mi" 30 | }, 31 | "default": { 32 | "cpu": "100m", 33 | "memory": "100Mi" 34 | } 35 | } 36 | ] 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /conf/resource-quota.json: -------------------------------------------------------------------------------- 1 | { 2 | "apiVersion": "v1", 3 | "kind": "ResourceQuota", 4 | "metadata": { 5 | "name": "test-quota" 6 | }, 7 | "spec": { 8 | "hard": { 9 | "memory": "1Gi", 10 | "cpu": "1", 11 | "pods": "3", 12 | "services": "5", 13 | "replicationcontrollers":"5", 14 | "resourcequotas":"2" 15 | } 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /conf/sample-jenkins-script: -------------------------------------------------------------------------------- 1 | node { 2 | stage ("Build") { 3 | echo '*** Build Starting ***' 4 | openshiftBuild apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', bldCfg: 'hello-nodejs', buildName: '', checkForTriggeredDeployments: 'false', commitID: '', namespace: '', showBuildLogs: 'false', verbose: 'false', waitTime: '' 5 | openshiftVerifyBuild apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', bldCfg: 'hello-nodejs', checkForTriggeredDeployments: 'false', namespace: '', verbose: 'false' 6 | echo '*** Build Complete ***' 7 | } 8 | stage ("Deploy") { 9 | echo '*** Deployment Starting ***' 10 | openshiftDeploy apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', depCfg: 'hello-nodejs', namespace: '', verbose: 'false', waitTime: '' 11 | openshiftVerifyDeployment apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', depCfg: 'hello-nodejs', namespace: '', replicaCount: '1', verbose: 'false', verifyReplicaCount: 'false', waitTime: '' 12 | echo '*** Deployment Complete ***' 13 | } 14 | stage ("Verify") { 15 | echo '*** Service Verification Starting ***' 16 | openshiftVerifyService apiURL: 'https://openshift.default.svc.cluster.local', authToken: '', namespace: '', svcName: 'hello-nodejs', verbose: 'false' 17 | echo '*** Service Verification Complete ***' 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /conf/scaler.yml: -------------------------------------------------------------------------------- 1 | apiVersion: extensions/v1beta1 2 | kind: HorizontalPodAutoscaler 3 | metadata: 4 | name: frontend-scaler 5 | spec: 6 | scaleRef: 7 | kind: DeploymentConfig 8 | name: welcome-php 9 | apiVersion: v1 10 | subresource: scale 11 | minReplicas: 1 12 | maxReplicas: 5 13 | cpuUtilization: 14 | targetPercentage: 5 15 | -------------------------------------------------------------------------------- /libs/README.md: -------------------------------------------------------------------------------- 1 | # Openshift 2 | Scripts in here are used by the ~bin shell scripts 3 | They include common functions used by many of the bin scripts. 4 | -------------------------------------------------------------------------------- /libs/functions: -------------------------------------------------------------------------------- 1 | # 2 | # functions: stuff we use over and over again... 3 | # 4 | 5 | # ---------------------------------------------------------------- 6 | # FUNCTION TO SETUP COLOURS TO BE USED WHEN RUNNING ECHOs 7 | # ---------------------------------------------------------------- 8 | 9 | RED='\033[0;31m' 10 | GREEN='\033[0;32m' 11 | BLUE='\033[0;34m' 12 | NC='\033[0m' # No Color 13 | 14 | # --------------------------------------------- 15 | # FUNCTION TO DO THE GRUNT WORK, STEP BY STEP 16 | # [WE EITHER ECHO A COMMAND OR RUN IT...] 17 | # --------------------------------------------- 18 | 19 | run_cmd () { 20 | if [ $1 = "echo" ] 21 | then 22 | shift 23 | action="$*" 24 | echo -e $action 25 | echo " when ready" 26 | read x 27 | elif [ $1 = "run" ] 28 | then 29 | shift 30 | action="$*" 31 | echo -e "${GREEN}$action${NC}" 32 | eval $action 33 | echo 34 | fi 35 | } 36 | 37 | # ---------------------------------------------------------------- 38 | # FUNCTION TO WAIT UNTIL A BUILD HAS COMPLETED BEFORE WE PROCEED 39 | # ---------------------------------------------------------------- 40 | 41 | check_build () { 42 | build_status="`oc get builds | grep ${1}-1 | awk '{print $4}'`" 43 | while true 44 | do 45 | if [ -z $build_status ] 46 | then 47 | echo "Whoops! There is no build image, something went wrong :(" 48 | exit 99 49 | else 50 | until [ $build_status = "Complete" ] 51 | do 52 | echo "$1 build is still $build_status..." 53 | sleep 10 54 | build_status="`oc get builds | grep ${1}-1 | awk '{print $4}'`" 55 | done 56 | fi 57 | echo "$1 build is DONE!" 58 | echo 59 | break 60 | done 61 | } 62 | 63 | # ---------------------------------------------------------------- 64 | # FUNCTION TO WAIT UNTIL HPA HAS BEEN SETUP BEFORE WE PROCEED 65 | # ---------------------------------------------------------------- 66 | 67 | check_hpa () { 68 | build_status="`oc get hpa | grep waiting | awk '{print $4}'`" 69 | while true 70 | do 71 | if [ -z $build_status ] 72 | then 73 | echo "Whoops! There is nothing doing here, something went wrong :(" 74 | exit 99 75 | else 76 | until [ "$build_status" != "" ] 77 | do 78 | echo "Auto scaling is still $build_status ..." 79 | sleep 10 80 | build_status="`oc get hpa | grep waiting | awk '{print $4}'`" 81 | done 82 | fi 83 | echo "Auto scaling is setup!" 84 | echo 85 | break 86 | done 87 | } 88 | 89 | # ------------------------------------------------------------------------------- 90 | # RETURN OC VERSION IN CASE THINGS CHANGE ACROSS REVISIONS (& THEY DO) 91 | # VERSION 3.1 RETURNS "3.1.0" 92 | # VERSION 3.0 RETURNS "3.0.2" (last tested version) 93 | # ------------------------------------------------------------------------------- 94 | 95 | export OC_VERSION=`oc version | grep oc | sed -n 's/oc[ ]v\([0-9].[0-9].[0-9]\).*/\1/p'` 96 | 97 | # ------------------------- 98 | # RETURN LIST OF PROJECTS 99 | # ------------------------- 100 | 101 | export OC_PROJECTS=`oc get projects | sed '1d' | awk '{print $1}'` 102 | 103 | # --------------- 104 | # GET USERS UID 105 | # --------------- 106 | 107 | export MY_UID="`id -u`" 108 | -------------------------------------------------------------------------------- /openshift.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: localhost 3 | connection: local 4 | gather_facts: no 5 | 6 | vars: 7 | ansible_python_interpreter: /var/lib/awx/venv/ansible/bin/python 8 | 9 | tasks: 10 | 11 | - name: Create a k8s namespace 12 | k8s: 13 | kubeconfig: /etc/ansible/files/kubeconfig 14 | context: preprod-dev 15 | name: testing 16 | api_version: v1 17 | kind: Namespace 18 | state: present 19 | -------------------------------------------------------------------------------- /playbooks/README.md: -------------------------------------------------------------------------------- 1 | # Ansible Playbooks For Demo Scripts 2 | You can use these to auto deploy the walkthrough demo scripts, used in conjunction with demobuilder. 3 | 4 | ### Setup 5 | 6 | You have a demobuilder all-in-one master/node VM, or vagrant config to bring it up. 7 | 8 | You might need to change the entries in the ansible_hosts file if you've different OSE hostnames 9 | 10 | You already have a local ansible client installed and SSH keys setup as per the normal ansible installation/setup guides. 11 | 12 | ### Installing 13 | 14 | To install the demo scripts from a client CLI: 15 | 16 | ``` 17 | $ cd ~/openshift/playbooks 18 | $ ansible-playbook -i ./ansible_hosts ./ose3-master-scripts.yml 19 | ``` 20 | 21 | ### Vagrant Auto Provisioning 22 | 23 | You can get vagrant to auto provision as part of the initialisation. *This isn't working currently - looks like an issue with SSH keys, so use this as a reference only* 24 | 25 | Add this to your Vagrantfile: 26 | 27 | ``` 28 | # If you want to do some ansible provisioning, this is how... 29 | config.vm.provision "ansible" do |ansible| 30 | #ansible.limit = 'ose-offline-demo' 31 | #ansible.inventory_path = "ansible/ansible_hosts" 32 | ansible.playbook = "ansible/ose3-master-scripts.yml" 33 | end 34 | ``` 35 | 36 | When you run ```vagrant up``` it'll call the provisioning plugin to deploy. 37 | If your VM is already up, then use ```vagrant provision``` 38 | -------------------------------------------------------------------------------- /playbooks/ansible_hosts: -------------------------------------------------------------------------------- 1 | #[local] 2 | #localhost ansible_connection=local 3 | 4 | [master] 5 | ose3-master.example.com ansible_connection=ssh ansible_ssh_user=root 6 | 7 | [nodes] 8 | ose3-node1.example.com ansible_connection=ssh ansible_ssh_user=root 9 | ose3-node2.example.com ansible_connection=ssh ansible_ssh_user=root 10 | 11 | [ose3:children] 12 | master 13 | nodes 14 | 15 | [all:children] 16 | ose3 17 | -------------------------------------------------------------------------------- /playbooks/ose3-master-scripts.yml: -------------------------------------------------------------------------------- 1 | --- 2 | - hosts: master 3 | remote_user: root 4 | sudo: no 5 | tasks: 6 | 7 | - name: "copy over walkthrough OSE demo project script #1 - AB Deployments" 8 | copy: src=~/openshift/create-ose3-app-ab-deployment.sh dest=/home/demo owner=demo mode=0755 backup=yes 9 | - name: "copy over walkthrough OSE demo project script #2 - BG Rolling Deployments" 10 | copy: src=~/openshift/create-ose3-app-bluegreen-deployment.sh dest=/home/demo owner=demo mode=0755 backup=yes 11 | - name: "copy over walkthrough OSE demo project script #3 - App Promotion Acress Envs" 12 | copy: src=~/openshift/create-ose3-app-promo-envs.sh dest=/home/demo owner=demo mode=0755 backup=yes 13 | - name: "copy over walkthrough OSE demo project script #4 - MLBParks Google Maps demo" 14 | copy: src=~/openshift/create-ose3-mlbparks-app.sh dest=/home/demo owner=demo mode=0755 backup=yes 15 | --------------------------------------------------------------------------------