Chatting with Copilot

Let's continue our dialogue with Copilot by finding out more about the project it generated and how we can execute the script. Let's ask the following question:

Prompt Copilot to explain the project and provide instructions

Explain this project and provide instructions on how to execute the Go program

basics-what-is-go-mod

As we can see, we get a precise and informative answer to help us understand what this project template contains, as well as the command that will allow us to execute the Go script. But before we attempt to run our program we should consider, do we have all the prerequisites on our machine to allow us to run a Go program? Let's assume that we do not, since Golang isn't a requirement for this workshop/exercise. However, we do have Docker available to us so lets see if Copilot can help "Dockerize" our project with the following prompt:

Prompt Copilot to Dockerize the project

I do not have Golang installed locally. Generate a Dockerfile that will allow me to run this program in a container. Please include docker execution commands as well

basics-3

As we can see, Copilot has generated a Dockerfile that will allows us to run our application in a container. Click the ... symbol to inject the provided Dockerfile script into a new file called Dockerfile at the root of our project.

basics-docker-build

Let's build and run our application in a container using the commands provided by Copilot.

basics-docker-build-error

Hmm, we seem to have hit a docker build error. Looks like we're missing a go.sum file that our Dockerfile expects to exist. As we are still learning Golang and it's intricacies, let's ask Copilot to enlighten us on what a go.sum is and how we can generate one:

Prompt Copilot for go.sum explanation

What is a go.sum file and how can I generate one for my project?

⚠ Remember that Copilot's output is non-deterministic so at this point you may or may not be receiving the same error as in this example. If you are encountering any different errors or issues at this point, please reach out to the workshop facilitators for assistance.

go-sum

Looks like the go.sum is used for managing checksums of dependencies. Since our simple project does not contain any dependencies, let's go ahead and remove the go.sum from our Dockerfile. In this particular example, we can also see that some of the pathing is slightly off in where the Dockerfile expects our Go files to be. This is a good showcase on how Copilot can often set a good foundation, but may misconfigure a few details because of lack of specific context. Let's go ahead and get those pathing issues fixed, and then attempt a rebuild and run.

run-final

Voila! Our application is now running successfully in a Docker container. Following Copilot's advice has allowed us to quickly get a Golang project up and running, despite a potential unfamiliarity with the language and lack of prerequisite installations. We’re essentially pairing with a domain expert whose knowledge extends almost infinitely. However, as powerful as a tool that Copilot is, it’s also important to keep in mind its limitations and shortcomings. We’ll cover more on that topic in a later section.