├── Jenkins X and CKCD Workshop.pdf ├── LICENSE ├── README.md ├── create-devpod.md ├── create-quickstart.md ├── getting-started-sso.md ├── images ├── create-pull-request.png └── pull-request.png ├── install-guide.txt ├── install-jx.sh ├── preview-environments.md ├── pull-request.md ├── theia-ide.md └── workshop.md /Jenkins X and CKCD Workshop.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudbees-days/jenkins-x-workshop/9fd9c3145893fb6ddfbeba86fc4f64a2ca89b8e9/Jenkins X and CKCD Workshop.pdf -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Jenkins X and CloudBees Core for Kubernetes CD Developers Workshop 2 | In this workshop you will discover how Jenkins X and CloudBees Core for Kubernetes (K8s) CD can help you deliver streamlined workflows for cloud native applications on Kubernetes with Jenkins Pipelines and pre-production environments created automatically. 3 | 4 | ## Workshop Content 5 | Please review the [workshop prerequisites](https://github.com/cloudbees-days/jenkins-x-workshop#workshop-prerequisites) before proceeding to the workshop. 6 | 7 | * Instaling CloudBees Core for Kubernetes CD (CKCD) 8 | * Creating a Quickstart Project 9 | * Creating and using a DevPod 10 | * Using the Theia IDE web based IDE 11 | * Leveraging Preview Environments for Pull Requests 12 | 13 | [![Open in Cloud Shell](http://gstatic.com/cloudssh/images/open-btn.svg)](https://ssh.cloud.google.com/cloudshell/open?cloudshell_git_repo=https%3A%2F%2Fgithub.com%2Fcloudbees-days%2Fjenkins-x-workshop&cloudshell_print=install-guide.txt&cloudshell_tutorial=workshop.md) 14 | 15 | ## Workshop Prerequisites 16 | * Web browser 17 | * A basic understanding of Jenkins Pipelines: https://jenkins.io/doc/book/pipeline/getting-started/ 18 | * A basic understanding of Kubernetes: https://kubernetes.io/docs/concepts/overview/what-is-kubernetes/ 19 | * Internet access to include access to https://github.com to include the ability to access and use [the GitHub File Editor](https://help.github.com/articles/editing-files-in-your-repository/) 20 | * An account on Github.com and a basic understanding of how to use Github to do things like fork a repository, edit files in the web UI, and create pull requests 21 | * Google cloud account (there's a $300 credit, free tier if you don't already have one https://cloud.google.com/free/) 22 | * A Google cloud project (select your project with `gcloud config set project PROJECT_ID` once Cloud Shell is ready) 23 | 24 | ## Disclaimer 25 | 26 | Although the examples and code in this repository were originally created by employees of CloudBees, Inc. to use in training customers, your use of this material is not sponsored or supported by CloudBees, Inc. 27 | 28 | ## Contributors 29 | 30 | * Contributors: [Kurt Madel](https://github.com/kmadel), [David Canadillas](https://github.com/dcanadillas) 31 | 32 | ## Questions, Feedback, Pull Requests Etc. 33 | 34 | If you have any questions, feedback, suggestions, etc. please submit them via issues or, even better, submit a Pull Request! 35 | 36 | -------------------------------------------------------------------------------- /create-devpod.md: -------------------------------------------------------------------------------- 1 | # Create and Use a DevPod 2 | 3 | A [DevPod](https://jenkins-x.io/developing/devpods/) allows you to develop in a K8s pod running in the same cluster where Jenkins X is running. DevPods allow you to build and test your Jenkins X application before you are ready to create a Pull Request - all without installing any developer tools on your computer. 4 | 5 | DevPods provide a terminal/shell that is based on the exact same operating system, docker containers and tools that are installed in the pod templates used in the Jenkins X CI/CD pipelines. This allows you to build, run tests or redeploy apps using the exact same tools as the CI/CD pipelines provided by Jenkins X build-packs and before you commit to your upstream Git repository. 6 | 7 | Before creating a DevPod you want to be in the source code repository for which you want to make changes - the one create with the quickstart from the last exercise: 8 | 9 | ```bash 10 | cd ~/cloudbees_days/jx-go 11 | ``` 12 | 13 | To create your own DevPod use the command [`jx create devpod`](https://jenkins-x.io/commands/jx_create_devpod/). Run command to get a list of all available DevPods. Once you have reviewed the list cancel with `ctrl+c`. 14 | 15 | ```bash 16 | jx create devpod 17 | ``` 18 | 19 | For the workshop we want to create a simple **http Golang** project with the following command where the `-l go` specifies the programming language to supporet - but make sure you are in your quickstart repository directory that you created in the previous exercise: 20 | ```bash 21 | jx create devpod -l go --username='[your GitHub username]' 22 | ``` 23 | 24 | This will then create a new DevPod based on the `go` based pod template and open your terminal inside that pod. You are now free to use the various pre-installed tools like git, docker, go, skaffold, jx which will all be using the same exact configuration as the automated Jenkins X CI/CD pipelines. 25 | 26 | Now you are ready to move on to the [Using the Theia IDE](./theia-ide.md). 27 | 28 | -------------------------------------------------------------------------------- /create-quickstart.md: -------------------------------------------------------------------------------- 1 | # Create a Quickstart Project 2 | 3 | Quickstarts are very basic pre-made applications you can start a project from, instead of creating a project from scratch. 4 | 5 | You can create new applications from a list of curated Quickstart applications via the [`jx create quickstart` command](https://jenkins-x.io/commands/jx_create_quickstart/). 6 | 7 | Before creating our quickstart application let's create a directory to work within. 8 | 9 | ```bash 10 | mkdir -p ~/cloudbees_days/jx-workshop 11 | ``` 12 | ```bash 13 | cd ~/cloudbees_days/jx-workshop 14 | ``` 15 | 16 | Let's then be sure that all our files, local repos and projects are set from commands that are run from this directory. 17 | 18 | We will run a quickstart command whith following parameters: 19 | 20 | - `-l go` will filter the list of available quickstarts to a specific language - Go in this case - 21 | - `-f http` will filter for text that is part of the quickstart project names 22 | - `-p jx-go` will set *jx-go* as the application project name (application and git repo name) 23 | 24 | So, the following command will result in a list of Golang projects with 'http' in their names and will set the repo name in Git as *jx-go*: 25 | 26 | ```bash 27 | jx create quickstart -l go -f http -p jx-go-http 28 | ``` 29 | 30 | In this case there is only one match so it will automatically choose that one for you and move right to setting it up. 31 | 32 | When prompted with: 33 | 34 | **? Do you wish to use ckcd-sa-bot as the Git user name? (Y/n)** - choose the value n for "No". Do not choose the default value Y for "Yes". 35 | ‍ 36 | 37 | When prompted for: 38 | 39 | **? Git user name?**- specify your own/usual GitHub account username. 40 | 41 | **? GitHub user name:** choose the default value, which should be your own GitHub account username that you specified in the previous step. 42 | 43 | **? API Token:**- enter your GitHub personal access token. If you don't have one then click on this [link](https://github.com/settings/tokens/new?scopes=repo,read:user,read:org,user:email,write:repo_hook,delete_repo) - logging in to GitHub with the same GitHub account used in the previus steps and enter the API token. 44 | 45 | **? Enter the new repository name:** - this will be your project name and the name of the repository created for the project. We will all call 'jx-go-http', so enter **jx-go-http**. 46 | 47 | **? Would you like to initialise git now?** Choose the value "Y" to initialize git for your new project. 48 | 49 | **? Commit message: (Initial import)** Just hit enter to execept the default commit message of "Initial import". 50 | 51 | After you finish responding to the prompts a Jenkins X quickstart will automate all of the following for you: 52 | 53 | * creates a new application from the quickstart in a sub directory 54 | * add your source code into a git repository 55 | * create a remote git repository on a git service, such as GitHub 56 | * push your code to the remote git service 57 | * adds default files: 58 | * Dockerfile to build your application as a docker image 59 | * Jenkinsfile to implement the CI / CD pipeline 60 | * Helm chart to run your application inside Kubernetes 61 | * register a webhook on the remote git repository to your teams Jenkins 62 | * add the git repository to your teams Jenkins 63 | * trigger the first pipeline 64 | 65 | Watch pipeline activity via: 66 | ```bash 67 | jx get activity -f jx-go-http -w 68 | ``` 69 | Browse the pipeline log via: 70 | ```bash 71 | jx get build logs /jx-go-http/master 72 | ``` 73 | Open the Jenkins console via: 74 | ```bash 75 | jx console 76 | ``` 77 | You can list the pipelines via: 78 | ```bash 79 | jx get pipelines 80 | ``` 81 | When the pipeline is complete: 82 | ```bash 83 | jx get applications 84 | ``` 85 | 86 | And you can take a look at your project in CKCD. 87 | 88 | To see a list of all the quickstarts available in the current environment run the following command: 89 | ```bash 90 | jx create quickstart 91 | ``` 92 | 93 | Cancel that command with `ctrl+c`. 94 | -------------------------------------------------------------------------------- /getting-started-sso.md: -------------------------------------------------------------------------------- 1 | # Getting Started with SSO 2 | 3 | The Jenkins X cluster that you will be using today has the [CloudBees addon](https://jenkins-x.io/commands/jx_create_addon_cloudbees/) installed, providing CloudBees Core for Kuberenetes CD (CKCD). One feature of CKCD is that it provides single-sign-on. This will allow multiple users to use the same Kubernetes cluster with Jenkins X rather than creating a cluster for each developer. 4 | 5 | You should already have the Jenkins X `jx` CLI installed (if not follow [these instructions](https://jenkins-x.io/getting-started/install/)). Open a terminal on you computer and run the following command to login to the cluster we will be using today: 6 | 7 | ``` 8 | jx login --url https://core.jx.ckcd.beedemo.net/ 9 | ``` 10 | 11 | When you run this command it will install some additional dependencies if you don't already have them installed on your computer. These include: 12 | * `kubectl` 13 | * `helm` 14 | * `terraform` 15 | 16 | If you already have any of these dependencies installed then you will want to make sure they are at the following version: 17 | * `kubectl` client version v1.13.2 18 | * `helm` version: 2.12.2 19 | * `terraform` version v0.11.11 20 | 21 | The `jx login` command will onboard you into the CKCD application and update your local Kubernetes client (`kubectl`) configuration to allow running `jx` CLI commands against the workshop cluster. 22 | 23 | Once you have successfully run that command the CKCD application should open in your default browser - if not, navigate to https://core.jx.ckcd.beedemo.net/ and login with your GitHub credentials. 24 | 25 | The output of the command in your terminal should look something like the following: 26 | ```sh 27 | You are successfully logged in. You credentials are stored in ~/.kube/config file. 28 | Using team 'jx' on server 'https://.........'. 29 | ``` 30 | 31 | Now you are ready to move on to the [next exercise to create a Jenkins X application using a Jenkins X Quickstart](./create-quickstart.md). 32 | 33 | -------------------------------------------------------------------------------- /images/create-pull-request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudbees-days/jenkins-x-workshop/9fd9c3145893fb6ddfbeba86fc4f64a2ca89b8e9/images/create-pull-request.png -------------------------------------------------------------------------------- /images/pull-request.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/cloudbees-days/jenkins-x-workshop/9fd9c3145893fb6ddfbeba86fc4f64a2ca89b8e9/images/pull-request.png -------------------------------------------------------------------------------- /install-guide.txt: -------------------------------------------------------------------------------- 1 | ================================================================== 2 | Jenkins X and CloudBees Core for Kubernetes CD Developers Workshop 3 | ================================================================== 4 | 5 | To get started, you will need to install all required dependencies. To do this 6 | run the script: 7 | 8 | `source ./install-jx.sh` to install jx and add it to you path. 9 | 10 | Enjoy... -------------------------------------------------------------------------------- /install-jx.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | JX_VERSION=2.0.28 4 | 5 | function install_dependencies() { 6 | mkdir -p ~/bin 7 | echo "Downloading & installing Jenkins X ${JX_VERSION}" 8 | curl -sL https://github.com/jenkins-x/jx/releases/download/v${JX_VERSION}/jx-linux-amd64.tar.gz \ 9 | | tar xvz -C ~/bin 10 | echo "Installed" 11 | } 12 | 13 | function add_path_to_bashrc() { 14 | if grep -q PATH ~/.bashrc; then 15 | echo "Already on path" 16 | else 17 | echo "export PATH=$PATH:$HOME/bin:$HOME/.jx/bin" >> ~/.bashrc 18 | export PATH=$PATH:$HOME/bin:$HOME/.jx/bin 19 | jx --help 20 | fi 21 | } 22 | 23 | install_dependencies 24 | add_path_to_bashrc -------------------------------------------------------------------------------- /preview-environments.md: -------------------------------------------------------------------------------- 1 | # Leveraging Preview Environments for Pull Requests 2 | 3 | Preview environments provide temporary environments to review your changes as part of the Pull Request process. 4 | 5 | To see our previous preview environments by the pull request created: 6 | 7 | ```bash 8 | jx get previews 9 | ``` 10 | 11 | And 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /pull-request.md: -------------------------------------------------------------------------------- 1 | # Creating a pull request and preview environments 2 | 3 | In this exercise we will change the message of our application created before and create a pull request for those changes. 4 | 5 | First, we ensure we are on our project local repo directory: 6 | ```bash 7 | cd ~/cloudbees_days/jx-workshop/jx-go-http 8 | ``` 9 | Let's create a branch where to create our pull request: 10 | ```bash 11 | git checkout -b cloudbees-days 12 | ``` 13 | Now, let's change the message of the go application created before: 14 | 15 | (oprtional): *If you are using the CloudShell tutorial you can use the editor at the left to edit the main.go file and change the message. Or you can change the file using Vim:* 16 | 17 | ```bash 18 | vim main.go 19 | ``` 20 | To change the message in one line code: 21 | ```bash 22 | sed 's/Hello\ from\:/Hello\ Madrid\ from\ CloudBees\:/g' main.go > main.go.tmp \ 23 | && mv main.go.tmp main.go 24 | ``` 25 | 26 | Once we have our application with the new welcome message, let's commit and push our changes: 27 | ```bash 28 | git commit -am " A new message for CloudBees Days" 29 | git push origin cloudbees-days 30 | ``` 31 | So, now should be a pull request to create in our github repo. If we open the repo: 32 | 33 | ```bash 34 | jx repo 35 | ``` 36 | From GitHub repo we click the *Compare and Pull Request*: 37 | 38 | ![alt text](./images/pull-request.png "Compare and pull request") 39 | 40 | And then a message can be edited (let's use the default one) and create the pull request: 41 | 42 | ![alt text](./images/create-pull-request.png "Compare and pull request") 43 | -------------------------------------------------------------------------------- /theia-ide.md: -------------------------------------------------------------------------------- 1 | # Using the Theia IDE 2 | DevPods have a `--sync` feature that will automatically sync local changes up to the DevPod. That is any changes you make locally will be pushed up to the DevPod, built automatically, and then a temporary version of your application will be deployed to the Jenkins X cluster. 3 | 4 | Instead of using `--sync` we will be using another cool features of DevPods - [an embedded web based IDE called Theia](https://www.theia-ide.org/). 5 | 6 | Open the Theia IDE in your browser. 7 | 8 | Make a change to the code. 9 | 10 | Commit to a new branch. 11 | 12 | Go to GitHub and create a PR to the master branch. 13 | 14 | Next section - [Preview Environments](./preview-environments.md) -------------------------------------------------------------------------------- /workshop.md: -------------------------------------------------------------------------------- 1 | # Creating your first JX install on GKE 2 | 3 | ## Let's get started! 4 | 5 | This guide will show you how to install `jx`, use it to create a cluster on Google Kubernetes Engine and then explore the developer-centric features of Jenkins X to include: 6 | 7 | * Instaling CloudBees Core for Kubernetes CD (CKCD) 8 | * Creating a Quickstart Project 9 | * Creating and using a DevPod 10 | * Using the Theia IDE web based IDE 11 | * Leveraging Preview Environments for Pull Requests 12 | 13 | >NOTE: It is recommended that your [create a GitHub Organization](https://help.github.com/en/articles/creating-a-new-organization-from-scratch) specifically for this workshop. 14 | 15 | **Time to complete**: About 75 minutes 16 | 17 | Click the **Next** button to move to the next step. 18 | 19 | ## Installing Dependencies 20 | 21 | The first thing we need to do is install the `jx` binary and add it to your PATH. The following command will execute a script that does that for you. 22 | 23 | ```bash 24 | source ./install-jx.sh 25 | ``` 26 | 27 | 28 | 29 | **Tip**: Click the copy button on the side of the code box to paste the command in the Cloud Shell terminal to run it. 30 | 31 | This may take a few minutes to complete as it downloads everything it requires. 32 | 33 | ## Create a cluster 34 | 35 | To create the cluster, run the following: 36 | 37 | ```bash 38 | jx create cluster gke --no-tiller --skip-login --default-admin-password=admin 39 | ``` 40 | 41 | This will guide you through creating a cluster on GKE. 42 | 43 | ### Missing Dependencies 44 | 45 | JX will attempt to locate any required dependencies, if it discovers that some are missing 46 | it will prompt to install them for you in the `~/.jx/bin` folder. It is recommended that 47 | you allow `jx` to install any missing dependencies. 48 | 49 | ### Configure your cluster 50 | 51 | JX will then prompt you for the basic configuration options for your cluster, such as: 52 | 53 | * What type of cluster would you like to create `Zonal` 54 | * Google Compute Zone - select a zone that is near to you 55 | * Google Cloud Machine Type - recommended `n1-standard-8` 56 | * Minimum number of Nodes - recommended `3` 57 | * Maximum number of Nodes - recommended `5` 58 | * Would you like use preemptible VMs - recommended `No` 59 | * Would you like to access Google Cloud Storage / Google Container Registry - recommended `No` 60 | * Would you like to enable Kaniko for building container images - recommended `Yes` 61 | * (Optional) Would you like to enable Cloud Build, Container Registry & Container Analysis APIs - recommended `No` 62 | 63 | ### Creating the cluster 64 | 65 | Once the cluster is created (this will take a few minutes), you will be prompted for some configuration options: 66 | 67 | * Please enter the name you wish to use with git: `enter your GitHub username` 68 | * Please enter the email address you wish to use with git: `enter any valid email address` 69 | * Install Ingress Controller - recommended `Yes` 70 | * Domain Configuration - recommended `Use the default` 71 | 72 | ### GitHub connectivity 73 | 74 | If this is the first time you have run `jx` in this cloudshell, `jx` will prompt you for a 75 | github username & api token. If you already have one, simply enter the values when prompted. 76 | If you don't have an api token, click on the link provided to generated one and enter the 77 | token value into the prompt. You may be prompted for your GitHub api token twice, make sure 78 | you enter the same token. 79 | 80 | * Do you wish to use GitHub as the pipelines Git server: `Yes` 81 | 82 | ### Serverless Jenkins X Pipeline with Tekton Installation 83 | 84 | * Select Jenkins Installation Type - select `Serverless Jenkins X Pipelines with Tekton` 85 | * Pick workload build pack - select `Kubernetes Workloads: Automated CI+CD with GitOps Promotion` 86 | 87 | Next, `jx` will install Prow and Tekton (among other components). 88 | 89 | * Select the organization where you want to create the environment repository: enter `the GitHub org name you created for workshop` 90 | 91 | ### What did Jenkins X install? 92 | 93 | Now let's take a look at what got installed. 94 | 95 | ```bash 96 | kubectl -n jx get pods 97 | ``` 98 | 99 | ## Install CloudBees Core for Kubernetes CD (CKCD) 100 | The CloudBees Core for Kubernetes CD addon provides a visual dashboard for your Jenkins X applications. 101 | 102 | CKCD is installed as a Jenkins X addon called `cloudbees`. Run the following command to install CKCD on 103 | your Jenkins X cluster: 104 | ```bash 105 | jx create addon cloudbees --basic 106 | ``` 107 | When prompted for: 108 | 109 | * CloudBees Preview username - enter username provided by instructor 110 | * CloudBees Preview password - enter password provided by instructor 111 | 112 | After the addon installed successfully, run the following command to get the URL for CKCD: 113 | ```bash 114 | jx cloudbees 115 | ``` 116 | 117 | Click on the provided url to open CloudBees Core for Kubernetes CD. Login with the username `admin` and password `admin`. 118 | If the service isn't available yet run the following command to get the status of the CKCC addon: 119 | ```bash 120 | kubectl get pods 121 | ``` 122 | 123 | >NOTE: There may be a small issue where you have to update the container images for the CloudBees addon by patching the pod - replacing {core-pod-id} with the id of your core pod: 124 | 125 | ```bash 126 | kubectl patch pod/{core-pod-id} -p '{"spec":{"containers":[{"name":"core-frontend","image":"docker.io/jenkinsxio/core-frontend:0.0.612"},{"name":"core-backend","image":"docker.io/jenkinsxio/core-backend:0.0.210"}]}}' 127 | ``` 128 | 129 | ## Create a Quickstart Project 130 | 131 | Quickstarts are very basic pre-made applications you can start a project from, instead of creating a project from scratch. 132 | 133 | You can create new applications from a list of curated Quickstart applications via the [`jx create quickstart` command](https://jenkins-x.io/commands/jx_create_quickstart/). 134 | 135 | Before creating our quickstart application let's create a directory for our work. 136 | 137 | ```bash 138 | mkdir -p ~/cloudbees_days/jx-workshop 139 | ``` 140 | ```bash 141 | cd ~/cloudbees_days/jx-workshop 142 | ``` 143 | 144 | Let's then be sure that all our files, local repos and projects are set from commands that are run from this directory. 145 | 146 | We will run a quickstart command whith following parameters: 147 | 148 | - `-l go` will filter the list of available quickstarts to a specific language - Go in this case - 149 | - `-f http` will filter for text that is part of the quickstart project names 150 | - `-p jx-go-http` will set *jx-go-http* as the application project name (application and git repo name) 151 | 152 | So, the following command will result in a list of Golang projects with 'http' in their names and will set the repo name in Git as *jx-go-http*: 153 | 154 | ```bash 155 | jx create quickstart -l go -f http -p jx-go-http 156 | ``` 157 | 158 | In this case there is only one match so it will automatically choose that one for you and move right to setting it up. 159 | 160 | When prompted with: 161 | 162 | * Do you wish to use kmadel as the Git user name? - select `Y` 163 | * Which organisation do you want to use? - enter `the GitHub org name you created for this workshop` 164 | * Enter the new repository name: enter `jx-go-http` 165 | * Would you like to initialise git now? select `Y` 166 | * Commit message: it return for default 167 | 168 | After you finish responding to the prompts a Jenkins X quickstart will automate all of the following for you: 169 | 170 | * creates a new application from the quickstart in a sub directory 171 | * add your source code into a git repository 172 | * create a remote git repository on a git service, such as GitHub 173 | * push your code to the remote git service 174 | * adds default files: 175 | * Dockerfile to build your application as a docker image 176 | * Jenkinsfile to implement the CI / CD pipeline 177 | * Helm chart to run your application inside Kubernetes 178 | * register a webhook on the remote git repository to your teams Jenkins 179 | * add the git repository to your teams Jenkins 180 | * trigger the first pipeline 181 | 182 | Watch pipeline activity via: 183 | ```bash 184 | jx get activity -f jx-go-http -w 185 | ``` 186 | Browse the pipeline log via: 187 | ```bash 188 | jx get build logs 189 | ``` 190 | Select your pipeline from the list. 191 | 192 | You can list the pipelines via: 193 | ```bash 194 | jx get pipelines 195 | ``` 196 | When the pipeline is complete: 197 | ```bash 198 | jx get applications 199 | ``` 200 | 201 | And you can take a look at your pipeline in CKCD. 202 | 203 | ## Create and Use a DevPod 204 | 205 | Now typically you would need to set up your computer with all the tools needed to makes changes to the code in the project and to be able to test those changes locally. In this exercise you will see how **DevPods** do all of that for you. 206 | 207 | A [DevPod](https://jenkins-x.io/developing/devpods/) allows you to develop in a K8s pod running in the same cluster where Jenkins X is running. DevPods allow you to build and test your Jenkins X application before you are ready to create a Pull Request - all without locally installing any developer tools. 208 | 209 | Before creating a DevPod you want to be in the source code repository for which you want to make changes - the one created with the quickstart from the last exercise: 210 | ```bash 211 | cd ./jx-go-http 212 | ``` 213 | 214 | To create your own DevPod we will use the command [`jx create devpod`](https://jenkins-x.io/commands/jx_create_devpod/). 215 | 216 | For the workshop we are using the **http Golang** quickstart project. We will create a DevPod with the `-l go` argumeent, specifying the programming language to support - make sure you are in your quickstart repository directory that you created in the previous exercise: 217 | 218 | ```bash 219 | jx create devpod -l go 220 | ``` 221 | 222 | This will then create a new DevPod based on the `go` based pod template and open your terminal inside that pod. You are now free to use the various pre-installed tools like git, docker, go, skaffold, jx which will all be using the same exact configuration as the automated Jenkins X CI/CD pipelines. 223 | 224 | Run the following command to see all the containers running in your DevPod: 225 | ```bash 226 | kubectl describe pod/kmadel-go -n jx 227 | ``` 228 | 229 | ## Using the Theia IDE 230 | DevPods have a `--sync` feature that will automatically sync local changes up to the DevPod. Any changes you make locally will be pushed up to the DevPod, built automatically, and then a temporary version of your application will be deployed to the Jenkins X cluster. 231 | 232 | Instead of using `--sync` we will be using another cool features of DevPods - [an embedded web based IDE called Theia](https://www.theia-ide.org/). 233 | 234 | Open the Theia IDE in your browser. 235 | ```bash 236 | jx get urls 237 | ``` 238 | Click on the URL for Theia. 239 | 240 | ## Leveraging Preview Environments for Pull Requests 241 | 242 | Preview environments provide temporary environments to review your changes as part of the Pull Request process. 243 | 244 | Create a new branch for the pull request and check it out in your DevPod shell: 245 | ```bash 246 | git checkout -b my-pr 247 | ``` 248 | 249 | >NOTE: In the Theid IDE the Git branch changed in the lower left. 250 | 251 | Update the `main.go` file in Theia. 252 | 253 | * Update line 10 to: `title := "Jenkins X golang http example by "` 254 | * The Theid IDE will automatically save your changes and sync them with the files in your DevPod 255 | 256 | In your DevPod shell: 257 | * Stage the change for commit: 258 | ```bash 259 | git add main.go 260 | ``` 261 | * Commit the changes to GitHub: 262 | ```bash 263 | git commit -m "This is a PR" 264 | ``` 265 | * Push the changes to GitHub: 266 | ```bash 267 | git push --set-upstream origin my-pr 268 | ``` 269 | * Use the **jx** CLI to create a GitHub PR: 270 | ```bash 271 | jx create pr -t "My PR" \ 272 | --body "This is the text that describes the PR 273 | and it can span multiple lines" -b 274 | ``` 275 | 276 | Open the link that is the output of that command. 277 | 278 | Check the progress of the PR build via: 279 | ```bash 280 | jx get activity 281 | ``` 282 | 283 | Get the preview environments: 284 | ```bash 285 | jx get previews 286 | ``` 287 | Check the output of your updated application: 288 | 289 | * Open CKCD and go to the *Environments* screen 290 | * Click on the *Preview* button of your *jx-http-go* application under the *Development* environment 291 | 292 | Merge the PR: 293 | 294 | * Open the pull request screen in GitHub 295 | * Add a `/approve` comment to your PR. 296 | * Prow's Tide component will auot-merge the PR for you and deploy your application to your Staging environment. 297 | 298 | View automatice deployment to staging environment: 299 | 300 | ```bash 301 | jx get activity -f jx-go-http -w 302 | ``` 303 | 304 | You will also see it updated in CKCD. 305 | 306 | ## Use CKCD to Promote to Production 307 | 308 | Open CKCD in your browser and go to the *Environments* screen. 309 | Your instructor will walk you through using CKCD to promote applications between *Staging* 310 | and *Production* environments. 311 | 312 | 313 | 314 | --------------------------------------------------------------------------------