firecow / gitlab-ci-local

Tired of pushing to test your .gitlab-ci.yml?
MIT License
2.28k stars 128 forks source link

support `image:pull_policy` to allow forcing 'always' behavior #1199

Closed danstoner closed 4 months ago

danstoner commented 5 months ago

Is your feature request related to a problem? Please describe.

I had an old version of a docker image on my computer that had been pulled previously. Running the job via gitlab-ci-local failed because the current pipeline was no longer compatible with the contents of the old image. Docker's default behavior is to only pull the image if it is 'missing'.

By manually forcing the pull of the latest image locally with docker pull I was able to resolve the issue, but I had to go digging around in the pipeline code to find which image our pipeline was using. This is bound to happen again in the future. This is not a great experience for my developers and requires having to know the internals of the pipeline (rather than just using it).

Describe the solution you'd like

It would be nice if gitlab-ci-local supported image pull_policy. This way we could set it to 'always' and avoid developers having stale images.

Our current dev deploy pipeline specifies an image:

.deploy/feature:
  # Job configuration for deploying apps on feature branches to dev account.
  image: "registry.gitlab.com/path/to/cicd-docker:latest"
  stage: "deploy"
  ...

Possible future:

.deploy/feature:
  # Job configuration for deploying apps on feature branches to dev account.
  image:
    name: "registry.gitlab.com/path/to/cicd-docker:latest"
    pull_policy: "always"
  stage: "deploy"

Describe alternatives you've considered

gitlab-ci-local could itself always run pull before run via its standard command-line option:

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

or maybe allow an environment variable to be set to control that behavior.

Speaking of environment variables, I could not find a DOCKER_ environment variable to control this behavior from outside gitlab-ci-local.

Additional context

Here are some links to GitLab docs and discussion on their addition of the pull_policy feature:

https://docs.gitlab.com/ee/ci/yaml/?query=pull_policy#imagepull_policy

https://gitlab.com/gitlab-org/gitlab/-/issues/21619

elafontaine commented 5 months ago

To pitch in on this, we were actually considering this package, but the main limiter for us has been the fact that our customer base (developers) would be running stale images for a while. We would prefer to be able to mention something in the configuration to pull always and use the CLI to deactivate that feature when needed (e.g. --no-pull).

I do not care about the gitlab job definition support, it's really about the tooling of gitlab-ci-local that we would want it to be configurable.

firecow commented 5 months ago

I will start working on a --image-pull-policy command line option.

elafontaine commented 4 months ago

I would make it a --pull and/or --no-pull option that would also be configurable (default to "pull"? )

Just a recommendation based on my experience, take it with a grain of salt ;)

firecow commented 4 months ago

https://github.com/firecow/gitlab-ci-local/blob/master/src/index.ts#L202 I have used the same terms that gitlab does --pull-policy=always or --pull-policy=if-not-present (default, until 5.x.x)