buildkite-plugins / docker-compose-buildkite-plugin

🐳⚡️ Run build scripts, and build + push images, w/ Docker Compose
MIT License
172 stars 138 forks source link

Ability prepare step before run docker-comopse #440

Closed velios closed 1 month ago

velios commented 4 months ago

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 commented 4 months ago

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 commented 4 months ago

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.

toote commented 1 month ago

@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.