Depot Cache works with Go from your local machine, from Depot's managed GitHub Actions runners, or within containerized builds using Dockerfiles or Bake files.
Note: Go added support for remote caching in Go 1.24, so you need this version or later to take advantage of Depot Cache. Additionally, you need a Depot API token to authenticate with the cache service.
To use Depot Cache with Go on your local machine, set the GOCACHEPROG environment variable:
export GOCACHEPROG="depot gocache"The depot CLI needs authorization to write to the cache.
If you are a member of multiple organizations and authenticating with a user token, specify which organization to use for cache storage:
export GOCACHEPROG='depot gocache --organization ORG_ID'After you configure Go to use Depot Cache, run your builds as you normally would. Go automatically communicates with GOCACHEPROG to fetch from Depot Cache and reuse any stored build artifacts.
To clean the cache, use the typical go clean workflow:
go clean -cacheTo enable verbose output:
export GOCACHEPROG='depot gocache --verbose'When building Docker images that contain Go projects locally, your build needs access to Go's remote cache credentials to benefit from caching. Containerized builds execute in isolated environments that require explicit configuration.
Update your Dockerfile to install the Depot CLI and configure Go cache:
# syntax=docker/dockerfile:1
# ... other Dockerfile instructions
# Install Depot CLI
RUN curl -L https://depot.dev/install-cli.sh | sh
# Mount secret and set GOCACHEPROG
RUN --mount=type=secret,id=DEPOT_TOKEN,env=DEPOT_TOKEN \
PATH="/root/.depot/bin:$PATH" \
GOCACHEPROG="depot gocache" \
go build -v ./Adding # syntax=docker/dockerfile:1 as the first line of your Dockerfile enables mounting secrets as environment variables.
depot build --secret id=DEPOT_TOKEN,env=DEPOT_TOKEN -t your-image:tag .docker buildx build --secret id=DEPOT_TOKEN,env=DEPOT_TOKEN -t your-image:tag .Define the secret in your docker-bake.hcl file:
target "default" {
context = "."
dockerfile = "Dockerfile"
tags = ["your-image:tag"]
secret = [
{
type = "env"
id = "DEPOT_TOKEN"
}
]
}Then run the build:
DEPOT_TOKEN=your_token depot bakeDepot GitHub Actions runners are pre-configured to use Depot Cache with Go. Each runner launches with the GOCACHEPROG environment variable pre-populated with the connection details for Depot Cache.
You don't need additional configuration. Run your Go builds as normal:
jobs:
build:
runs-on: depot-ubuntu-24.04
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.24'
- run: go build ./...To disable automatic configuration, turn off Allow Actions jobs to automatically connect to Depot Cache in your organization settings page. You can then manually configure GOCACHEPROG as described in the Local workstation section.
When running containerized builds on Depot GitHub Actions runners, your build needs access to Go's remote cache credentials. These credentials aren't automatically available inside your Docker build environment.
Update your Dockerfile to install the Depot CLI and configure Go cache:
# syntax=docker/dockerfile:1
# ... other Dockerfile instructions
# Install Depot CLI
RUN curl -L https://depot.dev/install-cli.sh | sh
# Mount secret and set GOCACHEPROG
RUN --mount=type=secret,id=DEPOT_TOKEN,env=DEPOT_TOKEN \
PATH="/root/.depot/bin:$PATH" \
GOCACHEPROG="depot gocache" \
go build -v ./Adding # syntax=docker/dockerfile:1 as the first line of your Dockerfile enables mounting secrets as environment variables.
depot/build-push-actionStore the Depot token in a GitHub Secret named DEPOT_TOKEN, then configure your workflow:
- name: Build and push
uses: depot/build-push-action@v1
with:
context: .
file: ./Dockerfile
push: true
tags: your-image:tag
secrets: |
"DEPOT_TOKEN=${{ secrets.DEPOT_TOKEN }}"depot/bake-actionDefine the secret in your docker-bake.hcl file:
target "default" {
context = "."
dockerfile = "Dockerfile"
tags = ["your-image:tag"]
secret = [
{
type = "env"
id = "DEPOT_TOKEN"
}
]
}Then configure your workflow:
- name: Bake
uses: depot/bake-action@v1
with:
files: docker-bake.hcl
env:
DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}Store the Depot token in a GitHub Secret named DEPOT_TOKEN, then configure your workflow:
- name: Build
run: |
docker buildx build \
--secret id=DEPOT_TOKEN,env=DEPOT_TOKEN \
-t your-image:tag .
env:
DEPOT_TOKEN: ${{ secrets.DEPOT_TOKEN }}