docker-compose-buildkite-plugin icon indicating copy to clipboard operation
docker-compose-buildkite-plugin copied to clipboard

Ability prepare step before run docker-comopse

Open velios opened this issue 1 year ago • 2 comments

Hi. First of all, thank you very much for such a wonderful plugin.

I have a slight misunderstanding about what needs to be done to perform some settings on the agent before running docker and is this possible? I expected that a command at the step level was created for this, but it passes directly to the docker. Are there any mechanisms for preparing the agent before run docker-compose ?

  - label: "Format namespaces"
  plugins:
  - docker-compose#v5.2.0:
      pre-steps: "some preparation command" # is it possible make something like this?
      run: "fmt-ns"
      command: ["check"] # docker-compose run fmt-ns check
      mount-checkout: true
      workdir: "/app"
  retry:
    automatic:
      - exit_status: "*"
        limit: 1

I understand it can be done with pre-command hook, but intrested in another options

velios avatar May 21 '24 15:05 velios

Or like in documentation example

- plugins:
      - docker-login#v2.0.1:
          username: xyz
      - docker-compose#v5.2.0:
          build: app
          push: app:index.docker.io/myorg/myrepo:tag

but instead of docker-login call some custom user command

velios avatar May 22 '24 08:05 velios

Solved, but hacky. By adding my own plugin. It seems like it would be nice if the plugin had a pre-command hook that would be controlled by a separate argument. For preparation steps. Supports both passing strings and vectors of strings.

  label: "Format namespaces"
  plugins:
  - velios/hooks#v1.0.0:
      precommand: "some-command-line-tool container registry configure-docker"
  - docker-compose#v5.2.0:
      run: "fmt-ns"
      command: ["check"] # check - режим не меняющий файлы внутри volume
      mount-checkout: true
      workdir: "/app"
  retry:
    automatic:
      - exit_status: "*"
        limit: 1

If this feature is not desirable, then the task can be closed; I have described a workaround.

velios avatar May 22 '24 08:05 velios

@velios thanks a lot for the comments and feedback. We have thought about something like what you requested but in most cases it is something that is better placed in hooks outside of this plugin. Otherwise, we will end up replicating all the logic of the agent itself within this plugin 😛

If it is something that is necessary on the agent setup level, it should be an agent-level hook or maybe even a configuration of the machine itself. If it is something that requires some cleanup afterwards (to prevent cross-contamination of the execution environment with other steps ran by the same agent afterwards), like logging out of the registry or cleaning up the docker configuration then you should use repository hooks or - as you have done - a plugin on its own to replicate that functionality when/if you need it.

toote avatar Aug 13 '24 09:08 toote