Commit 03c35e72 authored by Dan Plumbley's avatar Dan Plumbley Committed by Ian Ernst
Browse files

Resolve "Delete Redundant ILT Labs"

parent 7f41ccdd
Loading
Loading
Loading
Loading
+0 −22
Original line number Diff line number Diff line
---
title: "GitLab Duo Principles - Hands-On Lab Overview"
description: "This Hands-On Guide walks you through the lab exercises in the GitLab Duo Principles course."
---

## GitLab Duo Principles

| Lab Name | Lab Link |
|-----------|------------|
| Getting Started with GitLab Duo | [Lab Guide](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduolab1) |
| Code Generation with GitLab Duo | [Lab Guide](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduolab2) |
| Working with Issues and Merge Requests | [Lab Guide](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduolab3) |
| Using GitLab Duo to Write New Code | [Lab Guide](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduolab4) |
| Working with Security Vulnerabilities | [Lab Guide](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduolab5) |

## Quick links

* [GitLab Duo Principles Course Description](https://university.gitlab.com/pages/duo-training)

## Suggestions?

If you'd like to suggest changes to the *GitLab Duo Principles*, please submit them via merge request.
+0 −54
Original line number Diff line number Diff line
---
title: "GitLab Duo Principles - Hands-On Lab: Getting Started with GitLab Duo"
description: "This Hands-On Guide walks you through using GitLab Duo to answer technical questions."
---

> Estimated time to complete: 10 minutes

## Objectives

GitLab Duo allows you to use AI-assisted features across GitLab. To get started with GitLab Duo, you will need to first generate a lab environment to work in. This lab environment will provide you with all the GitLab Duo features demonstrated in this course.

## Task A. Access your Training Group

1. Navigate to [**https://gitlabdemo.com/invite**](https://gitlabdemo.com/invite) in a web browser.

1. In the **Invitation Code** field, enter the invitation code provided by your instructor or in the GitLab University LMS.

1. Select **Provision Training Environment**.

1. The system will prompt you for your **GitLab.com** username. Enter your GitLab.com username (excluding the leading @ sign) in the field provided. Select **Provision Training Environment**.

1. On the confirmation page, locate the `Your GitLab Credentials` section. Read this section carefully, noting the expiration date. Your access to this group and all of the projects that you create is ephemeral and will be deleted after the expiration date.

1. Select **My Group** at the bottom of the page.

1. Sign in with your GitLab.com credentials.

1. You will be redirected to a **My Test Group** group that provides a sandbox for you to perform training lab steps in.

    > This group has a GitLab Ultimate license to see all of the features while your personal username namespace requires a paid subscription or a free trial to access all of the features.

1. From your **My Test Group** training subgroup, navigate to the **GitLab Duo Principles** project.

    > This project has been pre-populated with a `go.mod` file that will be used in upcoming labs. It also contains an `examples` folder that holds additional examples and activities per lab.

## Task B. Working with GitLab Duo Chat

1. From your project, click the **GitLab Duo Chat** button in the top right corner.

1. A new chat window will appear on the right side of the screen. Try asking some questions and see how the GitLab Duo responds!

Here are a few demo questions you can ask Duo:

- `How do I move an issue from one project to another?`
- `What is a merged results pipeline?`
- `What is an example of a simple Python function?`

## Lab Guide Complete

You have completed this lab exercise. You can view the other [lab guides for this course](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduo).

## Suggestions?

If you'd like to suggest changes to the lab, please submit them via merge request.
+0 −120
Original line number Diff line number Diff line
---
title: "GitLab Duo Principles - Hands-On Lab: Code Generation with GitLab Duo Chat"
description: "This Hands-On Guide walks you through using GitLab Duo to generate and explain code."
---

> Estimated time to complete: 15 minutes

## Objectives

To get started with GitLab Duo, we will test out some of the basic code generation features. Code generation allows you to prompt GitLab Duo for code that solves a specific programming problem.

## Task A. Generating Some Simple Code

In this task, we are going to generate a basic 'hello world' program in Go using GitLab Duo. This task will help you get familiar with the process of creating code in a project with GitLab Duo.

1. Navigate to your GitLab Duo Principles project.

1. Select **Code > Web IDE**.

    > **Note:** In this lab we are using the Web IDE, but you can also use Duo Chat and other Duo tools in your local IDE. [See available extensions](https://docs.gitlab.com/ee/user/project/repository/code_suggestions/supported_extensions.html#supported-editor-extensions).

1. In the Web IDE, locate the GitLab Duo Chat icon. This icon will be the last item in the left side bar, showing the GitLab icon.

1. In the chat text input, enter the text `How do I create a hello world Go program?`

1. Duo chat should respond with code similar to this:

   ```go
   package main

   import "fmt"

   func main() {
     fmt.Println("hello world")
   }
   ```

   > **Note:** Any AI generator will be non-deterministic in nature. This means that when you prompt an AI, there is a possibility that your answer may differ from someone else's answer. If you ever receive an output that appears significantly different from the lab guide, please use the lab guide snippets to ensure you can follow along with other examples.

1. Copy the code generated by GitLab Duo.

1. Select the explorer icon in the left sidebar to return to your code.

1. Next to your project name, select the **New File** icon. The new file should be stored in the root level of your repository.

1. Name the file `main.go`.

1. Inside the file, paste the AI generated code.

You have now created a simple hello world program in Go! In the next section, you will learn how to explain AI generated code.

## Task B. Explaining AI Code

Being able to generate code is only one part of the software development process. In many cases, you also want to be able to understand code that has been written. Whether the code is generated by coworkers or AI, GitLab Duo can explain any code snippet you provide.

1. In the Web IDE, highlight all of the code in your `main.go` file.

1. Select the GitLab Duo icon from the left sidebar.

1. With the code still highlighted, type `/explain` into the chat prompt text box.

1. You will see an explanation of all of the code you have highlighted as a result of the prompt.

## Task C. Commit your Code

Now that you have code generated and you understand the code, you can commit the code into your project.

1. Select **Source Control** in the left sidebar.

1. Enter any commit message, then select `Commit and push to 'main'`

1. If you receive a prompt stating `You are committing your changes to the default branch`, select `Continue`.

1. Select `Go to Project` to return to your GitLab repository.

## Task D. Add a `.gitlab-ci.yml` File

The last step of this lab is to create a `.gitlab-ci.yml` file to build our Go application.

1. In the project repository, at the root level, create a new file in the main branch by clicking **(+) > This directory > New file**.

1. In the **Filename** field, type `.gitlab-ci.yml`.

1. Copy the YAML below into the file.

   ```yml
   stages:
     - build

   default:
     image: golang:latest

   build app:
     stage: build
     script:
       - go run main.go

   ```

   > This `.gitlab-ci.yml` file has one stage `build` with a job `build app` that runs as part of the stage. This job runs our `main.go` app.
   >
   > Again, feel free to highlight the YAML and use `/explain` in GitLab Duo chat to explain the CI pipeline!

1. Select **Commit changes**. In the **Commit message**, type any appropriate message.

1. Ensure the **Target Branch** field is set to main.

1. Select **Commit changes**.

1. To view the pipeline, select **Build > Pipelines** to see the pipeline running.

1. Once the pipeline has successfully completed running, click on the `build app` job to view the output of your main.go app. The `build app` job can be found under your **Stages** section in the build stage.

## Lab Guide Complete

You have completed this lab exercise. You can view the other [lab guides for this course](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduo).

## Suggestions?

If you'd like to suggest changes to the lab, please submit them via merge request.
+0 −168
Original line number Diff line number Diff line
---
title: "GitLab Duo Principles - Hands-On Lab: Working with Issues and Merge Requests"
description: "This Hands-On Guide walks you through using GitLab Duo to create Issues and merge requests."
---

> Estimated time to complete: 20 minutes

## Objectives

GitLab Duo extends beyond just code generation. GitLab Duo can support you through any stage of the DevSecOps lifecycle! In this lab, you will see how GitLab Duo can work with issues and merge requests inside of a project.

## Task A. Creating an Issue with GitLab Duo

1. Navigate to your GitLab Duo Principles Project.

1. In your project, from the left sidebar, select **Plan > Issues**.

1. Select **New issue**.

1. For the Title, input `Update hello world visuals`.

1. In the Duo Chat, enter: `Create an issue description for our team. We want to make our "hello world" application more visually appealing for the end user. We want to incorporate the Go Figure module into our application to print out more exciting text.`

1. The response will look similar to the following:

   ```text
   Issue: The "hello world" application lacks visual appeal

   The current "hello world" application prints basic text without any formatting or visual elements. We want to enhance the user experience and make the application output more interesting to look at.

   The Go Figure module allows printing text in different styles and formats. Integrating this module into our "hello world" code will let us customize how the message is displayed, such as changing fonts, colors, effects and more. This will make our application stand out more and be more enjoyable for end users to interact with.

   ***
   _Description was generated using AI_

   ```

1. Copy the response from Duo Chat and paste it into the issue description field, assign the issue to yourself and select **Create issue**.

## Task B. Creating a Merge Request

1. From the issue you just created, select **Create merge request**.

1. Add a brief description similar to `This MR introduces the Go Figure module to our "hello world" application`.

1. Leave all other options as default and select **Create merge request**.

## Task C. Add Code to Your MR

1. In your MR, select **Code > Open in Web IDE**.

1. Select the Duo Chat icon from the left sidebar.

1. In the chat, write the prompt: `How could I use the go-figure module of go to print hello world in a different font?`

   You will get a response similar to this:

   ```go
   package main

   import (
       "github.com/common-nighthawk/go-figure"
   )

   func main() {
       myFigure := figure.NewFigure("hello world", "", true)
       myFigure.Print()
   }
   ```

1. Copy the generated code.

1. From the left sidebar, select the Explorer icon.

1. Select `main.go`.

1. Replace the contents of `main.go` with the AI generated code by copying and pasting or using the insert button on the code snippet in the Duo Chat window.

1. Your `.gitlab-ci.yml` file should now look like this:

   ```yml
   stages:
     - build

   default:
     image: golang:latest

   build app:
     stage: build
     script:
       - go run main.go
   ```

1. From the left sidebar, select **Source Control**.

1. Enter any commit message and select the **Commit** button to commit the code changes.

1. Select **Go to MR** to return back to your merge request.

## Task D. Summarizing your Code Changes

1. On your merge request, select **Edit**.

1. Just above the Description input, select **Summarize code changes**.

1. Review the new AI generated description.

1. Select **Save changes**.

## Task E. Root Cause Analysis

> Uh-oh! You may have noticed that our pipeline failed.

1. From the MR, select the most recent pipeline run that failed.

1. Select the job that failed.

1. At the bottom of the job output, select **Troubleshoot**.

1. This will open a Duo chat window with a description of the `root cause of failure`. **Note:** You could have also opened Duo chat and used the `/troubleshoot` command to generate this explanation.

1. Review the explanation of the failed job and the example fix.

   > The suggested fix follows a good practice of updating your Go dependencies locally. For our demo purposes we will add this dependency in the `.gitlab-ci.yml` file. Follow the steps below to apply this change. These instructions mirror the suggested fix from GitLab Duo.

1. Return to your merge request.

1. Select **Code > Open in Web IDE**.

1. Open your `.gitlab-ci.yml` file.

1. In the `script` section of your `build app` job, add the script to pull the `go-figure` dependency.

   Your configuration file should look like the file below:

   ```yml
   stages:
     - build

   default:
     image: golang:latest

   build app:
     stage: build
     script:
       - go get github.com/common-nighthawk/go-figure
       - go run main.go
   ```

1. From the left sidebar, select the Source Control icon.

1. Enter any commit message and select the **Commit** button to commit the code changes.

1. Select **Go to MR** to return back to your merge request.

1. From your merge request, wait for the pipeline to complete. You should see that your pipeline passed.

1. If you set your merge request as `Draft`, select `Mark as ready`.

1. Select **Merge** to merge your code updates into the main branch.

## Lab Guide Complete

You have completed this lab exercise. You can view the other [lab guides for this course](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduo).

## Suggestions?

If you'd like to suggest changes to the lab, please submit them via merge request.
+0 −170
Original line number Diff line number Diff line
---
title: "GitLab Duo Principles - Hands-On Lab: Using GitLab Duo to Write New Code"
description: "This Hands-On Guide walks you through using GitLab Duo to generate code and tests."
---

> Estimated time to complete: 25 minutes

## Objectives

In this lab, you will see how GitLab Duo can writing and testing code inside of a project.

## Task A. Using Code Suggestions to Write a New Function

1. Navigate to the root of your GitLab Duo Principles Project.

1. Select the `main.go` file.

1. Select **Edit > Open in Web IDE**.

1. Between the `import` block and `main` function, type the following comment:

   ```text
   // write a function called print_phrase that contains a list of string values. It takes in an index of the list and returns the value at the provided index from a list as a string
   ```

1. Press enter and note the small Tanuki icon that appears in the code margin. Wait until code appears. Once you see code, press Tab.

1. Call your new function in the `main()` function as part of the new `myFigure` object. Make sure you provide an index as an argument. In the example code, the index provided is 0.

1. After doing this, your code should look similar to this:

   ```go
   package main

   import (
       "github.com/common-nighthawk/go-figure"
   )

    // write a function called print_phrase that contains a list of string values. It takes in an index of the list and returns the value at the provided index from a list as a string
    func print_phrase(index int) string {
        phrases := []string{
            "Hello, world!",
            "Go is awesome",
            "Programming is fun",
            "Keep coding",
            "Practice makes perfect",
        }

        if index < 0 || index >= len(phrases) {
            return "Invalid index"
        }

        return phrases[index]
    }

   func main() {
       myFigure := figure.NewFigure(print_phrase(0), "", true)
       myFigure.Print()
   }
   ```

   > By nature, the prompt we entered will generate different code for most users, since we asked for random words from a list. If you see different words in the `phrases :=` definition, that is ok.

## Task B. Generating Code Tests

> The code generated by the GitLab Duo is likely correct, however it is still best practice to test the code for errors before using it in any production environment. Luckily, GitLab Duo can also help us with the test generation process!

1. Highlight all of the code in the `func print_phrase() string` function.

1. Select the GitLab Duo Chat icon in the left sidebar.

1. Type the prompt `/tests`. You will receive some tests similar to below:

   ```go
    package main

    import (
        "testing"
    )

    func TestPrintPhrase(t *testing.T) {
        tests := []struct {
            name     string
            index    int
            expected string
        }{
            {"Valid index 0", 0, "Hello, world!"},
            {"Valid index 2", 2, "Programming is fun"},
            {"Valid index 4", 4, "Practice makes perfect"},
            {"Negative index", -1, "Invalid index"},
            {"Index out of range", 5, "Invalid index"},
        }

        for _, tt := range tests {
            t.Run(tt.name, func(t *testing.T) {
                result := print_phrase(tt.index)
                if result != tt.expected {
                    t.Errorf("print_phrase(%d) = %s; want %s", tt.index, result, tt.expected)
                }
            })
        }
    }
   ```

   > As always, feel free to use `/explain` to understand what this code is doing.

1. To add the tests to your project, start by copying the code generated by GitLab Duo.

1. From the left sidebar, select the Explorer icon.

1. To add the tests to your project, create a new file named `print_phrases.test.go`.

1. If Duo did not already add the package and testing import, include them by adding the following code to the top of the file:

   ```go
   package main

   import "testing"
   ```

1. Below the import for testing, on a new line, paste the generated tests from GitLab Duo.

1. From the left sidebar, select Source Control, enter any commit message, and select **Commit and push to main**.

1. Select **Go to Project** to return to your project.

## Task C. Run tests in a CI/CD pipeline

1. Navigate to **Build > Pipeline editor**.

1. In the `stages` section, add a new stage called `test`.

1. Under the `build app` job create a new job called `test`.

1. Add the `go test` command to run the tests. Your `.gitlab-ci.yml` file will look like the following:

   ```yml
   stages:
       - build
       - test

   default:
       image: golang:latest

   build app:
       stage: build
       script:
           - go get github.com/common-nighthawk/go-figure
           - go run main.go

   test:
       stage: test
       script:
           - go get github.com/common-nighthawk/go-figure
           - go test ./...
   ```

1. Select **Commit changes**.

1. Wait for the pipeline to complete and review the results.

You should now have a pipeline that passed the tests. If a job failed, feel free to use **Troubleshoot** to troubleshoot any errors.

## Lab Guide Complete

You have completed this lab exercise. You can view the other [lab guides for this course](/handbook/customer-success/professional-services-engineering/education-services/devsecopswithduo).

## Suggestions?

If you'd like to suggest changes to the lab, please submit them via merge request.
Loading