Skip to content
This repository was archived by the owner on Nov 27, 2023. It is now read-only.

introduce --pull flag to set pull policy#1183

Closed
ndeloof wants to merge 1 commit intomainfrom
pull_policy
Closed

introduce --pull flag to set pull policy#1183
ndeloof wants to merge 1 commit intomainfrom
pull_policy

Conversation

@ndeloof
Copy link
Collaborator

@ndeloof ndeloof commented Jan 27, 2021

What I did
Allow user to pass --pull=never or --pull=always to force some image lifecycle

Related issue
see docker/compose#6464 and related debates on pull vs build vs never pull vs pull before build etc

(not mandatory) A picture of a cute animal, if possible in relation with what you did

@github-actions github-actions bot added the cli cli label Jan 27, 2021
}

if contextType == store.LocalContextType {
flags.StringVar(&opts.PullPolicy, "pull", "", "Define pull policy for service images (always|never|if_not_present|build).")
Copy link
Member

Choose a reason for hiding this comment

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

docker run uses "missing" for the if_not_present case (which is the default);

      --pull string                    Pull image before running ("always"|"missing"|"never") (default "missing")

For backward-compatibility (--pull used to be a "boolean" on docker run), specifying --pull without a value is equivalent to --pull=always. Not sure if we need to add that logic here (because this is a new flag).

What's the build option? It's a bit unclear to me what it's intended for; if that's meant for "only do a pull if we also have to do a build", should we keep it simple, and keep that for docker compose build [--pull=<policy>] ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

that's a bit unfortunate defining this pull_policy as part of the compose-spec was not coordinated with introducion of the docker run pull flag for consistency :'(

Copy link
Member

Choose a reason for hiding this comment

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

With the compose-spec not having a release yet, could we still change? I see I left a comment at the time in compose-spec/compose-spec#78 (comment) as well

TBH; Overall a bit on the fence of having it as an option in the compose-file itself, as it feels more of an option that should be set by the person doing the deploy, not a "declarative" option that specifies/defines the stack

Copy link
Contributor

@gtardif gtardif left a comment

Choose a reason for hiding this comment

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

LGTM after updating with compose-spec/compose-go#99

@thaJeztah
Copy link
Member

GitHub was a bit too eager closing

Screenshot 2021-01-29 at 16 47 16

@gtardif
Copy link
Contributor

gtardif commented Jan 29, 2021

Thx @thaJeztah !
#1183 is now merged, @ndeloof we can bump version and use "missing" here

@thaJeztah
Copy link
Member

I'm still confused by the --pull-policy=build option (even more so because it's in the compose-file itself);

build: Compose implementations SHOULD build the image. Compose implementations SHOULD rebuild the image if already present.

  • docker-compose up --build is (currently) to trigger a build; the builder (if no changes) should then use its caching mechanism to determine if a rebuild is needed
  • --pull-policy=always (note that currently docker (buildx) build only supports --pull (boolean)) would in case of a "build" also update images used for the build itself

Note that the combination of --build and "pulling" can be tricky (what comes first?);

  • a service that builds an image (and has "just" rebuilt its image) would first overwrite the fresh (locally built) image, then the build would overwrite it again with a the new version
  • having a pull-policy in the compose-file (in various situations) would now effectively "force" a user to also pass --pull-policy on the command-line to override the behavior (local development cycle) to prevent work being "un-done"

So I'm still quite uncomfortable with the pull policy being in the compose-file itself; this really feels like an option that should generally be passed on the commandline, as it's not declarative.

@ndeloof
Copy link
Collaborator Author

ndeloof commented Jan 29, 2021

I'm still confused because it's in the compose-file itself

The compose spec actually defines an model, and attributes can be set by yaml or command line flags, depending the implementation. This is up to users to decide if they want to hard code some behaviour in the yaml file or repeat --pull option. Basically, many users rely on compose to make docker run commands shorter and not have to remember tons of flags.

Note that the combination of --build and "pulling" can be tricky (what comes first?);

this is what pull_policy has been designed for. pull_policy: build means image should be built from source, not pulled. Compose spec is not designed to follow buildx UX :D

@thaJeztah
Copy link
Member

Basically, many users rely on compose to make docker run commands shorter and not have to remember tons of flags.

I understand how it's used, but still think there's a separation between describing/declaring a "stack", and runtime options / options for a specific deploy (I recall some discussion on that in docker/compose#846)

@ndeloof
Copy link
Collaborator Author

ndeloof commented Feb 2, 2021

Most of the deploy section is actually about runtime options. It's way too late to make compose file format a clean, abstract declarative model.
From a pure usability point of view, users have asked for a way to get compose up to build first of pull first (on disctinct issues) with reasonable usage scenarios. With this attribute we give them an opportunity to achieve this. Obviously flags allow to override for other usages.

@ndeloof ndeloof self-assigned this Feb 2, 2021
Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
@ndeloof
Copy link
Collaborator Author

ndeloof commented Mar 11, 2021

closing this, will see later if we want to introduce this flag to compose command

@ndeloof ndeloof closed this Mar 11, 2021
@lorenrh lorenrh deleted the pull_policy branch October 18, 2021 14:47
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

cli cli

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants