Skip to content

Commit

Permalink
add docker config volume to API container
Browse files Browse the repository at this point in the history
  • Loading branch information
skylenet committed Oct 25, 2024
1 parent 04c515d commit 2b582d4
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@ package backend_creator
import (
"context"
"fmt"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/database_accessors/enclave_db"
"net"
"os"
"path"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/database_accessors/enclave_db"

"github.com/docker/docker/client"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/docker_kurtosis_backend/logs_collector_functions"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ const (
NameOfNetworkToStartEngineAndLogServiceContainersIn = "bridge"
HttpApplicationProtocol = "http"

GitHubAuthStorageDirPath = "/kurtosis-data/github-auth/"
DockerConfigStorageDir = "/root/.docker/"
GitHubAuthStorageDirPath = "/kurtosis-data/github-auth/"
DockerConfigStorageDirPath = "/root/.docker/"

EmptyApplicationURL = ""
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -618,3 +618,22 @@ func (backend *DockerKurtosisBackend) getGitHubAuthStorageVolume(ctx context.Con
volume := foundVolumes[0]
return volume.Name, nil
}

// Guaranteed to either return a Docker config storage volume name or throw an error
func (backend *DockerKurtosisBackend) getDockerConfigStorageVolume(ctx context.Context) (string, error) {
volumeSearchLabels := map[string]string{
docker_label_key.VolumeTypeDockerLabelKey.GetString(): label_value_consts.DockerConfigStorageVolumeTypeDockerLabelValue.GetString(),
}
foundVolumes, err := backend.dockerManager.GetVolumesByLabels(ctx, volumeSearchLabels)
if err != nil {
return "", stacktrace.Propagate(err, "An error occurred getting Docker config storage volumes matching labels '%+v'", volumeSearchLabels)
}
if len(foundVolumes) > 1 {
return "", stacktrace.NewError("Found multiple Docker config storage volumes. This should never happen")
}
if len(foundVolumes) == 0 {
return "", stacktrace.NewError("No Docker config storage volume found.")
}
volume := foundVolumes[0]
return volume.Name, nil
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@ package docker_kurtosis_backend
import (
"context"
"encoding/json"
"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_registry_spec"
"net"
"time"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_interface/objects/image_registry_spec"

"github.com/kurtosis-tech/kurtosis/container-engine-lib/lib/backend_impls/docker/object_attributes_provider/docker_label_key"

"github.com/docker/go-connections/nat"
Expand Down Expand Up @@ -81,6 +82,11 @@ func (backend *DockerKurtosisBackend) CreateAPIContainer(
return nil, stacktrace.Propagate(err, "An error occurred getting the GitHub auth storage volume name.")
}

dockerConfigStorageVolumeName, err := backend.getDockerConfigStorageVolume(ctx)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred getting the Docker config storage volume name.")
}

// Get the Docker network ID where we'll start the new API container
enclaveNetwork, err := backend.getEnclaveNetworkByEnclaveUuid(ctx, enclaveUuid)
if err != nil {
Expand Down Expand Up @@ -191,8 +197,9 @@ func (backend *DockerKurtosisBackend) CreateAPIContainer(
}

volumeMounts := map[string]string{
enclaveDataVolumeName: enclaveDataVolumeDirpath,
githubAuthStorageVolumeName: consts.GitHubAuthStorageDirPath,
enclaveDataVolumeName: enclaveDataVolumeDirpath,
githubAuthStorageVolumeName: consts.GitHubAuthStorageDirPath,
dockerConfigStorageVolumeName: consts.DockerConfigStorageDirPath,
}

labelStrs := map[string]string{}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ func CreateEngine(
if err = dockerManager.CreateVolume(ctx, dockerConfigStorageVolNameStr, dockerConfigStorageVolLabelStrs); err != nil {
return nil, stacktrace.Propagate(err, "An error occurred creating Docker config storage volume.")
}
err = docker_config_storage_creator.CreateDockerConfigStorage(ctx, targetNetworkId, dockerConfigStorageVolNameStr, consts.DockerConfigStorageDir, dockerManager)
err = docker_config_storage_creator.CreateDockerConfigStorage(ctx, targetNetworkId, dockerConfigStorageVolNameStr, consts.DockerConfigStorageDirPath, dockerManager)
if err != nil {
return nil, stacktrace.Propagate(err, "An error occurred creating Docker config storage.")
}
Expand All @@ -278,7 +278,7 @@ func CreateEngine(
volumeMounts := map[string]string{
logsStorageVolNameStr: logsStorageDirPath,
githubAuthStorageVolNameStr: consts.GitHubAuthStorageDirPath,
dockerConfigStorageVolNameStr: consts.DockerConfigStorageDir,
dockerConfigStorageVolNameStr: consts.DockerConfigStorageDirPath,
}

if serverArgs.OnBastionHost {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2313,6 +2313,7 @@ func pullImage(dockerClient *client.Client, imageName string, registrySpec *imag
imagePullOptions.RegistryAuth = encodedAuthConfig

}

out, err := dockerClient.ImagePull(pullImageCtx, imageName, imagePullOptions)
if err != nil {
return stacktrace.Propagate(err, "Tried pulling image '%v' with platform '%v' but failed", imageName, platform), false
Expand Down

0 comments on commit 2b582d4

Please sign in to comment.