Skip to main content

コンテナにGoエージェントをインストール

Goエージェントのコンテナへのインストールは、インストールがコンテナ内で行われる点を除き、基本的に標準のインストール手順と同じです。

ヒント

DockerfileでGoエージェントを使用するサンプルアプリケーションを参照したい場合は、Go Test Benchプロジェクトをご覧ください。

開始する前に

  • コンテナや関連ソフトウェアの仕組みを基本的に理解している必要があります。

  • 必要に応じて、お客様の環境に合わせて手順を調整してください。

Goアプリケーションをインストール、ビルド、実行

  1. Goがインストールされていることを確認します。

  2. 以下のコマンドで、contrast-goをインストールします。

    RUN github.com/contrast-security-oss/contrast-go-installer@latest latest
  3. 通常のgo buildコマンドをcontrast-go buildに置き換えて、アプリケーションをビルドします。このステップによって、Contrastが組み込まれた実行ファイルがビルドされます。

    RUN contrast-go build ./app
  4. エージェント設定ファイルか環境変数で、エージェントを設定します。

Dockerの例

DockerコンテナにGoアプリケーションをインストール、ビルド、および実行する方法の例として、以下を参照ください。

# Step 1: Install Go. You can use a different base image than the one shown in
# this example.
FROM golang:1.21 AS builder
WORKDIR /build

COPY . .

# Step 2: This step installs contrast-go and makes sure it's in your $PATH so 
# you can use it in the next step.
RUN go run github.com/contrast-security-oss/contrast-go-installer@latest latest

# Step 3: This step is your normal build step, but uses contrast-go instead of
# go. This step doesn't replace Go; it just wraps it so that it can add 
# instrumentation during the build process.
RUN contrast-go build ./app

# Optional: Move the finished build to a new container.
# Not required, but nice to have!
FROM alpine:latest
COPY --from=builder /build/app .

# Step 4: Copy the Contrast configuration file. Alternatively, you can use 
# environment variables intsead of the configuration file.
COPY ./contrast_security.yaml .

ENTRYPOINT ["./app"]

関連項目