Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow absolute URI specification for action images #616

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions cmd/tink-worker/cmd/root.go
Expand Up @@ -40,6 +40,7 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {
user := viper.GetString("registry-username")
pwd := viper.GetString("registry-password")
registry := viper.GetString("docker-registry")
useAbsoluteImageURI := viper.GetBool("use-absolute-image-uri")
captureActionLogs := viper.GetBool("capture-action-logs")

logger.With("version", version).Info("starting")
Expand All @@ -61,9 +62,10 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {
logger,
dockerClient,
worker.RegistryConnDetails{
Registry: registry,
Username: user,
Password: pwd,
Registry: registry,
Username: user,
Password: pwd,
UseAbsoluteImageURI: useAbsoluteImageURI,
})

logCapturer := worker.NewDockerLogCapturer(dockerClient, logger, os.Stdout)
Expand Down Expand Up @@ -96,6 +98,7 @@ func NewRootCommand(version string, logger log.Logger) *cobra.Command {
rootCmd.Flags().StringP("docker-registry", "r", "", "Sets the Docker registry (DOCKER_REGISTRY)")
rootCmd.Flags().StringP("registry-username", "u", "", "Sets the registry username (REGISTRY_USERNAME)")
rootCmd.Flags().StringP("registry-password", "p", "", "Sets the registry-password (REGISTRY_PASSWORD)")
rootCmd.Flags().BoolP("use-absolute-image-uri", "a", false, "Do not prepend docker_registry to template action images (USE_ABSOLUTE_IMAGE_URI)")

must := func(err error) {
if err != nil {
Expand Down
7 changes: 6 additions & 1 deletion cmd/tink-worker/worker/container_manager.go
Expand Up @@ -48,8 +48,13 @@ func NewContainerManager(logger log.Logger, cli DockerClient, registryDetails Re

func (m *containerManager) CreateContainer(ctx context.Context, cmd []string, wfID string, action *pb.WorkflowAction, captureLogs, privileged bool) (string, error) {
l := m.getLogger(ctx)

actionImage := action.GetImage()
if !m.registryDetails.UseAbsoluteImageURI && len(m.registryDetails.Registry) > 0 {
actionImage = path.Join(m.registryDetails.Registry, action.GetImage())
}
config := &container.Config{
Image: path.Join(m.registryDetails.Registry, action.GetImage()),
Image: actionImage,
AttachStdout: true,
AttachStderr: true,
Cmd: cmd,
Expand Down
14 changes: 10 additions & 4 deletions cmd/tink-worker/worker/registry.go
Expand Up @@ -13,9 +13,10 @@ import (

// RegistryConnDetails are the connection details for accessing a Docker registry.
type RegistryConnDetails struct {
Registry string
Username string
Password string
Registry string
Username string
Password string
UseAbsoluteImageURI bool
}

// ImagePullStatus is the status of the downloaded Image chunk.
Expand Down Expand Up @@ -43,7 +44,12 @@ func (m *containerManager) PullImage(ctx context.Context, image string) error {
}
authStr := base64.URLEncoding.EncodeToString(encodedJSON)

out, err := m.cli.ImagePull(ctx, path.Join(m.registryDetails.Registry, image), types.ImagePullOptions{RegistryAuth: authStr})
imageURI := image
if !m.registryDetails.UseAbsoluteImageURI && len(m.registryDetails.Registry) > 0 {
imageURI = path.Join(m.registryDetails.Registry, image)
}

out, err := m.cli.ImagePull(ctx, imageURI, types.ImagePullOptions{RegistryAuth: authStr})
if err != nil {
return errors.Wrap(err, "DOCKER PULL")
}
Expand Down