Skip to content

Set image metadata - #1535

Merged
aluzzardi merged 1 commit into
dagger:mainfrom
helderco:docker-set
Feb 1, 2022
Merged

aluzzardi merged 1 commit into
dagger:mainfrom
helderco:docker-set

Conversation

@helderco

Copy link
Copy Markdown
Contributor

Closes #1339

Signed-off-by: Helder Correia

/cc @jlongtine


Why

Currently there’s no way to update/add values to a Docker image metadata, only to replace in its entirety. Users expect to be able to change the default user, working directory and environment variables, for example.

What

Added a new docker.#Set definition to update/add image config values.

How

Here’s an example that adds to PATH:

package main

import (
	"dagger.io/dagger"
	"universe.dagger.io/docker"
)

dagger.#Plan & {
	inputs: directories: rootfs: path: "rootfs"
	actions: {
		image: docker.#Pull & {
			source: "debian"
		}
		copy: docker.#Copy & {
			input:    image.output
			contents: inputs.directories.rootfs.contents
		}
		set: docker.#Set & {
			input: copy.output
			config: {
				env: {
					FOO_BIN: "/opt/foo/bin"
					PATH:    "\(FOO_BIN):\(input.config.env.PATH)"
				}
				entrypoint: ["/entrypoint.sh"]
			}
		}
		push: docker.#Push & {
			image: set.output
			dest:  "foo/bar"
		}
	}
}

The following #ImageConfig fields are merged: env, label, volume and expose. The field onbuild is appended. All others are fully replaced.

@jlongtine

Copy link
Copy Markdown
Contributor

LGTM!

@aluzzardi

Copy link
Copy Markdown
Contributor

Nice! LGTM!

/cc @shykes for DX review

@shykes shykes left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome. Thanks Helder.

@aluzzardi @jlongtine @talentedmrjones are you OK with that package dagger/utils? Once it’s there, it’s forever :) I’m neutral.

@aluzzardi

Copy link
Copy Markdown
Contributor

@aluzzardi @jlongtine @talentedmrjones are you OK with that package dagger/utils? Once it’s there, it’s forever :) I’m neutral.

Eh, I'd rather not just to be safe. I'd prefer a private _#mergeStructs in the dagger package, for now.

@jlongtine

Copy link
Copy Markdown
Contributor

@aluzzardi @jlongtine @talentedmrjones are you OK with that package dagger/utils? Once it’s there, it’s forever :) I’m neutral.

Eh, I'd rather not just to be safe. I'd prefer a private _#mergeStructs in the dagger package, for now.

I'd lean this direction for now, too. Just to reduce our public maintenance surface. We can expose it later, if we feel inclined.

@helderco

Copy link
Copy Markdown
Contributor Author

I've updated 🙂

@aluzzardi

Copy link
Copy Markdown
Contributor

I've updated 🙂

Thank you! Good to go after CI passes :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Europa: Set image metadata in a Docker build

4 participants