Skip to content

batch_exec: inject docker container registry as a prefix

Erik Seliger requested to merge dd/inject-container-registry into main

Created by: danieldides

Part of https://github.com/sourcegraph/customer/issues/1872 Depends on: https://github.com/sourcegraph/sourcegraph/pull/48499

This checks for the presence of an optional environment variable passed to the src batch exec directive that contains a docker registry URL. If it's present, it prefixes the container name with the registry information to create a fully-qualified domain name for all subsequent docker commands.

Test plan

Batch spec:

name: test
description: Add Hello World to READMEs

on:
  - repositoriesMatchingQuery: file:README.md count:4

steps:
  - run: IFS=$'\n'; echo Hello World | tee -a $(find -name README.md)
    container: busybox:1.35.0

changesetTemplate:
  title: Hello World
  body: My first batch change!
  commit:
    message: Append Hello World to all README.md files
  branch: ${{ batch_change.name }}

Add

for _, step := range task.Steps {
	fmt.Println("step: ", step.Container)
}

before the docker.NewImageCache() function call.

Execute a batch change without the environment variable set (default):

Screenshot 2023-03-01 at 14 03 54

Note the container name is just 1.35.0.

Execute a batch change with the environment variable set:

Restart sg start batches setting:

batches-executor:
    <<: *executor_template
    cmd: |
      env TMPDIR="$HOME/.sourcegraph/batches-executor-temp" .bin/executor
    env:
      EXECUTOR_QUEUE_NAME: batches
      EXECUTOR_MAXIMUM_NUM_JOBS: 8
      EXECUTOR_DOCKER_REGISTRY_PREFIX_URL: us-central1-docker.pkg.dev/control-plane-5e9ee072/remote-docker-hub

Or similar in sg.config.yaml. Restart the batch change (you may need to make a small change to it to prevent cached results from showing): Screenshot 2023-03-01 at 14 29 57

Note the container name is now fully prefixed.

Merge request reports

Loading