Skip to main content

Install the Go agent using a container

The Go agent has two main components: contrast-go (a build tool) and the agent itself (a package injected into your app at build time by contrast-go).

You can download contrast-go with a curl command, or from a repository or package manager. You will also need to configure the agent to connect with Contrast. You can use a YAML configuration file or environment variables. You can download the YAML from Contrast, or create your own from a template.

When installing the Contrast Go agent in a container, you just need to follow these steps in your container image file.

Tip

If you would like to explore a sample application using the Go agent in a separate container, see the Go Test Bench open source project.

Before you begin

This topic provides general guidance for installing the Contrast Go agent in a containerized application, with Docker as an example.

You should have a basic understanding of how containers and related software work. You may need to adjust the instructions to meet your specific circumstances.

Build your application with contrast-go

Follow the instructions to install the Go agent.

  1. Download the Go agent. Either use the curl below, or install with Debian.

    RUN curl -L https://pkg.contrastsecurity.com/go-agent-release/latest/linux-amd64/contrast-go > contrast-go
    
  2. Ensure the correct permissions are set

    RUN chmod u+x contrast-go
  3. Replace your normal go build command with contrast-go build. This will give you an executable with Contrast embedded in it.

    RUN ./contrast-go build -o instrumented-app

    Note

    -o instrumented-app names it instrumented-app which is used in the below steps. You can change the name or omit the -o entirely and a default name is generated based on the package.

Run your instrumented application

  • Run your application.

    CMD ./instrumented-app

See also