diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index a06df507..136e81cc 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -17,14 +17,15 @@ steps: plugins: plugin-linter#v3.2.0: id: docker-compose + readme: docs/examples.md - label: ":bash: Tests" plugins: ${BUILDKITE_PULL_REQUEST_REPO:-$BUILDKITE_REPO}#${BUILDKITE_COMMIT}: run: tests - command: ["bats", "tests", "tests/v2"] # for pretty colors tty: true + command: ["bats", "tests", "tests/v1"] # The rest of the steps are integration tests @@ -109,6 +110,7 @@ steps: - label: run after prebuild with custom tag depends_on: prebuild-custom-image-name + key: run-custom-image-name env: RESTORE_REGISTRY_FROM: prebuild-custom-image-name plugins: @@ -119,7 +121,7 @@ steps: commmand: ["/hello"] - label: push after build with custom tag - depends_on: prebuild-custom-image-name + depends_on: run-custom-image-name env: RESTORE_REGISTRY_FROM: prebuild-custom-image-name plugins: diff --git a/README.md b/README.md index 9330f134..c0530ea5 100644 --- a/README.md +++ b/README.md @@ -7,296 +7,10 @@ A [Buildkite plugin](https://buildkite.com/docs/agent/v3/plugins) that lets you * Supports pre-building of images, allowing for fast parallel builds across distributed agents * Supports pushing tagged images to a repository -## Example -The following pipeline will run `test.sh` inside a `app` service container using Docker Compose, the equivalent to running `docker-compose run app test.sh`: +## Examples -```yml -steps: - - command: test.sh - plugins: - - docker-compose#v4.16.0: - run: app -``` - -:warning: Warning: you should not use this plugin with an array of commands at the step level. Execute a script in your repository, a single command separated by `;` or the plugin's [`command` option](#command-optional-run-only-array) instead: - -```yml -steps: - - plugins: - - docker-compose#v4.16.0: - run: app - command: ["custom", "command", "values"] -``` - -The plugin will honor the value of the `COMPOSE_FILE` environment variable if one exists (for example, at the pipeline or step level). But you can also specify custom Docker Compose config files with the `config` option: - -```yml -steps: - - command: test.sh - plugins: - - docker-compose#v4.16.0: - run: app - config: docker-compose.tests.yml - env: - - BUILDKITE_BUILD_NUMBER -``` - -## Authenticated registries - -You can leverage the [docker-login plugin](https://github.com/buildkite-plugins/docker-login-buildkite-plugin) in tandem for authenticating with a registry. For example, the following will build and push an image to a private repo, and pull from that private repo in subsequent run commands: - -```yml -steps: - - plugins: - - docker-login#v2.0.1: - username: xyz - - docker-compose#v4.16.0: - build: app - push: app:index.docker.io/myorg/myrepo:tag - - wait - - command: test.sh - plugins: - - docker-login#v2.0.1: - username: xyz - - docker-compose#v4.16.0: - run: app -``` - -Note, you will need to add the configuration to all steps in which you use this plugin. - -## Artifacts - -If you’re generating artifacts in the build step, you’ll need to ensure your Docker Compose configuration volume mounts the host machine directory into the container where those artifacts are created. - -For example, if your `app` service generates information that you want as artifacts in the `/folder/dist` folder, you would need to ensure the `app` service in your Docker Compose config has a host volume mount defined as `./dist:/folder/dist` or specify it in the plugin's configuration: - -```yml -steps: - - command: generate-dist.sh - artifact_paths: "dist/*" - plugins: - - docker-compose#v4.16.0: - run: app - volumes: - - "./dist:/folder/dist" -``` - -If you want to use environment variables in the `volumes` element, you will need to activate the (unsafe) option `expand-volume-vars` (and most likely escape it using `$$VARIABLE_NAME` to ensure they are not interpolated when the pipeline is uploaded). - -## Environment - -By default, docker-compose makes whatever environment variables it gets available for -interpolation of docker-compose.yml, but it doesn't pass them in to your containers. - -You can use the [environment key in docker-compose.yml](https://docs.docker.com/compose/environment-variables/) to either set specific environment vars or "pass through" environment variables from outside docker-compose. - -### Specific values - -If you want to add extra environment above what is declared in your `docker-compose.yml`, -this plugin offers a `environment` block of its own: - -```yml -steps: - - command: generate-dist.sh - plugins: - - docker-compose#v4.16.0: - run: app - env: - - BUILDKITE_BUILD_NUMBER - - BUILDKITE_PULL_REQUEST - - MY_CUSTOM_ENV=llamas -``` - -Note how the values in the list can either be just a key (so the value is sourced from the environment) or a KEY=VALUE pair. - -### Pipeline variables - -Alternatively, you can have the plugin add all environment variables defined for the job by the agent as defined in [`BUILDKITE_ENV_FILE`](https://buildkite.com/docs/pipelines/environment-variables#BUILDKITE_ENV_FILE) activating the `propagate-environment` option: - -```yml -steps: - - command: use-vars.sh - plugins: - - docker-compose#v4.16.0: - run: app - propagate-environment: true -``` - -## Container Labels - -When running a command, the plugin will automatically add the following Docker labels to the container specified in the `run` option: -- `com.buildkite.pipeline_name=${BUILDKITE_PIPELINE_NAME}` -- `com.buildkite.pipeline_slug=${BUILDKITE_PIPELINE_SLUG}` -- `com.buildkite.build_number=${BUILDKITE_BUILD_NUMBER}` -- `com.buildkite.job_id=${BUILDKITE_JOB_ID}` -- `com.buildkite.job_label=${BUILDKITE_LABEL}` -- `com.buildkite.step_key=${BUILDKITE_STEP_KEY}` -- `com.buildkite.agent_name=${BUILDKITE_AGENT_NAME}` -- `com.buildkite.agent_id=${BUILDKITE_AGENT_ID}` - -These labels can make it easier to query containers on hosts using `docker ps` for example: - -```bash -docker ps --filter "label=com.buildkite.job_label=Run tests" -``` - -This behaviour can be disabled with the `run-labels: false` option. - -## Build Arguments - -You can use the [build args key in docker-compose.yml](https://docs.docker.com/compose/compose-file/build/#args) to set specific build arguments when building an image. - -Alternatively, if you want to set build arguments when pre-building an image, this plugin offers an `args` block of its own: - -```yml -steps: - - command: generate-dist.sh - plugins: - - docker-compose#v4.16.0: - build: app - args: - - MY_CUSTOM_ARG=panda - push: app -``` - -Note that the values in the list must be a `KEY=VALUE` pair. - -## Pre-building the image - -If you have multiple steps that use the same service/image (such as steps that run in parallel), you can use this plugin in a specific `build` step to your pipeline. That will set specific metadata in the pipeline for this plugin to use in `run` steps afterwards: - -```yml -steps: - - label: ":docker: Build" - plugins: - - docker-compose#v4.16.0: - build: app - push: app - - - wait - - - label: ":docker: Test %n" - command: test.sh - parallelism: 25 - plugins: - - docker-compose#v4.16.0: - run: app -``` - -All `run` steps for the service `app` will automatically pull and use the pre-built image. Without this, each `Test %n` job would build its own instead. - -## Building multiple images - -Sometimes your compose file has multiple services that need building. The example below will build images for the `app` and `tests` service and then the run step will pull them down and use them for the run as needed. - -```yml -steps: - - label: ":docker: Build" - agents: - queue: docker-builder - plugins: - - docker-compose#v4.16.0: - build: - - app - - tests - push: - - app - - tests - - - wait - - - label: ":docker: Test %n" - command: test.sh - parallelism: 25 - plugins: - - docker-compose#v4.16.0: - run: tests -``` - -## Pushing Tagged Images - -If you want to push your Docker images ready for deployment, you can use the `push` configuration (which operates similar to [docker-compose push](https://docs.docker.com/compose/reference/push/): - -```yml -steps: - - label: ":docker: Push" - plugins: - - docker-compose#v4.16.0: - push: app -``` - -To push multiple images, you can use a list: - -```yml -steps: - - label: ":docker: Push" - plugins: - - docker-compose#v4.16.0: - push: - - first-service - - second-service -``` - -If you want to push to a specific location (that's not defined as the `image` in your docker-compose.yml), you can use the `{service}:{repo}:{tag}` format, for example: - -```yml -steps: - - label: ":docker: Push" - plugins: - - docker-compose#v4.16.0: - push: - - app:index.docker.io/myorg/myrepo/myapp - - app:index.docker.io/myorg/myrepo/myapp:latest -``` - -## Reusing caches from images - -A newly spawned agent won't contain any of the docker caches for the first run which will result in a long build step. To mitigate this you can reuse caches from a previously built image (if it was pushed from a previous build): - -```yaml -steps: - - label: ":docker: Build an image" - plugins: - - docker-compose#v4.16.0: - build: app - push: app:myregistry:port/myrepo/myapp:my-branch - cache-from: - - "app:myregistry:port/myrepo/myapp:my-branch" - - "app:myregistry:port/myrepo/myapp:latest" - - - wait - - - label: ":docker: Push to final repository" - plugins: - - docker-compose#v4.16.0: - push: - - app:myregistry:port/myrepo/myapp:latest -``` - -For images to be pulled and used as a cache they [need to be built with the `BUILDKIT_INLINE_CACHE=1` build argument](https://docs.docker.com/engine/reference/commandline/build/#cache-from). - -The values you add in the `cache-from` will be mapped to the corresponding service's configuration. That means that you can use any valid cache type your environment supports: - -```yaml -steps: - - label: ":docker: Build an image" - plugins: - - docker-compose#v4.16.0: - build: app - push: app:index.docker.io/myorg/myrepo:my-branch - cache-from: - - "app:type=registry,ref=myregistry:port/myrepo/myapp:my-branch" - - "app:myregistry:port/myrepo/myapp:latest" - - - wait - - - label: ":docker: Push to final repository" - plugins: - - docker-compose#v4.16.0: - push: - - app:myregistry:port/myrepo/myapp:latest -``` +You can learn a lot about how this plugin is used by browsing the [documentation examples](docs/examples.md). ## Configuration @@ -306,9 +20,9 @@ You will need to specify at least one of the following to use this extension. #### `build` -The name of a service to build and store, allowing following pipeline steps to run faster as they won't need to build the image. The step's `command` will be ignored and does not need to be specified. +The name of a service to build and store, allowing following pipeline steps to run faster as they won't need to build the image. Either a single service or multiple services can be provided as an array. -Either a single service or multiple services can be provided as an array. +If you do not specify a `push` option for the same services, the built image(s) will not be available to be used and may cause further steps to fail. If there is no `run` option, the step's `command` will be ignored. #### `run` @@ -316,45 +30,17 @@ The name of the service the command should be run within. If the docker-compose #### `push` -A list of services to push in the format `service:image:tag`. If an image has been pre-built with the build step, that image will be re-tagged, otherwise docker-compose's built-in push operation will be used. - -#### Known issues +A list of services to push. You can specify just the service name to push or the format `service:registry:tag` to override where the service's image is pushed to. Needless to say, the image for the service must have been built in the very same step or built and pushed previously to ensure it is available for pushing. -##### Run & Push +### Other options -A basic pipeline similar to the following: +None of the following are mandatory. -```yaml -steps: - - label: ":docker: Run & Push" - plugins: - - docker-compose#v4.16.0: - run: myservice - push: myservice -``` - -Will cause the image to be built twice (once before running and once before pushing) unless there was a previous `build` step that set the appropriate metadata. - -##### Build & Push - -A basic pipeline similar to the following: - -```yaml -steps: - - label: ":docker: Build & Push" - plugins: - - docker-compose#v4.16.0: - build: myservice - push: myservice -``` - -Will cause the image to be pushed twice (once by the build step and another by the push step) - -### `pull` (optional, run only) +#### `pull` (run only, string or array) Pull down multiple pre-built images. By default only the service that is being run will be pulled down, but this allows multiple images to be specified to handle prebuilt dependent images. Note that pulling will be skipped if the `skip-pull` option is activated. -### `collapse-logs` (optional, boolean) +#### `collapse-logs` (boolean) Whether to collapse or expand the log group that is created for the output of the main commands (`run`, `build` and `push`). When this setting is `true`, the output is collected into a `---` group, when `false` the output is collected into a `+++` group. Setting this to `true` can be useful to de-emphasize plugin output if your command creates its own `+++` group. @@ -362,37 +48,37 @@ For more information see [Managing log output](https://buildkite.com/docs/pipeli Default `false` -### `config` (optional) +#### `config` The file name of the Docker Compose configuration file to use. Can also be a list of filenames. If `$COMPOSE_FILE` is set, it will be used if `config` is not specified. Default: `docker-compose.yml` -### `build-alias` (optional, build only) +#### `build-alias` (push only, string or array) Other docker-compose services that should be aliased to the service that was built. This is to have a pre-built image set for different services based off a single definition. Important: this only works when building a single service, an error will be generated otherwise. -### `args` (optional, build and run only) +#### `args` (build only, string or array) A list of KEY=VALUE that are passed through as build arguments when image is being built. -### `env` or `environment` (optional, run only) +#### `env` or `environment` (run only, string or array) A list of either KEY or KEY=VALUE that are passed through as environment variables to the container. -### `env-propagation-list` (optional, string) +#### `env-propagation-list` (run only) If you set this to `VALUE`, and `VALUE` is an environment variable containing a space-separated list of environment variables such as `A B C D`, then A, B, C, and D will all be propagated to the container. This is helpful when you've set up an `environment` hook to export secrets as environment variables, and you'd also like to programmatically ensure that secrets get propagated to containers, instead of listing them all out. -### `propagate-environment` (optional, boolean) +#### `propagate-environment` (run only, boolean) Whether or not to automatically propagate all pipeline environment variables into the run container. Avoiding the need to be specified with environment. **Important**: only pipeline environment variables will be propagated (what you see in the BuildKite UI, those listed in `$BUILDKITE_ENV_FILE`). This does not include variables exported in preceeding `environment` hooks. If you wish for those to be propagated you will need to list them specifically or use `env-propagation-list`. -### `command` (optional, run only, array) +#### `command` (run only, array) Sets the command for the Docker image, and defaults the `shell` option to `false`. Useful if the Docker image has an entrypoint, or doesn't contain a shell. @@ -400,51 +86,51 @@ This option can't be used if your step already has a top-level, non-plugin `comm Examples: `[ "/bin/mycommand", "-c", "test" ]`, `["arg1", "arg2"]` -### `shell` (optional, run only, array or boolean) +#### `shell` (run only, array or boolean) Set the shell to use for the command. Set it to `false` to pass the command directly to the `docker-compose run` command. The default is `["/bin/sh", "-e", "-c"]` unless you have provided a `command`. Example: `[ "powershell", "-Command" ]` -### `skip-checkout` (optional, run only) +#### `skip-checkout` (boolean) Whether to skip the repository checkout phase. This is useful for steps that use a pre-built image and will fail if there is no pre-built image. -**Important**: as the code repository will not be available in the step, you need to ensure that the docker compose file(s) are present in some way (like using artifacts) +**Important**: as the code repository will not be available in the step, you need to ensure that any files used (like the docker compose files or scripts to be executed) are present in some other way (like using artifacts or pre-baked into the images used). -### `skip-pull` (optional, build and run only) +#### `skip-pull` (build and run only, boolean) Completely avoid running any `pull` command. Images being used will need to be present in the machine from before or have been built in the same step. Could be useful to avoid hitting rate limits when you can be sure the operation is unnecessary. Note that it is possible other commands run in the plugin's lifecycle will trigger a pull of necessary images. -### `workdir` (optional, run only) +#### `workdir` (run only) -Specify the container working directory via `docker-compose run --workdir`. This option is also used by [`mount-checkout`](#mount-checkout-optional-run-only-boolean) if it doesn't specify where to mount the checkout in the container. +Specify the container working directory via `docker-compose run --workdir`. This option is also used by [`mount-checkout`](#mount-checkout-run-only-string-or-boolean) if it doesn't specify where to mount the checkout in the container. Example: `/app` -### `user` (optional, run only) +#### `user` (run only) Run as specified username or uid via `docker-compose run --user`. -### `propagate-uid-gid` (optional, run-only, boolean) +#### `propagate-uid-gid` (run only, boolean) Whether to match the user ID and group ID for the container user to the user ID and group ID for the host user. It is similar to specifying user: 1000:1000, except it avoids hardcoding a particular user/group ID. Using this option ensures that any files created on shared mounts from within the container will be accessible to the host user. It is otherwise common to accidentally create root-owned files that Buildkite will be unable to remove, since containers by default run as the root user. -### `mount-ssh-agent` (optional, run-only, boolean or string) +#### `mount-ssh-agent` (run only, boolean or string) Whether to mount the ssh-agent socket (at `/ssh-agent`) from the host agent machine into the container or not. Instead of just `true` or `false`, you can specify absolute path in the container for the home directory of the user used to run on which the agent's `.ssh/known_hosts` will be mounted (by default, `/root`). Default: `false` -### `mount-buildkite-agent` (optional, run-only, boolean) +#### `mount-buildkite-agent` (run only, boolean) Whether to automatically mount the `buildkite-agent` binary and associated environment variables from the host agent machine into the container. Default: `false` -### `mount-checkout` (optional, run-only, string or boolean) +#### `mount-checkout` (run only, boolean or string) The absolute path where to mount the current working directory which contains your checked out codebase. @@ -452,37 +138,33 @@ If set to `true` it will mount onto `/workdir`, unless `workdir` is set, in whic Default: `false` -### `pull-retries` (optional) +#### `pull-retries` (run only, integer) A number of times to retry failed docker pull. Defaults to 0. -This option can also be configured on the agent machine using the environment variable `BUILDKITE_PLUGIN_DOCKER_COMPOSE_PULL_RETRIES`. - -### `push-retries` (optional) +#### `push-retries` (push only, integer) A number of times to retry failed docker push. Defaults to 0. -This option can also be configured on the agent machine using the environment variable `BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_RETRIES`. - -### `cache-from` (optional, build only) +#### `cache-from` (build only, string or array) A list of images to attempt pulling before building in the format `service:CACHE-SPEC` to allow for layer re-use. Will be ignored if `no-cache` is turned on. They will be mapped directly to `cache-from` elements in the build according to the spec so any valid format there should be allowed. -### `target` (optional, build only) +#### `target` (build only) Allow for intermediate builds as if building with docker's `--target VALUE` options. Note that there is a single build command run for all services so the target value will apply to all of them. -### `volumes` (optional, run only) +#### `volumes` (run only, string or array) A list of volumes to mount into the container. If a matching volume exists in the Docker Compose config file, this option will override that definition. Additionally, volumes may be specified via the agent environment variable `BUILDKITE_DOCKER_DEFAULT_VOLUMES`, a `;` (semicolon) delimited list of mounts in the `-v` syntax. (Ex. `buildkite:/buildkite;./app:/app`). -### `expand-volume-vars` (optional, boolean, run only, unsafe) +#### `expand-volume-vars` (run only, boolean, unsafe) When set to true, it will activate interpolation of variables in the elements of the `volumes` configuration array. When turned off (the default), attempting to use variables will fail as the literal `$VARIABLE_NAME` string will be passed to the `-v` option. @@ -490,91 +172,91 @@ When set to true, it will activate interpolation of variables in the elements of Note that rules regarding [environment variable interpolation](https://buildkite.com/docs/pipelines/environment-variables#runtime-variable-interpolation) apply here. That means that `$VARIABLE_NAME` is resolved at pipeline upload time, whereas `$$VARIABLE_NAME` will be at run time. All things being equal, you likely want to use `$$VARIABLE_NAME` on the variables mentioned in this option. -### `graceful-shutdown` (optional, run only) +#### `graceful-shutdown` (run only, boolean) Gracefully shuts down all containers via 'docker-compose stop`. The default is `false`. -### `leave-volumes` (optional, run only) +#### `leave-volumes` (run only, boolean) Prevent the removal of volumes after the command has been run. The default is `false`. -### `no-cache` (optional, build and run only) +#### `no-cache` (build and run only, boolean) -Build with `--no-cache`, causing Docker Compose to not use any caches when building the image. +Build with `--no-cache`, causing Docker Compose to not use any caches when building the image. This will also avoid creating an override with any `cache-from` entries. The default is `false`. -### `build-parallel` (optional, build and run only) +#### `build-parallel` (build only, boolean) Build with `--parallel`, causing Docker Compose to run builds in parallel. Requires docker-compose `1.23+`. The default is `false`. -### `tty` (optional, run only) +#### `tty` (run only, boolean) If set to true, allocates a TTY. This is useful in some situations TTYs are required. The default is `false`. -### `dependencies` (optional, run only) +#### `dependencies` (run only, boolean) If set to false, runs with `--no-deps` and doesn't start linked services. The default is `true`. -### `pre-run-dependencies` (optional, run only) +#### `pre-run-dependencies` (run only, boolean) If `dependencies` are activated (which is the default), you can skip starting them up before the main container by setting this option to `false`. This is useful if you want compose to take care of that on its own at the expense of messier output in the run step. -### `wait` (optional, run only) +#### `wait` (run only, boolean) Whether to wait for dependencies to be up (and healthy if possible) when starting them up. It translates to using [`--wait` in the docker-compose up] command. Defaults to `false`. -### `ansi` (optional, run only) +#### `ansi` (run only, boolean) If set to false, disables the ansi output from containers. The default is `true`. -### `use-aliases` (optional, run only) +#### `use-aliases` (run only, boolean) If set to true, docker compose will use the service's network aliases in the network(s) the container connects to. The default is `false`. -### `verbose` (optional) +#### `verbose` (boolean) Sets `docker-compose` to run with `--verbose` The default is `false`. -### `quiet-pull` (optional, run only) +#### `quiet-pull` (run only, boolean) Start up dependencies with `--quiet-pull` to prevent even more logs during that portion of the execution. The default is `false`. -### `rm` (optional, run only) +#### `rm` (run only, boolean) If set to true, docker compose will remove the primary container after run. Equivalent to `--rm` in docker-compose. The default is `true`. -### `run-labels` (optional, run only) +#### `run-labels` (run only, boolean) If set to true, adds useful Docker labels to the primary container. See [Container Labels](#container-labels) for more info. The default is `true`. -### `compatibility` (optional, run only) +#### `compatibility` (boolean) -If set to true, all docker compose commands will rum with compatibility mode. Equivalent to `--compatibility` in docker-compose. +If set to true, all docker compose commands will rum with compatibility mode. Equivalent to `--compatibility` in docker compose. The default is `false`. @@ -584,17 +266,17 @@ Note that [the effect of this option changes depending on your docker compose CL - [Character separator for container names](https://github.com/docker/compose/blob/a0acc20d883ce22b8b0c65786e3bea1328809bbd/cmd/compose/compose.go#L181) - [Not normalizing compose models (when running `config`)](https://github.com/docker/compose/blob/2e7644ff21f9ca0ea6fb5e8d41d4f6af32cd7e20/cmd/compose/convert.go#L69) -### `entrypoint` (optional, run only) +#### `entrypoint` (run only) -Sets the `--entrypoint` argument when running `docker-compose`. +Sets the `--entrypoint` argument when running `docker compose`. -### `service-ports` (optional, run only) +#### `service-ports` (run only, boolean) If set to true, docker compose will run with the service ports enabled and mapped to the host. Equivalent to `--service-ports` in docker-compose. The default is `false`. -### `upload-container-logs` (optional, run only) +#### `upload-container-logs` (run only) Select when to upload container logs. @@ -604,21 +286,21 @@ Select when to upload container logs. The default is `on-error`. -### `cli-version` (optional, string or integer) +#### `cli-version` (string or integer) -If set to `2`, plugin will use `docker compose` to execute commands; otherwise it will default to version `1`, using `docker-compose` instead. +If set to `1`, plugin will use `docker-compose` (that is deprecated and unsupported) to execute commands; otherwise it will default to version `2`, using `docker compose` instead. -### `buildkit` (optional, build only, boolean) +#### `buildkit` (build only, boolean) -Assuming you have a compatible docker installation and configuration in the agent, activating this option would setup the environment for the `docker-compose build` call to use BuildKit. Note that if you are using `cli-version` 2, you are already using buildkit by default. +Assuming you have a compatible docker installation and configuration in the agent, activating this option would setup the environment for the `docker compose build` call to use BuildKit. Note that this should only be necessary if you are using `cli-version` 1 (version 2 already uses buildkit by default). You may want to also add `BUILDKIT_INLINE_CACHE=1` to your build arguments (`args` option in this plugin), but know that [there are known issues with it](https://github.com/moby/buildkit/issues/2274). -### `ssh` (optional, build only, boolean or string) +#### `ssh` (build only, boolean or string) It will add the `--ssh` option to the build command with the passed value (if `true` it will use `default`). Note that it assumes you have a compatible docker installation and configuration in the agent (meaning you are using BuildKit and it is correctly setup). -### `secrets` (optional, build only, array of strings) +#### `secrets` (build only, array of strings) All elements in this array will be passed literally to the `build` command as parameters of the [`--secrets` option](https://docs.docker.com/engine/reference/commandline/buildx_build/#secret). Note that you must have BuildKit enabled for this option to have any effect and special `RUN` stanzas in your Dockerfile to actually make use of them. @@ -627,7 +309,7 @@ All elements in this array will be passed literally to the `build` command as pa To run the tests: ```bash -docker-compose run --rm tests bats tests tests/v2 +docker-compose run --rm tests bats tests tests/v1 ``` ## License diff --git a/commands/build.sh b/commands/build.sh index f051f68e..6da04b0c 100755 --- a/commands/build.sh +++ b/commands/build.sh @@ -11,7 +11,7 @@ else group_type="+++" fi -if [[ "$(plugin_read_config BUILDKIT "false")" == "true" ]]; then +if [[ "$(plugin_read_config BUILDKIT "true")" == "true" ]]; then export DOCKER_BUILDKIT=1 export COMPOSE_DOCKER_CLI_BUILD=1 export BUILDKIT_PROGRESS=plain @@ -95,7 +95,7 @@ while read -r line ; do done <<< "$(plugin_read_list SECRETS)" if [[ "$(plugin_read_config SSH "false")" != "false" ]] ; then - if [[ "${DOCKER_BUILDKIT:-}" != "1" && "${BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION:-}" != "2" ]]; then + if [[ "${DOCKER_BUILDKIT:-}" != "1" && "${BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION:-2}" != "2" ]]; then echo "🚨 You can not use the ssh option if you are not using buildkit" exit 1 fi diff --git a/docs/examples.md b/docs/examples.md new file mode 100644 index 00000000..6b047629 --- /dev/null +++ b/docs/examples.md @@ -0,0 +1,294 @@ +# Examples + +This is a collection of snippets showing some common use-cases for the plugin and its caveats. + +### Simple run + +The following pipeline will run `test.sh` inside a `app` service container using Docker Compose, the equivalent to running `docker-compose run app test.sh`: + +```yml +steps: + - command: test.sh + plugins: + - docker-compose#v5.0.0: + run: app +``` + +:warning: Warning: you should not use this plugin with an array of commands at the step level. Execute a script in your repository, a single command separated by `;` or the plugin's [`command` option](#command-run-only-array) instead: + +```yml +steps: + - plugins: + - docker-compose#v5.0.0: + run: app + command: ["custom", "command", "values"] +``` + +The plugin will honor the value of the `COMPOSE_FILE` environment variable if one exists (for example, at the pipeline or step level). But you can also specify custom Docker Compose config files with the `config` option: + +```yml +steps: + - command: test.sh + plugins: + - docker-compose#v5.0.0: + run: app + config: docker-compose.tests.yml + env: + - BUILDKITE_BUILD_NUMBER +``` + +### Authenticated registries + +You can leverage the [docker-login plugin](https://github.com/buildkite-plugins/docker-login-buildkite-plugin) in tandem for authenticating with a registry. For example, the following will build and push an image to a private repo, and pull from that private repo in subsequent run commands: + +```yml +steps: + - plugins: + - docker-login#v2.0.1: + username: xyz + - docker-compose#v5.0.0: + build: app + push: app:index.docker.io/myorg/myrepo:tag + - wait + - command: test.sh + plugins: + - docker-login#v2.0.1: + username: xyz + - docker-compose#v5.0.0: + run: app +``` + +Note, you will need to add the configuration to all steps in which you use this plugin. + +### Artifacts + +If you’re generating artifacts in the build step, you’ll need to ensure your Docker Compose configuration volume mounts the host machine directory into the container where those artifacts are created. + +For example, if your `app` service generates information that you want as artifacts in the `/folder/dist` folder, you would need to ensure the `app` service in your Docker Compose config has a host volume mount defined as `./dist:/folder/dist` or specify it in the plugin's configuration: + +```yml +steps: + - command: generate-dist.sh + artifact_paths: "dist/*" + plugins: + - docker-compose#v5.0.0: + run: app + volumes: + - "./dist:/folder/dist" +``` + +If you want to use environment variables in the `volumes` element, you will need to activate the (unsafe) option `expand-volume-vars` (and most likely escape it using `$$VARIABLE_NAME` to ensure they are not interpolated when the pipeline is uploaded). + +### Environment + +By default, docker-compose makes whatever environment variables it gets available for +interpolation of docker-compose.yml, but it doesn't pass them in to your containers. + +You can use the [environment key in docker-compose.yml](https://docs.docker.com/compose/environment-variables/) to either set specific environment vars or "pass through" environment variables from outside docker-compose. + +### Specific values + +If you want to add extra environment above what is declared in your `docker-compose.yml`, +this plugin offers a `environment` block of its own: + +```yml +steps: + - command: generate-dist.sh + plugins: + - docker-compose#v5.0.0: + run: app + env: + - BUILDKITE_BUILD_NUMBER + - BUILDKITE_PULL_REQUEST + - MY_CUSTOM_ENV=llamas +``` + +Note how the values in the list can either be just a key (so the value is sourced from the environment) or a KEY=VALUE pair. + +### Pipeline variables + +Alternatively, you can have the plugin add all environment variables defined for the job by the agent as defined in [`BUILDKITE_ENV_FILE`](https://buildkite.com/docs/pipelines/environment-variables#BUILDKITE_ENV_FILE) activating the `propagate-environment` option: + +```yml +steps: + - command: use-vars.sh + plugins: + - docker-compose#v5.0.0: + run: app + propagate-environment: true +``` + +### Container Labels + +When running a command, the plugin will automatically add the following Docker labels to the container specified in the `run` option: +- `com.buildkite.pipeline_name=${BUILDKITE_PIPELINE_NAME}` +- `com.buildkite.pipeline_slug=${BUILDKITE_PIPELINE_SLUG}` +- `com.buildkite.build_number=${BUILDKITE_BUILD_NUMBER}` +- `com.buildkite.job_id=${BUILDKITE_JOB_ID}` +- `com.buildkite.job_label=${BUILDKITE_LABEL}` +- `com.buildkite.step_key=${BUILDKITE_STEP_KEY}` +- `com.buildkite.agent_name=${BUILDKITE_AGENT_NAME}` +- `com.buildkite.agent_id=${BUILDKITE_AGENT_ID}` + +These labels can make it easier to query containers on hosts using `docker ps` for example: + +```bash +docker ps --filter "label=com.buildkite.job_label=Run tests" +``` + +This behaviour can be disabled with the `run-labels: false` option. + +### Build Arguments + +You can use the [build args key in docker-compose.yml](https://docs.docker.com/compose/compose-file/build/#args) to set specific build arguments when building an image. + +Alternatively, if you want to set build arguments when pre-building an image, this plugin offers an `args` block of its own: + +```yml +steps: + - command: generate-dist.sh + plugins: + - docker-compose#v5.0.0: + build: app + args: + - MY_CUSTOM_ARG=panda + push: app +``` + +Note that the values in the list must be a `KEY=VALUE` pair. + +### Pre-building the image + +If you have multiple steps that use the same service/image (such as steps that run in parallel), you can use this plugin in a specific `build` step to your pipeline. That will set specific metadata in the pipeline for this plugin to use in `run` steps afterwards: + +```yml +steps: + - label: ":docker: Build" + plugins: + - docker-compose#v5.0.0: + build: app + push: app + + - wait + + - label: ":docker: Test %n" + command: test.sh + parallelism: 25 + plugins: + - docker-compose#v5.0.0: + run: app +``` + +All `run` steps for the service `app` will automatically pull and use the pre-built image. Without this, each `Test %n` job would build its own instead. + +### Building multiple images + +Sometimes your compose file has multiple services that need building. The example below will build images for the `app` and `tests` service and then the run step will pull them down and use them for the run as needed. + +```yml +steps: + - label: ":docker: Build" + agents: + queue: docker-builder + plugins: + - docker-compose#v5.0.0: + build: + - app + - tests + push: + - app + - tests + + - wait + + - label: ":docker: Test %n" + command: test.sh + parallelism: 25 + plugins: + - docker-compose#v5.0.0: + run: tests +``` + +### Pushing Tagged Images + +If you want to push your Docker images ready for deployment, you can use the `push` configuration (which operates similar to [docker-compose push](https://docs.docker.com/compose/reference/push/): + +```yml +steps: + - label: ":docker: Push" + plugins: + - docker-compose#v5.0.0: + push: app +``` + +To push multiple images, you can use a list: + +```yml +steps: + - label: ":docker: Push" + plugins: + - docker-compose#v5.0.0: + push: + - first-service + - second-service +``` + +If you want to push to a specific location (that's not defined as the `image` in your docker-compose.yml), you can use the `{service}:{repo}:{tag}` format, for example: + +```yml +steps: + - label: ":docker: Push" + plugins: + - docker-compose#v5.0.0: + push: + - app:index.docker.io/myorg/myrepo/myapp + - app:index.docker.io/myorg/myrepo/myapp:latest +``` + +### Reusing caches from images + +A newly spawned agent won't contain any of the docker caches for the first run which will result in a long build step. To mitigate this you can reuse caches from a previously built image (if it was pushed from a previous build): + +```yaml +steps: + - label: ":docker Build an image" + plugins: + - docker-compose#v5.0.0: + build: app + push: app:index.docker.io/myorg/myrepo:my-branch + cache-from: + - "app:myregistry:port/myrepo/myapp:my-branch" + - "app:myregistry:port/myrepo/myapp:latest" + + - wait + + - label: ":docker: Push to final repository" + plugins: + - docker-compose#v5.0.0: + push: + - app:myregistry:port/myrepo/myapp:latest +``` + +For images to be pulled and used as a cache they [need to be built with the `BUILDKIT_INLINE_CACHE=1` build argument](https://docs.docker.com/engine/reference/commandline/build/#cache-from). + +The values you add in the `cache-from` will be mapped to the corresponding service's configuration. That means that you can use any valid cache type your environment supports: + +```yaml +steps: + - label: ":docker Build an image" + plugins: + - docker-compose#v5.0.0: + build: app + push: app:index.docker.io/myorg/myrepo:my-branch + cache-from: + - "app:type=registry,ref=myregistry:port/myrepo/myapp:my-branch" + - "app:myregistry:port/myrepo/myapp:latest" + + - wait + + - label: ":docker: Push to final repository" + plugins: + - docker-compose#v5.0.0: + push: + - app:myregistry:port/myrepo/myapp:latest +``` diff --git a/docs/upgrading-to-v5.md b/docs/upgrading-to-v5.md new file mode 100644 index 00000000..3857d17b --- /dev/null +++ b/docs/upgrading-to-v5.md @@ -0,0 +1,69 @@ +# Upgrading to v5 + +Version 5.0.0 of this plugin introduced a lot of backwards-incompatible changes. This should help you review and provide you with actionable steps for you to upgrade. + +## Summary + +This is an overview of behaviour changes that may break your existing pipelines. + +* CLI v2 is now the default +* usage of buildkit is turned on by default +* `run` and `push` steps will not do a build if there is no image +* `build` steps will not push the image +* `image-registry` and `image-name` are no longer necessary +* pipeline meta-data used to share pre-built image information is set on `push` instead of `build` +* TTY allocation is turned off by default when running +* `collapse-run-log-groups` is now `collapse-logs` and applies to all stages (run, push and build) +* `cache-from` now is of the form: `SERVICE:CACHE_FROM_SPEC` and supports any cache type and specification supported by your underlying docker engine +* elements in `cache-from` will not be pulled, docker compose's cache will pull what/if necessary (inline cache is needed on images pushed) +* `separator-cache-from` is no longer necessary +* tags (if present) on `cache-from` or `push` options are no longer validated +* a service that has an `image` configuration will take precedence over pre-built image metadata + +Other minor fixes +* `target` option implementation has been fixed +* compose override files will only be created when: + - `target` option is used on `build` steps + - `cache-from` option is used on `build` steps + - a pre-built image is found on `push` or `run` steps +* when steps finish, override files will be deleted + +## `cache-from` (and `separator-cache-from`) + +The only accepted format now for this configuration is `:`. This means that you need to review the values if you: + +* used groups +* used the `separator-cache-from` option +* depend heavily on images being pulled for building + +This simplification means that all caching is now reliant on [docker's underlying `cache-from` implementation](https://docs.docker.com/engine/reference/commandline/build/#cache-from). Values can be any accepted format on that option which should provide with a lot more flexibility and resiliency. + +### Troubleshooting + +The plugin should print out the override file used in the step's logs for you to review and try to duplicate the behaviour in your local docker environment. + +As per the documentation, the images you want to use as cache must have been built with the `BUILDKIT_INLINE_CACHE=1` build argument. Otherwise, the manifest used by docker to determine if the image contains layers that could be useful to pull will not be present and will not be used. + +Note that docker silently ignores any `cache-from` configuration that is not valid or can not be used. + +## `image-repository` and/or `image-name` + +These options were used to push images in `build` steps. + +You need to: +* delete these options +* add a `push` or `run` on the very same step + +## `cli-version` + +If you were using this option to ensure that `docker compose` was used, you should be able to remove it safely. On the other hand, if your build environment only has the old v1 CLI interface (`docker-compose`), you will need to make some changes. + +**IMPORTANT**: Compose V1 has been [deprecated since July 2023](https://docs.docker.com/compose/migrate/), please consider upgrading. + +The easiest way to make the change would be to add an environment hook in your agent that defines the variable `BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1`. This way, not only you will not need to make any changes to all your pipelines, but also you can test out the same pipelines when you are ready to upgrade to agents that do have CLI v2 available with no further changes. + +Alternatively, you can add the same variable definition to your pipeline as a global environment variable instead of adding the option to each and every step. + +## `collapse-run-log-groups` + +Just rename the option to `collapse-logs` \ No newline at end of file diff --git a/lib/push.bash b/lib/push.bash index 1025c974..cfa33720 100644 --- a/lib/push.bash +++ b/lib/push.bash @@ -21,9 +21,9 @@ compose_image_for_service() { default_compose_image_for_service() { local service="$1" - local separator="_" - if [[ "$(plugin_read_config CLI_VERSION "1")" == "2" ]] && [[ "$(plugin_read_config COMPATIBILITY "false")" != "true" ]] ; then - separator="-" + local separator="-" + if [[ "$(plugin_read_config CLI_VERSION "2")" == "1" ]] || [[ "$(plugin_read_config COMPATIBILITY "false")" == "true" ]] ; then + separator="_" fi printf '%s%s%s\n' "$(docker_compose_project_name)" "$separator" "$service" diff --git a/lib/shared.bash b/lib/shared.bash index 01e34dcd..b6f679de 100644 --- a/lib/shared.bash +++ b/lib/shared.bash @@ -207,7 +207,7 @@ function build_image_override_file_with_version() { # Runs the docker-compose command, scoped to the project, with the given arguments function run_docker_compose() { local command=(docker-compose) - if [[ "$(plugin_read_config CLI_VERSION "1")" == "2" ]] ; then + if [[ "$(plugin_read_config CLI_VERSION "2")" == "2" ]] ; then command=(docker compose) fi diff --git a/plugin.yml b/plugin.yml index f4db4cf9..ede4255f 100644 --- a/plugin.yml +++ b/plugin.yml @@ -14,6 +14,7 @@ configuration: push: type: [ string, array ] minimum: 1 + ansi: type: boolean args: @@ -22,22 +23,24 @@ configuration: build-alias: type: [ string, array ] minimum: 1 + build-parallel: + type: boolean buildkit: type: boolean cache-from: type: [ string, array ] minimum: 1 - compatibility: - type: boolean cli-version: oneOf: - type: string enum: [ "1", "2" ] - type: integer enum: [ 1, 2 ] + collapse-logs: + type: boolean command: type: array - collapse-logs: + compatibility: type: boolean config: type: [ string, array ] @@ -56,6 +59,8 @@ configuration: type: string expand-volume-vars: type: boolean + graceful-shutdown: + type: boolean leave-volumes: type: boolean mount-buildkite-agent: @@ -85,31 +90,38 @@ configuration: type: boolean run-labels: type: boolean + secrets: + type: array + items: + type: string service-ports: type: boolean + shell: + type: [ boolean, array ] skip-checkout: type: boolean skip-pull: type: boolean ssh: type: [ boolean, string ] - secrets: - type: array - items: - type: string target: type: string tty: type: boolean upload-container-logs: type: string + enum: [ "always", "never", "on-error" ] use-aliases: type: boolean + user: + type: string verbose: type: boolean volumes: type: [ string, array ] minimum: 1 + wait: + type: boolean workdir: type: string anyOf: @@ -122,26 +134,41 @@ configuration: additionalProperties: false dependencies: ansi: [ run ] + args: [ build ] + build-alias: [ push ] + build-parallel: [ build ] buildkit: [ build ] cache-from: [ build ] + command: [ run ] dependencies: [ run ] + entrypoint: [ run ] env: [ run ] + env-propagation-list: [ run ] environment: [ run ] expand-volume-vars: [ volumes ] + graceful-shutdown: [ run ] leave-volumes: [ run ] mount-buildkite-agent: [ run ] mount-checkout: [ run ] + mount-ssh-agent: [ run ] + no-cache: [ build, run ] pre-run-dependencies: [ run ] + propagate-environment: [ run ] propagate-uid-gid: [ run ] pull: [ run ] + pull-retries: [ run ] push-retries: [ push ] quiet-pull: [ run ] + rm: [ run ] + run-labels: [ run ] service-ports: [ run ] skip-pull: [ build, run ] secrets: [ buildkit, build ] - ssh: [ buildkit ] + shell: [ run ] + ssh: [ build ] target: [ build ] tty: [ run ] + upload-container-logs: [ run ] use-aliases: [ run ] user: [ run ] volumes: [ run ] diff --git a/tests/build.bats b/tests/build.bats index a16dffcf..00d8a3e1 100644 --- a/tests/build.bats +++ b/tests/build.bats @@ -17,15 +17,15 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker-compose + unstub docker } @test "Build with no-cache" { @@ -35,14 +35,15 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull --no-cache myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --no-cache myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker-compose + + unstub docker } @test "Build with parallel" { @@ -52,14 +53,15 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull --parallel myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --parallel myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker-compose + + unstub docker } @test "Build with build args" { @@ -70,52 +72,19 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_0=MYARG=0 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_1=MYARG=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker-compose -} - -@test "Build with docker-compose and v1 is set explicitly " { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" - run "$PWD"/hooks/command - - assert_success - assert_output --partial "built myservice" - unstub docker-compose + unstub docker } -@test "Build with a repository" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "built myservice" - - unstub docker-compose -} - -# TODO: move this to push testing @test "Build with a repository and multiple build aliases" { + skip 'move to push' export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_ALIAS_0=myservice-1 @@ -123,106 +92,30 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "built myservice" - - unstub docker-compose -} - -@test "Build with a repository and push retries" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_RETRIES=3 - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker-compose + unstub docker } -@test "Build with a repository and custom config file" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG=tests/composefiles/docker-compose.v2.0.yml - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - - stub docker-compose \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 build --pull myservice : echo built myservice" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "built myservice" - - unstub docker-compose -} - -@test "Build with a repository and multiple custom config files" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG_0=tests/composefiles/docker-compose.v2.0.yml - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG_1=tests/composefiles/docker-compose.v2.1.yml - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - - stub docker-compose \ - "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 build --pull myservice : echo built myservice" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "built myservice" - - unstub docker-compose -} - -@test "Build with a repository and multiple services" { - export BUILDKITE_JOB_ID=1112 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=myservice1 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_1=myservice2 - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1112 build --pull myservice1 myservice2 : echo built all services" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "built all services" - - unstub docker-compose -} - -@test "Build with a docker-compose v1.0 configuration file" { +@test "Build with an override file and docker-compose v1.0 configuration file" { export BUILDKITE_JOB_ID=1112 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v1.0.yml" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache:latest export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v1.0.yml -p buildkite1112 build --pull helloworld : echo built service" - run "$PWD"/hooks/command - assert_success - assert_output --partial "built service" - - unstub docker-compose + assert_failure + assert_output --partial "versions 2.0 and above" + refute_output --partial "built service" } @test "Build with a cache-from image" { @@ -233,8 +126,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command @@ -242,7 +135,7 @@ teardown() { assert_output --partial "- my.repository/myservice_cache:latest" assert_output --partial "built helloworld" - unstub docker-compose + unstub docker } @test "Build with a cache-from image with no-cache also set" { @@ -254,15 +147,16 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 build --pull --no-cache helloworld : echo built helloworld" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 build --pull --no-cache helloworld : echo built helloworld" run "$PWD"/hooks/command assert_success refute_output --partial "- my.repository/myservice_cache:latest" assert_output --partial "built helloworld" - unstub docker-compose + + unstub docker } @test "Build with an invalid cache-from tag" { @@ -273,16 +167,17 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command assert_success + refute_output --partial "pulled cache image" assert_output --partial "- my.repository/myservice_cache:-latest" assert_output --partial "built helloworld" - unstub docker-compose + unstub docker } @test "Build with a cache-from image with no tag" { @@ -294,8 +189,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command @@ -303,7 +198,7 @@ teardown() { assert_output --partial "- my.repository/myservice_cache" assert_output --partial "built helloworld" - unstub docker-compose + unstub docker } @test "Build with several cache-from images for one service" { @@ -315,8 +210,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command @@ -325,7 +220,7 @@ teardown() { assert_output --partial "- my.repository/myservice_cache:latest" assert_output --partial "built helloworld" - unstub docker-compose + unstub docker } @test "Build with a cache-from image with hyphen" { @@ -336,8 +231,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull hello-world : echo built hello-world" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull hello-world : echo built hello-world" run "$PWD"/hooks/command @@ -345,7 +240,7 @@ teardown() { assert_output --partial "- my.repository/my-service_cache:latest" assert_output --partial "built hello-world" - unstub docker-compose + unstub docker } @test "Build with a service name and cache-from with period" { @@ -356,8 +251,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \$9" + stub docker \ + "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${10}}" run "$PWD"/hooks/command @@ -365,7 +260,7 @@ teardown() { assert_output --partial "- my.repository/my-service_cache:latest" assert_output --partial "built hello.world" - unstub docker-compose + unstub docker } @test "Build with target" { @@ -376,8 +271,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TARGET=intermediate - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${9}" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${10}" run "$PWD"/hooks/command @@ -385,7 +280,7 @@ teardown() { assert_output --partial "built myservice" assert_output --partial " target: intermediate" - unstub docker-compose + unstub docker } @test "Build with ssh option (but no buildkit)" { @@ -395,12 +290,18 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SSH=true + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT=false + + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --ssh default \* : echo built \${10} with ssh" run "$PWD"/hooks/command - assert_failure - assert_output --partial "You can not use the ssh option if you are not using buildkit" - refute_output --partial "built myservice" + assert_success + assert_output --partial "built myservice" + assert_output --partial "with ssh" + + unstub docker } @test "Build with ssh option as true and buildkit" { @@ -412,8 +313,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SSH=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull --ssh default \* : echo built \${9} with ssh" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --ssh default \* : echo built \${10} with ssh" run "$PWD"/hooks/command @@ -421,7 +322,7 @@ teardown() { assert_output --partial "built myservice" assert_output --partial "with ssh" - unstub docker-compose + unstub docker } @test "Build with ssh option as string and buildkit" { @@ -433,8 +334,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SSH=context - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull --ssh context \* : echo built \${9} with ssh" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --ssh context \* : echo built \${10} with ssh" run "$PWD"/hooks/command @@ -442,7 +343,7 @@ teardown() { assert_output --partial "built myservice" assert_output --partial "with ssh" - unstub docker-compose + unstub docker } @test "Build with secrets" { @@ -454,8 +355,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SECRETS_0='id=test,file=~/.test' export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SECRETS_1='id=SECRET_VAR' - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build --pull --secret \* --secret \* \* : echo built \${11} with secrets \${8} and \${10}" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build --pull --secret \* --secret \* \* : echo built \${12} with secrets \${9} and \${11}" run "$PWD"/hooks/command @@ -463,7 +364,7 @@ teardown() { assert_output --partial "built myservice" assert_output --partial "with secrets id=test,file=~/.test and id=SECRET_VAR" - unstub docker-compose + unstub docker } @test "Build without pull" { @@ -473,12 +374,13 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 build myservice : echo built myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 build myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker-compose + + unstub docker } diff --git a/tests/cleanup.bats b/tests/cleanup.bats index adb69f18..77d55bb1 100644 --- a/tests/cleanup.bats +++ b/tests/cleanup.bats @@ -16,14 +16,15 @@ load '../lib/run' export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 kill : echo killing containers" \ - "-f docker-compose.yml -p buildkite1111 rm --force -v : echo removing stopped containers" \ - "-f docker-compose.yml -p buildkite1111 down --remove-orphans --volumes : echo removing everything" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 kill : echo killing containers" \ + "compose -f docker-compose.yml -p buildkite1111 rm --force -v : echo removing stopped containers" \ + "compose -f docker-compose.yml -p buildkite1111 down --remove-orphans --volumes : echo removing everything" run "$PWD"/hooks/pre-exit assert_success assert_output --partial "Cleaning up after docker-compose" - unstub docker-compose + + unstub docker } diff --git a/tests/docker-compose-images.bats b/tests/docker-compose-images.bats index 39d3da1e..13f7bde3 100644 --- a/tests/docker-compose-images.bats +++ b/tests/docker-compose-images.bats @@ -12,57 +12,56 @@ setup() { } @test "Image for compose service with an image in config" { - stub docker-compose \ - "-f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" + stub docker \ + "compose -f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" run compose_image_for_service "app" assert_success assert_output "somewhere.dkr.ecr.some-region.amazonaws.com/blah" - unstub docker-compose + unstub docker } @test "Image for compose service with a service with hyphens in the name" { - stub docker-compose \ - "-f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.with.hyphens.yml" + stub docker \ + "compose -f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.with.hyphens.yml" run compose_image_for_service "foo-db" assert_success assert_output "postgres:9.4" - unstub docker-compose + unstub docker } @test "Image for compose service without an image in config" { - stub docker-compose \ - "-f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" + stub docker \ + "compose -f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" run compose_image_for_service "helper" assert_success - assert_output "buildkite_helper" + assert_output "buildkite-helper" - unstub docker-compose + unstub docker } -@test "Image for compose v2 service without an image in config" { - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=2 +@test "Image for compose v1 service without an image in config" { + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" + stub docker-compose \ + "-f docker-compose.yml -p buildkite config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" run compose_image_for_service "helper" assert_success - assert_output "buildkite-helper" + assert_output "buildkite_helper" - unstub docker + unstub docker-compose } -@test "Image for compose v2 service without an image in config using compatibility" { - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=2 +@test "Image for compose service without an image in config using compatibility" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true stub docker \ @@ -76,7 +75,8 @@ setup() { unstub docker } -@test "Image for compose service without an image in config using compatibility" { +@test "Image for compose v1 service without an image in config using compatibility" { + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true stub docker-compose \ diff --git a/tests/docker-compose-verbosity.bats b/tests/docker-compose-verbosity.bats index 75cb1769..1eae9b1c 100644 --- a/tests/docker-compose-verbosity.bats +++ b/tests/docker-compose-verbosity.bats @@ -7,38 +7,41 @@ load '../lib/run' # export DOCKER_COMPOSE_STUB_DEBUG=/dev/tty @test "docker-compose verbosity config unset" { - stub docker-compose \ - "-f docker-compose.yml -p buildkite run tests : echo ran without verbose flag" + stub docker \ + "compose -f docker-compose.yml -p buildkite run tests : echo ran without verbose flag" run run_docker_compose run tests assert_success assert_output --partial "ran without verbose flag" - unstub docker-compose + + unstub docker } @test "docker-compose verbosity config set to 'true'" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VERBOSE="true" - stub docker-compose \ - "--verbose -f docker-compose.yml -p buildkite run tests : echo ran with verbose flag" + stub docker \ + "compose --verbose -f docker-compose.yml -p buildkite run tests : echo ran with verbose flag" run run_docker_compose run tests assert_success assert_output --partial "ran with verbose flag" - unstub docker-compose + + unstub docker } @test "docker-compose verbosity config set to 'false'" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VERBOSE="false" - stub docker-compose \ - "-f docker-compose.yml -p buildkite run tests : echo ran without verbose flag" + stub docker \ + "compose -f docker-compose.yml -p buildkite run tests : echo ran without verbose flag" run run_docker_compose run tests assert_success assert_output --partial "ran without verbose flag" - unstub docker-compose + + unstub docker } diff --git a/tests/multiple-commands.bats b/tests/multiple-commands.bats index 3755bc2c..7295220b 100644 --- a/tests/multiple-commands.bats +++ b/tests/multiple-commands.bats @@ -5,7 +5,6 @@ load '../lib/shared' load '../lib/metadata' # export DOCKER_STUB_DEBUG=/dev/tty -# export DOCKER_COMPOSE_STUB_DEBUG=/dev/tty # export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty # export BATS_MOCK_TMPDIR=$PWD @@ -30,10 +29,10 @@ teardown() { # necessary for build export BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_REPOSITORY=my.repository/llamas - stub docker-compose \ - "-f docker-compose.yml -p buildkite12 build --pull myservice : echo built myservice" \ - "-f docker-compose.yml -p buildkite12 up -d --scale myservice=0 myservice : echo ran dependencies" \ - "-f docker-compose.yml -p buildkite12 run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite12 build --pull myservice : echo built myservice" \ + "compose -f docker-compose.yml -p buildkite12 up -d --scale myservice=0 myservice : echo ran dependencies" \ + "compose -f docker-compose.yml -p buildkite12 run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : test -f /tmp/build-run-metadata" @@ -45,7 +44,7 @@ teardown() { assert_output --partial "Starting dependencies" assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -53,31 +52,25 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice - # necessary for build - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_IMAGE_REPOSITORY=my.repository/llamas + stub docker \ + "compose -f docker-compose.yml -p buildkite12 build --pull myservice : echo built myservice" \ + "compose -f docker-compose.yml -p buildkite12 config : echo ''" \ + "image inspect \* : echo existing-image" \ + "compose -f docker-compose.yml -p buildkite12 push myservice : echo pushed myservice" - stub docker-compose \ - "-f docker-compose.yml -p buildkite12 build --pull myservice : echo built myservice" \ - "-f docker-compose.yml -p buildkite12 config : echo ''" \ - "-f docker-compose.yml -p buildkite12 push myservice : echo pushed myservice" - # these commands simulate metadata for a specific value by using an intermediate-file stub buildkite-agent \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4 > /tmp/build-push-metadata" - - stub docker \ - "image inspect buildkite12_myservice : echo existing-image" + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4 > /tmp/build-push-metadata" run "$PWD"/hooks/command assert_success assert_output --partial "Building services myservice" - assert_output --partial "Using service image buildkite12_myservice from Docker Compose config" + assert_output --partial "Using service image buildkite12-myservice from Docker Compose config" assert_output --partial "Pushing images for myservice" unstub docker - unstub docker-compose unstub buildkite-agent } @@ -85,10 +78,11 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice - stub docker-compose \ - "-f docker-compose.yml -p buildkite12 up -d --scale myservice=0 myservice : echo ran dependencies" \ - "-f docker-compose.yml -p buildkite12 run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" \ - "-f docker-compose.yml -p buildkite12 config : echo ''" + stub docker \ + "compose -f docker-compose.yml -p buildkite12 up -d --scale myservice=0 myservice : echo ran dependencies" \ + "compose -f docker-compose.yml -p buildkite12 run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" \ + "compose -f docker-compose.yml -p buildkite12 config : echo ''" \ + "image inspect \* : exit 1" # these make sure that the image is not pre-built stub buildkite-agent \ @@ -104,7 +98,7 @@ teardown() { assert_output --partial "ran myservice" assert_output --partial "No prebuilt-image nor service image found for service to push" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -112,14 +106,12 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice - stub docker-compose \ - "-f docker-compose.yml -p buildkite12 up -d --scale myservice=0 myservice : echo ran dependencies" \ - "-f docker-compose.yml -p buildkite12 run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" \ - "-f docker-compose.yml -p buildkite12 config : echo ''" \ - "-f docker-compose.yml -p buildkite12 push myservice : echo pushed myservice" - stub docker \ - "image inspect \* : echo found image \$3" + "compose -f docker-compose.yml -p buildkite12 up -d --scale myservice=0 myservice : echo ran dependencies" \ + "compose -f docker-compose.yml -p buildkite12 run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" \ + "compose -f docker-compose.yml -p buildkite12 config : echo ''" \ + "image inspect \* : echo found image \$3" \ + "compose -f docker-compose.yml -p buildkite12 push myservice : echo pushed myservice" # these make sure that the image is not pre-built stub buildkite-agent \ @@ -136,7 +128,6 @@ teardown() { assert_output --partial "Using service image" unstub docker - unstub docker-compose unstub buildkite-agent } @@ -144,12 +135,14 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice - stub docker-compose \ - "-f docker-compose.yml -p buildkite12 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite12 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran dependencies" \ - "-f docker-compose.yml -p buildkite12 -f docker-compose.buildkite-1-override.yml run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" \ - "-f docker-compose.yml -p buildkite12 config : echo ''" \ - "-f docker-compose.yml -p buildkite12 push myservice : echo pushed myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite12 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite12 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran dependencies" \ + "compose -f docker-compose.yml -p buildkite12 -f docker-compose.buildkite-1-override.yml run --name buildkite12_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" \ + "compose -f docker-compose.yml -p buildkite12 config : echo ''" \ + "image inspect \* : exit 1" \ + "pull myservice-tag : echo pulled pre-built image" \ + "compose -f docker-compose.yml -p buildkite12 push myservice : echo pushed myservice" # these make sure that the image is not pre-built stub buildkite-agent \ @@ -159,10 +152,6 @@ teardown() { "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myservice-tag" \ "meta-data set docker-compose-plugin-built-image-tag-myservice \* : set pre-built image metadata to \$4" - stub docker \ - "image inspect buildkite12_myservice : exit 1" \ - "pull myservice-tag : echo pulled pre-built image" - run "$PWD"/hooks/command assert_success @@ -175,6 +164,5 @@ teardown() { assert_output --partial "Pushing images for myservice" unstub docker - unstub docker-compose unstub buildkite-agent } diff --git a/tests/output.bats b/tests/output.bats index 7bf411f4..9b5a255a 100644 --- a/tests/output.bats +++ b/tests/output.bats @@ -30,11 +30,9 @@ setup_file() { "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" \ "artifact upload docker-compose-logs/\*.log : exit 0" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice command" - stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice command" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 -q : cat tests/fixtures/id-multiple-services.txt" \ "inspect -f {{if\ ne\ 0\ .State.ExitCode}}{{.Name}}.{{.State.ExitCode}}{{\ end\ }} 456456 789789 : echo 456456.1" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 --format \* : cat tests/fixtures/service-id-exit-multiple-services-failed.txt" \ @@ -50,8 +48,8 @@ setup_file() { assert_output --partial "ran myservice dependencies" assert_output --partial "ran myservice command" assert_output --partial "Some containers had non-zero exit codes" + unstub buildkite-agent - unstub docker-compose unstub docker } @@ -73,10 +71,8 @@ setup_file() { "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" \ "artifact upload docker-compose-logs/\*.log : exit 0" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : exit 1" \ - stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : exit 1" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 -q : cat tests/fixtures/id-multiple-services.txt" \ "inspect -f {{if\ ne\ 0\ .State.ExitCode}}{{.Name}}.{{.State.ExitCode}}{{\ end\ }} 456456 789789 : echo 456456.1" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 --format \* : cat tests/fixtures/service-id-exit-multiple-services-failed.txt" \ @@ -91,8 +87,8 @@ setup_file() { assert_failure assert_output --partial "Failed to start dependencies" assert_output --partial "Some containers had non-zero exit codes" + unstub buildkite-agent - unstub docker-compose unstub docker } @@ -112,11 +108,9 @@ setup_file() { stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" \ - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice command" - stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice command" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 -q : cat tests/fixtures/id-multiple-services.txt" \ "inspect -f {{if\ ne\ 0\ .State.ExitCode}}{{.Name}}.{{.State.ExitCode}}{{\ end\ }} 456456 789789 : echo" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 --format \* : cat tests/fixtures/id-service-multiple-services.txt" \ @@ -129,8 +123,8 @@ setup_file() { assert_output --partial "ran myservice dependencies" assert_output --partial "ran myservice command" refute_output --partial "Some containers had non-zero exit codes" + unstub docker - unstub docker-compose unstub buildkite-agent } @@ -153,11 +147,9 @@ setup_file() { stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" \ - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice command" - stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice command" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 -q : echo" \ "ps -a --filter label=com.docker.compose.project=buildkite1111 --format '{{.ID}}\\t{{.Label \"com.docker.compose.service\"}}' : cat tests/fixtures/id-service-no-services.txt" @@ -167,7 +159,7 @@ setup_file() { assert_output --partial "ran myservice dependencies" assert_output --partial "ran myservice command" refute_output --partial "Uploading linked container logs" + unstub docker - unstub docker-compose unstub buildkite-agent } diff --git a/tests/plugin-config.bats b/tests/plugin-config.bats index cf590b71..f809dac8 100644 --- a/tests/plugin-config.bats +++ b/tests/plugin-config.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats load "${BATS_PLUGIN_PATH}/load.bash" -load '../lib/shared' +load '../lib/shared.bash' @test "Read existing config without default" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=llamas diff --git a/tests/project-name.bats b/tests/project-name.bats index 18f00e7c..e5232ea7 100644 --- a/tests/project-name.bats +++ b/tests/project-name.bats @@ -1,7 +1,7 @@ #!/usr/bin/env bats load "${BATS_PLUGIN_PATH}/load.bash" -load '../lib/shared' +load '../lib/shared.bash' @test "Project name comes from BUILDKITE_JOB_ID" { export BUILDKITE_JOB_ID=11111-1111-11111-11111 diff --git a/tests/push.bats b/tests/push.bats index 3610731b..ee072c26 100644 --- a/tests/push.bats +++ b/tests/push.bats @@ -1,9 +1,8 @@ #!/usr/bin/env bats load "${BATS_PLUGIN_PATH}/load.bash" -load '../lib/shared' +load '../lib/shared.bash' -# export DOCKER_COMPOSE_STUB_DEBUG=/dev/tty # export DOCKER_STUB_DEBUG=/dev/tty # export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty # export BATS_MOCK_TMPDIR=$PWD @@ -15,23 +14,20 @@ load '../lib/shared' export BUILDKITE_BUILD_NUMBER=1 stub buildkite-agent \ - "meta-data set docker-compose-plugin-built-image-tag-app \* : echo setting metadata to \$4" - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : cat ${PWD}/tests/composefiles/docker-compose.config.v3.2.yml" \ - "-f docker-compose.yml -p buildkite1111 push app : echo pushed app" + "meta-data set docker-compose-plugin-built-image-tag-app \* : echo tagged \$4" stub docker \ - "image inspect \* : exit 0" + "compose -f docker-compose.yml -p buildkite1111 config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" \ + "image inspect somewhere.dkr.ecr.some-region.amazonaws.com/blah : exit 0" \ + "compose -f docker-compose.yml -p buildkite1111 push app : echo pushed app" run "$PWD"/hooks/command assert_success assert_output --partial "pushed app" - unstub docker-compose - unstub buildkite-agent unstub docker + unstub buildkite-agent } @test "Push a prebuilt image with a repository and a tag" { @@ -41,18 +37,47 @@ load '../lib/shared' export BUILDKITE_BUILD_NUMBER=1 stub docker \ + "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ "image inspect \* : exit 1" \ "pull myimage : echo pulled prebuilt image" \ "tag myimage my.repository/myservice:llamas : echo tagged image" \ "push my.repository/myservice:llamas : echo pushed myservice" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo tagged \$4" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "pulled prebuilt image" + assert_output --partial "tagged image" + assert_output --partial "pushed myservice" + + unstub docker + unstub buildkite-agent +} + +@test "Push a prebuilt image with a repository and a tag in compatibility mode" { + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PIPELINE_SLUG=test + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice:my.repository/myservice:llamas + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true + + stub docker \ + "compose --compatibility -f docker-compose.yml -p buildkite1111 config : echo blah" \ + "image inspect \* : exit 1" \ + "pull myimage : echo pulled prebuilt image" \ + "tag myimage my.repository/myservice:llamas : echo tagged image" \ + "push my.repository/myservice:llamas : echo pushed myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4 > ${BATS_TEST_TMPDIR}/build-push-metadata" + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo tagged \$4" run "$PWD"/hooks/command @@ -61,7 +86,6 @@ load '../lib/shared' assert_output --partial "tagged image" assert_output --partial "pushed myservice" - unstub docker-compose unstub docker unstub buildkite-agent } @@ -72,28 +96,23 @@ load '../lib/shared' export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ + "compose -f docker-compose.yml -p buildkite1111 config : echo blah" \ "image inspect \* : exit 1" \ - "pull prebuilt : echo 'pulled prebuilt image'" \ - "tag prebuilt \* : echo 'invalid tag'; exit 1" - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" + "pull myimage : echo pulled prebuilt image" \ + "tag myimage my.repository/myservice:-llamas : exit 1" \ stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" run "$PWD"/hooks/command assert_failure assert_output --partial "Pulling pre-built service" refute_output --partial "tagged image" - assert_output --partial "invalid tag" unstub docker - unstub docker-compose unstub buildkite-agent } @@ -106,32 +125,30 @@ load '../lib/shared' export BUILDKITE_BUILD_NUMBER=1 stub docker \ + "compose -f docker-compose.yml -p buildkite1111 config : echo blah" \ "image inspect \* : exit 1" \ "pull prebuilt : echo pulled prebuilt image" \ "tag prebuilt my.repository/myservice:llamas : echo tagged image1" \ "push my.repository/myservice:llamas : echo pushed myservice1" \ + "compose -f docker-compose.yml -p buildkite1111 config : echo blah" \ "image inspect \* : exit 1" \ - "tag prebuilt my.repository/myservice:latest : echo tagged image2" \ + "tag prebuilt2 my.repository/myservice:latest : echo tagged image2" \ "push my.repository/myservice:latest : echo pushed myservice2" \ + "compose -f docker-compose.yml -p buildkite1111 config : echo blah" \ "image inspect \* : exit 1" \ - "tag prebuilt my.repository/myservice:alpacas : echo tagged image3" \ + "tag prebuilt3 my.repository/myservice:alpacas : echo tagged image3" \ "push my.repository/myservice:alpacas : echo pushed myservice3" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" - stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo tagged \$4" \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt2" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo tagged \$4" \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt3" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo tagged \$4" run "$PWD"/hooks/command @@ -144,92 +161,83 @@ load '../lib/shared' assert_output --partial "tagged image3" assert_output --partial "pushed myservice3" - unstub docker-compose unstub docker unstub buildkite-agent } -@test "Push a single service without pre-built nor service image" { +@test "Push a single service with service image" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=helper:my.repository/helper:llamas export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-helper : exit 1" - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" + "meta-data set docker-compose-plugin-built-image-tag-helper \* : echo tagged \$4" stub docker \ - "image inspect \* : exit 1" + "compose -f docker-compose.yml -p buildkite1111 config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" \ + "image inspect buildkite1111-helper : exit 0" \ + "tag buildkite1111-helper my.repository/helper:llamas : echo tagged helper" \ + "push my.repository/helper:llamas : echo pushed helper" run "$PWD"/hooks/command - assert_failure - - assert_output --partial 'No prebuilt-image nor service image found for service to push' + assert_success + assert_output --partial "tagged helper" + assert_output --partial "pushed helper" - unstub docker-compose unstub docker unstub buildkite-agent } -@test "Push two services without pre-built nor service image (second one is never tried)" { +@test "Push a single service without prebuilt nor service image" { export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_0=myservice1:my.repository/myservice1 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_1=myservice2:my.repository/myservice2:llamas + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=helper:my.repository/helper:llamas export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-helper : exit 1" stub docker \ - "image inspect \* : exit 1" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice1 : exit 1" + "compose -f docker-compose.yml -p buildkite1111 config : cat $PWD/tests/composefiles/docker-compose.config.v3.2.yml" \ + "image inspect buildkite1111-helper : exit 1" run "$PWD"/hooks/command assert_failure - assert_output --partial 'No prebuilt-image nor service image found for service to push' - unstub docker-compose - unstub buildkite-agent unstub docker + unstub buildkite-agent } -@test "Push two pre-built services with target repositories and tags" { +@test "Push two services with pre-built images" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_0=myservice1:my.repository/myservice1 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_1=myservice2:my.repository/myservice2:llamas export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" \ - "-f docker-compose.yml -p buildkite1111 config : echo ''" \ - stub docker \ - "image inspect \* : exit 1" \ - "pull myservice1 : exit 0" \ - "tag myservice1 my.repository/myservice1 : echo tagging image1" \ + "compose -f docker-compose.yml -p buildkite1111 config : echo blah " \ + "image inspect buildkite1111-myservice1 : exit 1" \ + "pull prebuilt1 : exit 0" \ + "tag prebuilt1 my.repository/myservice1 : echo tagging image1" \ "push my.repository/myservice1 : echo pushing myservice1 image" \ - "image inspect \* : exit 1" \ - "pull myservice2 : exit 0" \ - "tag myservice2 my.repository/myservice2:llamas : echo tagging image2" \ + "compose -f docker-compose.yml -p buildkite1111 config : echo blah " \ + "image inspect buildkite1111-myservice2 : exit 1" \ + "pull prebuilt2 : exit 0" \ + "tag prebuilt2 my.repository/myservice2:llamas : echo tagging image2" \ "push my.repository/myservice2:llamas : echo pushing myservice2 image" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice1 : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice1 : echo myservice1" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice1 \* : echo \$4" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice1 : echo prebuilt1" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice1 \* : echo tagged \$4" \ "meta-data exists docker-compose-plugin-built-image-tag-myservice2 : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice2 : echo myservice2" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice2 \* : echo \$4" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice2 : echo prebuilt2" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice2 \* : echo tagged \$4" run "$PWD"/hooks/command @@ -239,7 +247,6 @@ load '../lib/shared' assert_output --partial "tagging image2" assert_output --partial "pushing myservice2 image" - unstub docker-compose - unstub buildkite-agent unstub docker + unstub buildkite-agent } diff --git a/tests/run.bats b/tests/run.bats index 46c48a2b..774f01b0 100644 --- a/tests/run.bats +++ b/tests/run.bats @@ -1,8 +1,8 @@ #!/usr/bin/env bats load "${BATS_PLUGIN_PATH}/load.bash" -load '../lib/shared' -load '../lib/run' +load '../lib/shared.bash' +load '../lib/run.bash' # export DOCKER_COMPOSE_STUB_DEBUG=/dev/tty # export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty @@ -13,8 +13,8 @@ setup_file() { } teardown() { - # some test failures may leave this file around - rm -f docker-compose.buildkite-1-override.yml + # plugin leaves override files around + rm -f docker-compose.buildkite*-override.yml } @test "Run without a prebuilt image" { @@ -26,9 +26,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -37,7 +37,8 @@ teardown() { assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -50,9 +51,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -60,9 +61,9 @@ teardown() { run "$PWD"/hooks/command assert_success - refute_output --partial "The Docker Compose Plugin does not correctly support step-level array commands" assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -76,9 +77,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --workdir=/test_workdir --rm myservice : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --workdir=/test_workdir --rm myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -87,7 +88,8 @@ teardown() { assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -100,9 +102,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'sh -c \'echo hello world\'' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'sh -c \'echo hello world\'' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -111,7 +113,8 @@ teardown() { assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -126,9 +129,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'cmd1\ncmd2\ncmd3' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'cmd1\ncmd2\ncmd3' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -136,9 +139,9 @@ cmd3" run "$PWD"/hooks/command assert_success - assert_output --partial "The Docker Compose Plugin does not correctly support step-level array commands" assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -153,9 +156,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -163,9 +166,9 @@ cmd3" run "$PWD"/hooks/command assert_success - refute_output --partial "The Docker Compose Plugin does not correctly support step-level array commands" assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -183,9 +186,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ENVIRONMENT_1=MYENV export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ENVIRONMENT_2=ANOTHER="this is a long string with spaces; and semi-colons" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e MYENV=0 -e MYENV -e MYENV=2 -e MYENV -e ANOTHER=this\ is\ a\ long\ string\ with\ spaces\;\ and\ semi-colons -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e MYENV=0 -e MYENV -e MYENV=2 -e MYENV -e ANOTHER=this\ is\ a\ long\ string\ with\ spaces\;\ and\ semi-colons -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -194,7 +197,8 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -208,9 +212,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -219,24 +223,24 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } -@test "Run without a prebuilt image with build args" { +@test "Run without a prebuilt image without pulling" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_0=MYARG=0 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_1=MYARG=1 export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND="echo hello world" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SKIP_PULL=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -245,7 +249,8 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -257,10 +262,10 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PROPAGATE_ENVIRONMENT=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -272,7 +277,7 @@ cmd3" assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice" assert_output --partial "Not propagating environment variables to container" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -288,10 +293,10 @@ cmd3" echo "VAR0=1" > "${BUILDKITE_ENV_FILE}" echo "VAR2=lalala" >> "${BUILDKITE_ENV_FILE}" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -e \* -e \* -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with vars \${11} and \${13}" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -e \* -e \* -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with vars \${12} and \${14}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -303,7 +308,7 @@ cmd3" assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice" assert_output --partial "ran myservice with vars VAR0 and VAR2" - unstub docker-compose + unstub docker unstub buildkite-agent rm "${BUILDKITE_ENV_FILE}" @@ -318,10 +323,10 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -331,7 +336,7 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -345,10 +350,10 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml : exit 0" \ @@ -358,7 +363,7 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -373,10 +378,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo pulled myservice" \ - "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo pulled myservice" \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml-tests/composefiles/docker-compose.v2.1.yml : exit 0" \ @@ -386,7 +391,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -400,10 +405,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml : exit 0" \ @@ -413,7 +418,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -426,8 +431,8 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -437,7 +442,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "Exited with 2" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -451,11 +456,11 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PULL_RETRIES=3 - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -466,7 +471,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "pulled myservice" assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -480,10 +485,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TTY=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without tty" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without tty" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -493,7 +498,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without tty" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -507,9 +512,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_DEPENDENCIES=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --no-deps --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without dependencies" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --no-deps --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without dependencies" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -519,7 +524,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without dependencies" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -533,9 +538,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PRE_RUN_DEPENDENCIES=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with dependencies" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with dependencies" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -545,7 +550,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with dependencies" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -559,10 +565,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ANSI=false - stub docker-compose \ - "--no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "--no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "--no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without ansi output" + stub docker \ + "compose --no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose --no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose --no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without ansi output" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -572,34 +578,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without ansi output" - unstub docker-compose - unstub buildkite-agent -} - - -@test "Run without pull" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND=pwd - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SKIP_PULL=true - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without pull" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice" - assert_output --partial "ran myservice without pull" - - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -613,10 +592,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_USE_ALIASES=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --use-aliases --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --use-aliases --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -626,10 +605,11 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with use aliases output" - unstub docker-compose + unstub docker unstub buildkite-agent } + @test "Run with compatibility mode" { export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd @@ -640,10 +620,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true - stub docker-compose \ - "--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" + stub docker \ + "compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -653,7 +633,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with use aliases output" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -668,10 +648,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="./dist:/app/dist" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="./pkg:/app/pkg" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v $PWD/dist:/app/dist -v $PWD/pkg:/app/pkg -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v $PWD/dist:/app/dist -v $PWD/pkg:/app/pkg -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -681,7 +661,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -695,10 +675,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES="buildkite:/buildkite" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -708,7 +688,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -725,114 +705,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_DOCKER_DEFAULT_VOLUMES="buildkite:/buildkite; ./dist:/app/dist;; ; ;" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "ran myservice with volumes" - unstub docker-compose - unstub buildkite-agent -} - -@test "Run with volumes with variables" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND=pwd - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="\$SUPER_VARIABLE:/mnt" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="/:\$OTHER_VARIABLE" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_2="\$RELATIVE_VARIABLE:/srv" - - export SUPER_VARIABLE='/test/path' - export OTHER_VARIABLE='/path/tested' - export RELATIVE_VARIABLE='./path' - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v \\\$SUPER_VARIABLE:/mnt -v /:\\\$OTHER_VARIABLE -v \\\$RELATIVE_VARIABLE:/srv -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "ran myservice with volumes" - unstub docker-compose - unstub buildkite-agent -} - - -@test "Run with volumes with variables but option turned off" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND=pwd - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_EXPAND_VOLUME_VARS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="\$SUPER_VARIABLE:/mnt" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="/:\$OTHER_VARIABLE" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_2="\$RELATIVE_VARIABLE:/srv" - - - export SUPER_VARIABLE='/test/path' - export OTHER_VARIABLE='/path/tested' - export RELATIVE_VARIABLE='./path' - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v \\\$SUPER_VARIABLE:/mnt -v /:\\\$OTHER_VARIABLE -v \\\$RELATIVE_VARIABLE:/srv -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "ran myservice with volumes" - unstub docker-compose - unstub buildkite-agent -} - -@test "Run with volumes with variables and option turned on" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND=pwd - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=true - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_EXPAND_VOLUME_VARS=true - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="\$SUPER_VARIABLE:/mnt" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="/:\$OTHER_VARIABLE" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_2="\$RELATIVE_VARIABLE:/srv" - - - export SUPER_VARIABLE='/test/path' - export OTHER_VARIABLE='/path/tested' - export RELATIVE_VARIABLE='./path' - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v /test/path:/mnt -v /:/path/tested -v $PWD/path:/srv -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -842,7 +718,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -856,10 +732,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_DOCKER_DEFAULT_VOLUMES="buildkite:/buildkite;./dist:/app/dist" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -869,7 +745,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -885,9 +761,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG_1="llamas2.yml" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG_2="llamas3.yml" - stub docker-compose \ - "-f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-llamas1.yml-llamas2.yml-llamas3.yml : exit 1" @@ -896,7 +772,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -909,9 +786,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : exit 2" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : exit 2" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -921,7 +798,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "^^^ +++" assert_output --partial "Failed to run command, exited with 2" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -936,10 +813,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull --parallel myservice1 myservice2 : echo pulled myservice1 and myservice2" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice1=0 myservice1 : echo started dependencies for myservice1" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice1_build_1 -T --rm myservice1 /bin/sh -e -c 'pwd' : echo ran myservice1" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull --parallel myservice1 myservice2 : echo pulled myservice1 and myservice2" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice1=0 myservice1 : echo started dependencies for myservice1" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice1_build_1 -T --rm myservice1 /bin/sh -e -c 'pwd' : echo ran myservice1" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice1 : exit 0" \ @@ -952,7 +829,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "pulled myservice1 and myservice2" assert_output --partial "ran myservice1" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -966,9 +843,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_USER="1000" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -977,7 +854,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -991,9 +869,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_USER="1000:1001" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000:1001 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000:1001 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1002,7 +880,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -1029,7 +908,7 @@ export BUILDKITE_JOB_ID=1111 } -@test "Run without -T --rm" { +@test "Run without --rm" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test @@ -1038,12 +917,11 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RM=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TTY=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : echo myimage" \ @@ -1053,7 +931,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without tty" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1067,9 +945,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ENTRYPOINT="my custom entrypoint" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm --entrypoint 'my custom entrypoint' myservice : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm --entrypoint 'my custom entrypoint' myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1078,7 +956,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -1092,9 +971,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_BUILDKITE_AGENT=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e BUILDKITE_JOB_ID -e BUILDKITE_BUILD_ID -e BUILDKITE_AGENT_ACCESS_TOKEN -v $BATS_MOCK_TMPDIR/bin/buildkite-agent:/usr/bin/buildkite-agent myservice : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e BUILDKITE_JOB_ID -e BUILDKITE_BUILD_ID -e BUILDKITE_AGENT_ACCESS_TOKEN -v $BATS_MOCK_TMPDIR/bin/buildkite-agent:/usr/bin/buildkite-agent myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1103,7 +982,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -1118,9 +998,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_NO_CACHE=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_PARALLEL=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1129,7 +1009,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -1143,9 +1024,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_REPO_MIRROR=/tmp/sample-mirror - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -v /tmp/sample-mirror:/tmp/sample-mirror:ro -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -v /tmp/sample-mirror:/tmp/sample-mirror:ro -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1154,7 +1035,8 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -1169,9 +1051,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_SSH_AGENT=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/root/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/root/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1181,12 +1063,12 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command - assert_success - kill %1 + assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @@ -1201,9 +1083,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_SSH_AGENT=/tmp/test - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/tmp/test/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/tmp/test/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1213,29 +1095,30 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command - assert_success - kill %1 + assert_success assert_output --partial "ran myservice" - unstub docker-compose + + unstub docker unstub buildkite-agent } @test "Run without mount-checkout doesn't set volume" { + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without mount-checkout" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without mount-checkout" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1245,24 +1128,26 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without mount-checkout" - unstub docker-compose + + unstub docker unstub buildkite-agent } @test "Run with mount-checkout set to true" { + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --workdir=/workdir -v $PWD:/workdir --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T --workdir=/workdir -v /plugin:/workdir --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1272,25 +1157,27 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with mount-checkout" - unstub docker-compose + + unstub docker unstub buildkite-agent } @test "Run with mount-checkout set to true with custom workdir" { + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR="/custom_workdir" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --workdir=$BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR -v $PWD:$BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T \* -v \* --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout on \${14}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1299,8 +1186,9 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command assert_success - assert_output --partial "ran myservice with mount-checkout" - unstub docker-compose + assert_output --partial "ran myservice with mount-checkout on /plugin:/custom_workdir" + + unstub docker unstub buildkite-agent } @@ -1315,10 +1203,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="/special" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T -v \* --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout on \${12}" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T -v \* --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout on \${13}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1329,7 +1217,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with mount-checkout on /plugin:/special" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1345,10 +1233,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="/special" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR="/custom_workdir" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T \* -v \* --rm myservice /bin/sh -e -c 'pwd' : echo echo ran myservice with mount-checkout on \${13}" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T \* -v \* --rm myservice /bin/sh -e -c 'pwd' : echo echo ran myservice with mount-checkout on \${14}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1360,7 +1248,7 @@ export BUILDKITE_JOB_ID=1111 assert_output --partial "ran myservice with mount-checkout on /plugin:/special" assert_output --partial "--workdir=/custom_workdir" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1375,8 +1263,8 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="not_absolute" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1387,7 +1275,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "mount-checkout should be either true or an absolute path to use as a mountpoint" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1403,8 +1291,8 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="not-absolute" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR="/custom_workdir" - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1415,7 +1303,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "mount-checkout should be either true or an absolute path to use as a mountpoint" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1429,9 +1317,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WAIT=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up --wait -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up --wait -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1439,10 +1327,9 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command assert_success - assert_output --partial "Starting dependencies" assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1456,10 +1343,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SERVICE_PORTS=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm --service-ports myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm --service-ports myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : echo myimage" \ @@ -1469,49 +1356,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without tty" - unstub docker-compose - unstub buildkite-agent -} - -@test "Run with Docker labels" { - # Pipeline vars - export BUILDKITE_AGENT_ID="1234" - export BUILDKITE_AGENT_NAME="agent" - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND=pwd - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_LABEL="Testjob" - export BUILDKITE_PIPELINE_NAME="label-test" - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_STEP_KEY="test-job" - - # Plugin config - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN_LABELS="true" - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 \ - --label com.buildkite.pipeline_name=${BUILDKITE_PIPELINE_NAME} \ - --label com.buildkite.pipeline_slug=${BUILDKITE_PIPELINE_SLUG} \ - --label com.buildkite.build_number=${BUILDKITE_BUILD_NUMBER} \ - --label com.buildkite.job_id=${BUILDKITE_JOB_ID} \ - --label com.buildkite.job_label=${BUILDKITE_LABEL} \ - --label com.buildkite.step_key=${BUILDKITE_STEP_KEY} \ - --label com.buildkite.agent_name=${BUILDKITE_AGENT_NAME} \ - --label com.buildkite.agent_id=${BUILDKITE_AGENT_ID} \ - -T --rm myservice /bin/sh -e -c $'pwd' : echo ran myservice" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : echo myimage" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1525,9 +1370,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_QUIET_PULL=true - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up --quiet-pull -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up --quiet-pull -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1538,7 +1383,7 @@ export BUILDKITE_JOB_ID=1111 refute_output --partial "Pulling" assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1553,9 +1398,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e VAR_A -e VAR_B -e VAR_C -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker \ + "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e VAR_A -e VAR_B -e VAR_C -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1564,7 +1409,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker-compose + unstub docker unstub buildkite-agent } @@ -1587,52 +1432,3 @@ export BUILDKITE_JOB_ID=1111 assert_output --partial "env-propagation-list desired, but LIST_OF_VARS is not defined!" unstub buildkite-agent } - -@test "Run with expanded run log group by default" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND="echo hello world" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "+++ :docker: Running /bin/sh -e -c 'echo hello world' in service myservice" - unstub docker-compose - unstub buildkite-agent -} - -@test "Run with collapsed run log group" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND="echo hello world" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COLLAPSE_LOGS=true - - stub docker-compose \ - "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "--- :docker: Running /bin/sh -e -c 'echo hello world' in service myservice" - unstub docker-compose - unstub buildkite-agent -} diff --git a/tests/v2/build.bats b/tests/v1/build.bats similarity index 61% rename from tests/v2/build.bats rename to tests/v1/build.bats index 0587d85b..b4bc033f 100644 --- a/tests/v2/build.bats +++ b/tests/v1/build.bats @@ -1,36 +1,34 @@ #!/usr/bin/env bats load "${BATS_PLUGIN_PATH}/load.bash" -load '../../lib/shared' +load '../../lib/shared.bash' -# export DOCKER_STUB_DEBUG=/dev/stdout -# export BUILDKITE_AGENT_STUB_DEBUG=/dev/stdout -# export BATS_MOCK_TMPDIR=$PWD - -setup_file() { - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=2 -} +# export DOCKER_COMPOSE_STUB_DEBUG=/dev/stdout teardown() { - # plugin leaves override files around + # some test failures may leave this file around rm -f docker-compose.buildkite*-override.yml } +setup_file() { + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 +} + @test "Build without a repository" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker + unstub docker-compose } @test "Build with no-cache" { @@ -40,14 +38,14 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull --no-cache myservice : echo built myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull --no-cache myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker + unstub docker-compose } @test "Build with parallel" { @@ -57,14 +55,14 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull --parallel myservice : echo built myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull --parallel myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker + unstub docker-compose } @test "Build with build args" { @@ -75,18 +73,52 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_0=MYARG=0 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_1=MYARG=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull --build-arg MYARG=0 --build-arg MYARG=1 myservice : echo built myservice" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "built myservice" + unstub docker-compose +} + +@test "Build with docker-compose and v1 is set explicitly " { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "built myservice" + unstub docker-compose +} + +@test "Build with a repository" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker + + unstub docker-compose } +# TODO: move this to push testing @test "Build with a repository and multiple build aliases" { - skip "need to be moved to push" export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_ALIAS_0=myservice-1 @@ -94,43 +126,51 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" \ - "compose -f docker-compose.yml -p buildkite1111 push myservice : echo pushed myservice" \ + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "built myservice" + + unstub docker-compose +} + +@test "Build with a repository and push retries" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_RETRIES=3 - stub buildkite-agent \ - "meta-data set docker-compose-plugin-built-image-tag-myservice my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice-1 my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice-1" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice-2 my.repository/llamas:test-myservice-build-1 : echo set image metadata for myservice-2" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - assert_output --partial "pushed myservice" - assert_output --partial "set image metadata for myservice" - assert_output --partial "set image metadata for myservice-1" - assert_output --partial "set image metadata for myservice-2" - unstub docker - unstub buildkite-agent + + unstub docker-compose } -@test "Build with a custom config file" { +@test "Build with a repository and custom config file" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG=tests/composefiles/docker-compose.v2.0.yml export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 build --pull myservice : echo built myservice" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker + unstub docker-compose } @test "Build with a repository and multiple custom config files" { @@ -141,15 +181,15 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 build --pull myservice : echo built myservice" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 build --pull myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - unstub docker + unstub docker-compose } @test "Build with a repository and multiple services" { @@ -159,29 +199,33 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1112 build --pull myservice1 myservice2 : echo built all services" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1112 build --pull myservice1 myservice2 : echo built all services" run "$PWD"/hooks/command assert_success assert_output --partial "built all services" - unstub docker + unstub docker-compose } @test "Build with a docker-compose v1.0 configuration file" { export BUILDKITE_JOB_ID=1112 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v1.0.yml" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache:latest export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 + stub docker-compose \ + "-f tests/composefiles/docker-compose.v1.0.yml -p buildkite1112 build --pull helloworld : echo built service" + run "$PWD"/hooks/command - assert_failure - assert_output --partial "Compose file versions 2.0 and above" + assert_success + assert_output --partial "built service" + + unstub docker-compose } @test "Build with a cache-from image" { @@ -192,8 +236,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command @@ -201,70 +245,68 @@ teardown() { assert_output --partial "- my.repository/myservice_cache:latest" assert_output --partial "built helloworld" - unstub docker + unstub docker-compose } -@test "Build with an invalid cache-from tag (just passed through)" { +@test "Build with a cache-from image with no-cache also set" { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache:-latest + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache:latest + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_NO_CACHE=true export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 build --pull --no-cache helloworld : echo built helloworld" run "$PWD"/hooks/command assert_success - assert_output --partial "- my.repository/myservice_cache:-latest" + refute_output --partial "- my.repository/myservice_cache:latest" assert_output --partial "built helloworld" - - unstub docker + unstub docker-compose } -@test "Build with a cache-from image with no tag" { - export BUILDKITE_BUILD_NUMBER=1 +@test "Build with an invalid cache-from tag" { + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache:-latest + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command assert_success - assert_output --partial "- my.repository/myservice_cache" + assert_output --partial "- my.repository/myservice_cache:-latest" assert_output --partial "built helloworld" - unstub docker + unstub docker-compose } -@test "Build with a cache-from image with no-cache also set" { - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" +@test "Build with a cache-from image with no tag" { + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache:latest - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_NO_CACHE=true export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 build --pull --no-cache helloworld : echo built helloworld" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_0=helloworld + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CACHE_FROM_0=helloworld:my.repository/myservice_cache + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG="tests/composefiles/docker-compose.v3.2.yml" + + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command assert_success - refute_output --partial "pulled cache image" - refute_output --partial "- my.repository/myservice_cache:latest" + assert_output --partial "- my.repository/myservice_cache" assert_output --partial "built helloworld" - unstub docker + unstub docker-compose } @test "Build with several cache-from images for one service" { @@ -276,8 +318,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull helloworld : echo built helloworld" run "$PWD"/hooks/command @@ -286,7 +328,7 @@ teardown() { assert_output --partial "- my.repository/myservice_cache:latest" assert_output --partial "built helloworld" - unstub docker + unstub docker-compose } @test "Build with a cache-from image with hyphen" { @@ -297,8 +339,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull hello-world : echo built hello-world" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull hello-world : echo built hello-world" run "$PWD"/hooks/command @@ -306,7 +348,7 @@ teardown() { assert_output --partial "- my.repository/my-service_cache:latest" assert_output --partial "built hello-world" - unstub docker + unstub docker-compose } @test "Build with a service name and cache-from with period" { @@ -317,8 +359,8 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${10}" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v3.2.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \$9" run "$PWD"/hooks/command @@ -326,7 +368,7 @@ teardown() { assert_output --partial "- my.repository/my-service_cache:latest" assert_output --partial "built hello.world" - unstub docker + unstub docker-compose } @test "Build with target" { @@ -337,8 +379,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TARGET=intermediate - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${10}" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml build --pull \* : echo built \${9}" run "$PWD"/hooks/command @@ -346,19 +388,36 @@ teardown() { assert_output --partial "built myservice" assert_output --partial " target: intermediate" - unstub docker + unstub docker-compose } -@test "Build with ssh option as boolean" { +@test "Build with ssh option (but no buildkit)" { export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SSH=true + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull --ssh default \* : echo built \${10} with ssh" + run "$PWD"/hooks/command + + assert_failure + assert_output --partial "You can not use the ssh option if you are not using buildkit" + refute_output --partial "built myservice" +} + +@test "Build with ssh option as true and buildkit" { + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PIPELINE_SLUG=test + + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT=true + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SSH=true + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull --ssh default \* : echo built \${9} with ssh" run "$PWD"/hooks/command @@ -366,19 +425,20 @@ teardown() { assert_output --partial "built myservice" assert_output --partial "with ssh" - unstub docker + unstub docker-compose } -@test "Build with ssh option as string" { +@test "Build with ssh option as string and buildkit" { export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILDKIT=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SSH=context - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull --ssh context \* : echo built \${10} with ssh" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull --ssh context \* : echo built \${9} with ssh" run "$PWD"/hooks/command @@ -386,7 +446,7 @@ teardown() { assert_output --partial "built myservice" assert_output --partial "with ssh" - unstub docker + unstub docker-compose } @test "Build with secrets" { @@ -398,8 +458,8 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SECRETS_0='id=test,file=~/.test' export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SECRETS_1='id=SECRET_VAR' - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build --pull --secret \* --secret \* \* : echo built \${12} with secrets \${9} and \${11}" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build --pull --secret \* --secret \* \* : echo built \${11} with secrets \${8} and \${10}" run "$PWD"/hooks/command @@ -407,7 +467,7 @@ teardown() { assert_output --partial "built myservice" assert_output --partial "with secrets id=test,file=~/.test and id=SECRET_VAR" - unstub docker + unstub docker-compose } @test "Build without pull" { @@ -417,13 +477,12 @@ teardown() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 build myservice : echo built myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 build myservice : echo built myservice" run "$PWD"/hooks/command assert_success assert_output --partial "built myservice" - - unstub docker + unstub docker-compose } diff --git a/tests/v2/push.bats b/tests/v1/push.bats similarity index 64% rename from tests/v2/push.bats rename to tests/v1/push.bats index 437d1da3..989f30bf 100644 --- a/tests/v2/push.bats +++ b/tests/v1/push.bats @@ -9,7 +9,7 @@ load '../../lib/shared' # export BATS_MOCK_TMPDIR=$PWD setup_file() { - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=2 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 } @test "Push a single service with an image in its config" { @@ -19,19 +19,23 @@ setup_file() { export BUILDKITE_BUILD_NUMBER=1 stub buildkite-agent \ - "meta-data set docker-compose-plugin-built-image-tag-app \* : echo \$4" + "meta-data set docker-compose-plugin-built-image-tag-app \* : echo setting metadata to \$4" + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : cat ${PWD}/tests/composefiles/docker-compose.config.v3.2.yml" \ + "-f docker-compose.yml -p buildkite1111 push app : echo pushed app" stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : cat ${PWD}/tests/composefiles/docker-compose.config.v3.2.yml" \ - "image inspect somewhere.dkr.ecr.some-region.amazonaws.com/blah : exit 0" \ - "compose -f docker-compose.yml -p buildkite1111 push app : echo pushed app" + "image inspect \* : exit 0" run "$PWD"/hooks/command assert_success assert_output --partial "pushed app" - unstub docker + + unstub docker-compose unstub buildkite-agent + unstub docker } @test "Push a prebuilt image with a repository and a tag" { @@ -41,47 +45,18 @@ setup_file() { export BUILDKITE_BUILD_NUMBER=1 stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ - "image inspect \* : exit 1" \ - "pull myimage : echo pulled prebuilt image" \ - "tag myimage my.repository/myservice:llamas : echo tagged image" \ - "push my.repository/myservice:llamas : echo pushed myservice" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "pulled prebuilt image" - assert_output --partial "tagged image" - assert_output --partial "pushed myservice" - unstub docker - unstub buildkite-agent -} - -@test "Push a prebuilt image with a repository and a tag in compatibility mode" { - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PIPELINE_SLUG=test - - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=myservice:my.repository/myservice:llamas - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true - - stub docker \ - "compose --compatibility -f docker-compose.yml -p buildkite1111 config : echo ''" \ "image inspect \* : exit 1" \ "pull myimage : echo pulled prebuilt image" \ "tag myimage my.repository/myservice:llamas : echo tagged image" \ "push my.repository/myservice:llamas : echo pushed myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4 > ${BATS_TEST_TMPDIR}/build-push-metadata" run "$PWD"/hooks/command @@ -89,6 +64,8 @@ setup_file() { assert_output --partial "pulled prebuilt image" assert_output --partial "tagged image" assert_output --partial "pushed myservice" + + unstub docker-compose unstub docker unstub buildkite-agent } @@ -99,12 +76,15 @@ setup_file() { export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 + stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ "image inspect \* : exit 1" \ - "pull prebuilt : echo ''" \ + "pull prebuilt : echo 'pulled prebuilt image'" \ "tag prebuilt \* : echo 'invalid tag'; exit 1" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" + stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ @@ -112,12 +92,12 @@ setup_file() { run "$PWD"/hooks/command assert_failure - - refute_output --partial "pulled prebuilt image" + assert_output --partial "Pulling pre-built service" refute_output --partial "tagged image" assert_output --partial "invalid tag" unstub docker + unstub docker-compose unstub buildkite-agent } @@ -130,30 +110,32 @@ setup_file() { export BUILDKITE_BUILD_NUMBER=1 stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ "image inspect \* : exit 1" \ "pull prebuilt : echo pulled prebuilt image" \ "tag prebuilt my.repository/myservice:llamas : echo tagged image1" \ "push my.repository/myservice:llamas : echo pushed myservice1" \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ "image inspect \* : exit 1" \ - "tag prebuilt2 my.repository/myservice:latest : echo tagged image2" \ + "tag prebuilt my.repository/myservice:latest : echo tagged image2" \ "push my.repository/myservice:latest : echo pushed myservice2" \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ "image inspect \* : exit 1" \ - "tag prebuilt3 my.repository/myservice:alpacas : echo tagged image3" \ + "tag prebuilt my.repository/myservice:alpacas : echo tagged image3" \ "push my.repository/myservice:alpacas : echo pushed myservice3" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" + stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt2" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt3" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo prebuilt" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice \* : echo \$4" \ run "$PWD"/hooks/command @@ -165,82 +147,93 @@ setup_file() { assert_output --partial "pushed myservice2" assert_output --partial "tagged image3" assert_output --partial "pushed myservice3" + + unstub docker-compose unstub docker unstub buildkite-agent } -@test "Push a single service with service image" { +@test "Push a single service without pre-built nor service image" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=helper:my.repository/helper:llamas export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 stub buildkite-agent \ - "meta-data set docker-compose-plugin-built-image-tag-helper \* : echo \$4" + "meta-data exists docker-compose-plugin-built-image-tag-helper : exit 1" + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : cat ${PWD}/tests/composefiles/docker-compose.config.v3.2.yml" \ - "image inspect buildkite1111-helper : exit 0" \ - "tag buildkite1111-helper my.repository/helper:llamas : echo tagged helper" \ - "push my.repository/helper:llamas : echo pushed helper" + "image inspect \* : exit 1" run "$PWD"/hooks/command - assert_success - assert_output --partial "tagged helper" - assert_output --partial "pushed helper" + assert_failure + + assert_output --partial 'No prebuilt-image nor service image found for service to push' + + unstub docker-compose unstub docker unstub buildkite-agent } -@test "Push a single service without prebuilt nor service image" { +@test "Push two services without pre-built nor service image (second one is never tried)" { export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH=helper:my.repository/helper:llamas + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_0=myservice1:my.repository/myservice1 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_1=myservice2:my.repository/myservice2:llamas export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-helper : exit 1" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : cat ${PWD}/tests/composefiles/docker-compose.config.v3.2.yml" \ - "image inspect buildkite1111-helper : exit 1" + "image inspect \* : exit 1" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice1 : exit 1" run "$PWD"/hooks/command assert_failure + assert_output --partial 'No prebuilt-image nor service image found for service to push' - unstub docker + unstub docker-compose unstub buildkite-agent + unstub docker } -@test "Push two services with pre-built images" { +@test "Push two pre-built services with target repositories and tags" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_0=myservice1:my.repository/myservice1 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PUSH_1=myservice2:my.repository/myservice2:llamas export BUILDKITE_PIPELINE_SLUG=test export BUILDKITE_BUILD_NUMBER=1 + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" \ + "-f docker-compose.yml -p buildkite1111 config : echo ''" \ + stub docker \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ - "image inspect buildkite1111-myservice1 : exit 1" \ - "pull prebuilt1 : exit 0" \ - "tag prebuilt1 my.repository/myservice1 : echo tagging image1" \ + "image inspect \* : exit 1" \ + "pull myservice1 : exit 0" \ + "tag myservice1 my.repository/myservice1 : echo tagging image1" \ "push my.repository/myservice1 : echo pushing myservice1 image" \ - "compose -f docker-compose.yml -p buildkite1111 config : echo ''" \ - "image inspect buildkite1111-myservice2 : exit 1" \ - "pull prebuilt2 : exit 0" \ - "tag prebuilt2 my.repository/myservice2:llamas : echo tagging image2" \ + "image inspect \* : exit 1" \ + "pull myservice2 : exit 0" \ + "tag myservice2 my.repository/myservice2:llamas : echo tagging image2" \ "push my.repository/myservice2:llamas : echo pushing myservice2 image" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice1 : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice1 : echo prebuilt1" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice1 : echo myservice1" \ "meta-data set docker-compose-plugin-built-image-tag-myservice1 \* : echo \$4" \ "meta-data exists docker-compose-plugin-built-image-tag-myservice2 : exit 0" \ - "meta-data get docker-compose-plugin-built-image-tag-myservice2 : echo prebuilt2" \ - "meta-data set docker-compose-plugin-built-image-tag-myservice2 \* : echo \$4" + "meta-data get docker-compose-plugin-built-image-tag-myservice2 : echo myservice2" \ + "meta-data set docker-compose-plugin-built-image-tag-myservice2 \* : echo \$4" \ run "$PWD"/hooks/command @@ -249,6 +242,8 @@ setup_file() { assert_output --partial "pushing myservice1 image" assert_output --partial "tagging image2" assert_output --partial "pushing myservice2 image" - unstub docker + + unstub docker-compose unstub buildkite-agent + unstub docker } diff --git a/tests/v2/run.bats b/tests/v1/run.bats similarity index 56% rename from tests/v2/run.bats rename to tests/v1/run.bats index 616daf7a..5823b1b0 100644 --- a/tests/v2/run.bats +++ b/tests/v1/run.bats @@ -1,16 +1,16 @@ #!/usr/bin/env bats load "${BATS_PLUGIN_PATH}/load.bash" -load '../../lib/shared' -load '../../lib/run' +load '../../lib/shared.bash' +load '../../lib/run.bash' # export DOCKER_COMPOSE_STUB_DEBUG=/dev/tty # export BUILDKITE_AGENT_STUB_DEBUG=/dev/tty # export BATS_MOCK_TMPDIR=$PWD setup_file() { - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=2 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN_LABELS="false" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLI_VERSION=1 } teardown() { @@ -27,9 +27,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -38,8 +38,7 @@ teardown() { assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -52,9 +51,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -62,9 +61,9 @@ teardown() { run "$PWD"/hooks/command assert_success + refute_output --partial "The Docker Compose Plugin does not correctly support step-level array commands" assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -78,9 +77,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --workdir=/test_workdir --rm myservice : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --workdir=/test_workdir --rm myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -89,8 +88,7 @@ teardown() { assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -103,9 +101,9 @@ teardown() { export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'sh -c \'echo hello world\'' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'sh -c \'echo hello world\'' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -114,8 +112,7 @@ teardown() { assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -130,9 +127,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'cmd1\ncmd2\ncmd3' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c $'cmd1\ncmd2\ncmd3' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -140,9 +137,9 @@ cmd3" run "$PWD"/hooks/command assert_success + assert_output --partial "The Docker Compose Plugin does not correctly support step-level array commands" assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -157,9 +154,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice echo 'hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -167,9 +164,9 @@ cmd3" run "$PWD"/hooks/command assert_success + refute_output --partial "The Docker Compose Plugin does not correctly support step-level array commands" assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -187,9 +184,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ENVIRONMENT_1=MYENV export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ENVIRONMENT_2=ANOTHER="this is a long string with spaces; and semi-colons" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e MYENV=0 -e MYENV -e MYENV=2 -e MYENV -e ANOTHER=this\ is\ a\ long\ string\ with\ spaces\;\ and\ semi-colons -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e MYENV=0 -e MYENV -e MYENV=2 -e MYENV -e ANOTHER=this\ is\ a\ long\ string\ with\ spaces\;\ and\ semi-colons -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -198,8 +195,7 @@ cmd3" assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -213,9 +209,9 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -224,61 +220,7 @@ cmd3" assert_success assert_output --partial "ran myservice" - - unstub docker - unstub buildkite-agent -} - -@test "Run without a prebuilt image with build args" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_0=MYARG=0 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ARGS_1=MYARG=1 - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND="echo hello world" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "ran myservice" - - unstub docker - unstub buildkite-agent -} - -@test "Run without a prebuilt image without pulling" { - export BUILDKITE_JOB_ID=1111 - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice - export BUILDKITE_PIPELINE_SLUG=test - export BUILDKITE_BUILD_NUMBER=1 - export BUILDKITE_COMMAND="echo hello world" - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SKIP_PULL=true - - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" - - stub buildkite-agent \ - "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" - - run "$PWD"/hooks/command - - assert_success - assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -290,10 +232,10 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PROPAGATE_ENVIRONMENT=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -305,7 +247,7 @@ cmd3" assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice" assert_output --partial "Not propagating environment variables to container" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -321,10 +263,10 @@ cmd3" echo "VAR0=1" > "${BUILDKITE_ENV_FILE}" echo "VAR2=lalala" >> "${BUILDKITE_ENV_FILE}" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -e \* -e \* -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with vars \${12} and \${14}" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -e \* -e \* -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with vars \${11} and \${13}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -336,7 +278,7 @@ cmd3" assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice" assert_output --partial "ran myservice with vars VAR0 and VAR2" - unstub docker + unstub docker-compose unstub buildkite-agent rm "${BUILDKITE_ENV_FILE}" @@ -351,10 +293,10 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -364,7 +306,7 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -378,10 +320,10 @@ cmd3" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml : exit 0" \ @@ -391,7 +333,7 @@ cmd3" assert_success assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -406,10 +348,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo pulled myservice" \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo pulled myservice" \ + "-f tests/composefiles/docker-compose.v2.0.yml -f tests/composefiles/docker-compose.v2.1.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml-tests/composefiles/docker-compose.v2.1.yml : exit 0" \ @@ -419,7 +361,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -433,10 +375,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f tests/composefiles/docker-compose.v2.0.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-tests/composefiles/docker-compose.v2.0.yml : exit 0" \ @@ -446,7 +388,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -459,8 +401,8 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -470,7 +412,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "Exited with 2" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -484,11 +426,11 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PULL_RETRIES=3 - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : exit 2" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -499,7 +441,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "pulled myservice" assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -513,10 +455,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TTY=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without tty" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without tty" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -526,7 +468,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without tty" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -540,9 +482,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_DEPENDENCIES=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --no-deps --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without dependencies" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --no-deps --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without dependencies" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -552,7 +494,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without dependencies" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -566,9 +508,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_PRE_RUN_DEPENDENCIES=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with dependencies" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with dependencies" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -578,8 +520,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with dependencies" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -593,10 +534,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ANSI=false - stub docker \ - "compose --no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose --no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose --no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without ansi output" + stub docker-compose \ + "--no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "--no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "--no-ansi -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without ansi output" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -606,7 +547,34 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without ansi output" - unstub docker + unstub docker-compose + unstub buildkite-agent +} + + +@test "Run without pull" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND=pwd + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SKIP_PULL=true + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without pull" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "Running /bin/sh -e -c 'pwd' in service myservice" + assert_output --partial "ran myservice without pull" + + unstub docker-compose unstub buildkite-agent } @@ -620,10 +588,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_USE_ALIASES=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --use-aliases --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --use-aliases --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -633,11 +601,10 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with use aliases output" - unstub docker + unstub docker-compose unstub buildkite-agent } - @test "Run with compatibility mode" { export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd @@ -648,10 +615,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COMPATIBILITY=true - stub docker \ - "compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose --compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" + stub docker-compose \ + "--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "--compatibility -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with use aliases output" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -661,7 +628,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with use aliases output" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -676,10 +643,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="./dist:/app/dist" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="./pkg:/app/pkg" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v $PWD/dist:/app/dist -v $PWD/pkg:/app/pkg -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v $PWD/dist:/app/dist -v $PWD/pkg:/app/pkg -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -689,7 +656,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -703,10 +670,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES="buildkite:/buildkite" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -716,7 +683,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -733,10 +700,43 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_DOCKER_DEFAULT_VOLUMES="buildkite:/buildkite; ./dist:/app/dist;; ; ;" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "ran myservice with volumes" + unstub docker-compose + unstub buildkite-agent +} + +@test "Run with volumes with variables" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND=pwd + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="\$SUPER_VARIABLE:/mnt" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="/:\$OTHER_VARIABLE" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_2="\$RELATIVE_VARIABLE:/srv" + + export SUPER_VARIABLE='/test/path' + export OTHER_VARIABLE='/path/tested' + export RELATIVE_VARIABLE='./path' + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v \\\$SUPER_VARIABLE:/mnt -v /:\\\$OTHER_VARIABLE -v \\\$RELATIVE_VARIABLE:/srv -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -746,7 +746,78 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker + unstub docker-compose + unstub buildkite-agent +} + + +@test "Run with volumes with variables but option turned off" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND=pwd + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_EXPAND_VOLUME_VARS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="\$SUPER_VARIABLE:/mnt" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="/:\$OTHER_VARIABLE" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_2="\$RELATIVE_VARIABLE:/srv" + + + export SUPER_VARIABLE='/test/path' + export OTHER_VARIABLE='/path/tested' + export RELATIVE_VARIABLE='./path' + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v \\\$SUPER_VARIABLE:/mnt -v /:\\\$OTHER_VARIABLE -v \\\$RELATIVE_VARIABLE:/srv -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "ran myservice with volumes" + unstub docker-compose + unstub buildkite-agent +} + +@test "Run with volumes with variables and option turned on" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND=pwd + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=true + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_EXPAND_VOLUME_VARS=true + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_0="\$SUPER_VARIABLE:/mnt" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_1="/:\$OTHER_VARIABLE" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_VOLUMES_2="\$RELATIVE_VARIABLE:/srv" + + + export SUPER_VARIABLE='/test/path' + export OTHER_VARIABLE='/path/tested' + export RELATIVE_VARIABLE='./path' + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v /test/path:/mnt -v /:/path/tested -v $PWD/path:/srv -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "ran myservice with volumes" + unstub docker-compose unstub buildkite-agent } @@ -760,10 +831,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_DOCKER_DEFAULT_VOLUMES="buildkite:/buildkite;./dist:/app/dist" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -v buildkite:/buildkite -v $PWD/dist:/app/dist -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with volumes" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -773,7 +844,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with volumes" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -789,9 +860,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG_1="llamas2.yml" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CONFIG_2="llamas3.yml" - stub docker \ - "compose -f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f llamas1.yml -f llamas2.yml -f llamas3.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice-llamas1.yml-llamas2.yml-llamas3.yml : exit 1" @@ -800,8 +871,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -814,9 +884,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : exit 2" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : exit 2" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -826,7 +896,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "^^^ +++" assert_output --partial "Failed to run command, exited with 2" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -841,10 +911,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull --parallel myservice1 myservice2 : echo pulled myservice1 and myservice2" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice1=0 myservice1 : echo started dependencies for myservice1" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice1_build_1 -T --rm myservice1 /bin/sh -e -c 'pwd' : echo ran myservice1" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull --parallel myservice1 myservice2 : echo pulled myservice1 and myservice2" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice1=0 myservice1 : echo started dependencies for myservice1" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice1_build_1 -T --rm myservice1 /bin/sh -e -c 'pwd' : echo ran myservice1" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice1 : exit 0" \ @@ -857,7 +927,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "pulled myservice1 and myservice2" assert_output --partial "ran myservice1" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -871,9 +941,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_USER="1000" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -882,8 +952,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -897,9 +966,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_USER="1000:1001" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000:1001 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --user=1000:1001 --rm myservice /bin/sh -e -c $'sh -c \'whoami\'' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -908,8 +977,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -936,7 +1004,7 @@ export BUILDKITE_JOB_ID=1111 } -@test "Run without --rm" { +@test "Run without -T --rm" { export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test @@ -945,11 +1013,12 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RM=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_TTY=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : echo myimage" \ @@ -959,7 +1028,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without tty" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -973,9 +1042,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_ENTRYPOINT="my custom entrypoint" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm --entrypoint 'my custom entrypoint' myservice : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm --entrypoint 'my custom entrypoint' myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -984,8 +1053,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -999,9 +1067,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_BUILDKITE_AGENT=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e BUILDKITE_JOB_ID -e BUILDKITE_BUILD_ID -e BUILDKITE_AGENT_ACCESS_TOKEN -v $BATS_MOCK_TMPDIR/bin/buildkite-agent:/usr/bin/buildkite-agent myservice : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e BUILDKITE_JOB_ID -e BUILDKITE_BUILD_ID -e BUILDKITE_AGENT_ACCESS_TOKEN -v $BATS_MOCK_TMPDIR/bin/buildkite-agent:/usr/bin/buildkite-agent myservice : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1010,8 +1078,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1026,9 +1093,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_NO_CACHE=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_BUILD_PARALLEL=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1037,8 +1104,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1052,9 +1118,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_REPO_MIRROR=/tmp/sample-mirror - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -v /tmp/sample-mirror:/tmp/sample-mirror:ro -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -v /tmp/sample-mirror:/tmp/sample-mirror:ro -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1063,8 +1129,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1079,9 +1144,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_SSH_AGENT=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/root/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/root/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1091,12 +1156,12 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command + assert_success + kill %1 - assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1111,9 +1176,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_SSH_AGENT=/tmp/test - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/tmp/test/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm -e SSH_AUTH_SOCK=/ssh-agent -v /tmp/ssh_auth_sock:/ssh-agent -v /root/.ssh/known_hosts:/tmp/test/.ssh/known_hosts myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1123,30 +1188,29 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command + assert_success + kill %1 - assert_success assert_output --partial "ran myservice" - - unstub docker + unstub docker-compose unstub buildkite-agent } @test "Run without mount-checkout doesn't set volume" { - export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd - - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without mount-checkout" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice without mount-checkout" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1156,26 +1220,24 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without mount-checkout" - - unstub docker + unstub docker-compose unstub buildkite-agent } @test "Run with mount-checkout set to true" { - export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd - - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T --workdir=/workdir -v /plugin:/workdir --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --workdir=/workdir -v $PWD:/workdir --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1185,27 +1247,25 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with mount-checkout" - - unstub docker + unstub docker-compose unstub buildkite-agent } @test "Run with mount-checkout set to true with custom workdir" { - export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 export BUILDKITE_COMMAND=pwd - - export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT=true export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR="/custom_workdir" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T \* -v \* --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout on \${14}" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --workdir=$BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR -v $PWD:$BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1214,9 +1274,8 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command assert_success - assert_output --partial "ran myservice with mount-checkout on /plugin:/custom_workdir" - - unstub docker + assert_output --partial "ran myservice with mount-checkout" + unstub docker-compose unstub buildkite-agent } @@ -1231,10 +1290,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="/special" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T -v \* --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout on \${13}" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T -v \* --rm myservice /bin/sh -e -c 'pwd' : echo ran myservice with mount-checkout on \${12}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1245,7 +1304,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice with mount-checkout on /plugin:/special" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1261,10 +1320,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="/special" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR="/custom_workdir" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T \* -v \* --rm myservice /bin/sh -e -c 'pwd' : echo echo ran myservice with mount-checkout on \${14}" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f \* up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f \* run --name buildkite1111_myservice_build_1 -T \* -v \* --rm myservice /bin/sh -e -c 'pwd' : echo echo ran myservice with mount-checkout on \${13}" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1276,7 +1335,7 @@ export BUILDKITE_JOB_ID=1111 assert_output --partial "ran myservice with mount-checkout on /plugin:/special" assert_output --partial "--workdir=/custom_workdir" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1291,8 +1350,8 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="not_absolute" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1303,7 +1362,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "mount-checkout should be either true or an absolute path to use as a mountpoint" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1319,8 +1378,8 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_MOUNT_CHECKOUT="not-absolute" export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WORKDIR="/custom_workdir" - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f \* pull myservice : echo pulled myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 0" \ @@ -1331,7 +1390,7 @@ export BUILDKITE_JOB_ID=1111 assert_failure assert_output --partial "mount-checkout should be either true or an absolute path to use as a mountpoint" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1345,9 +1404,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_WAIT=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up --wait -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up --wait -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1355,9 +1414,10 @@ export BUILDKITE_JOB_ID=1111 run "$PWD"/hooks/command assert_success + assert_output --partial "Starting dependencies" assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1371,10 +1431,10 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_SERVICE_PORTS=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ - "compose -f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm --service-ports myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 -T --rm --service-ports myservice /bin/sh -e -c $'pwd' : echo ran myservice without tty" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : echo myimage" \ @@ -1384,7 +1444,49 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice without tty" - unstub docker + unstub docker-compose + unstub buildkite-agent +} + +@test "Run with Docker labels" { + # Pipeline vars + export BUILDKITE_AGENT_ID="1234" + export BUILDKITE_AGENT_NAME="agent" + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND=pwd + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_LABEL="Testjob" + export BUILDKITE_PIPELINE_NAME="label-test" + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_STEP_KEY="test-job" + + # Plugin config + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN_LABELS="true" + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml pull myservice : echo pulled myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml up -d --scale myservice=0 myservice : echo started dependencies for myservice" \ + "-f docker-compose.yml -p buildkite1111 -f docker-compose.buildkite-1-override.yml run --name buildkite1111_myservice_build_1 \ + --label com.buildkite.pipeline_name=${BUILDKITE_PIPELINE_NAME} \ + --label com.buildkite.pipeline_slug=${BUILDKITE_PIPELINE_SLUG} \ + --label com.buildkite.build_number=${BUILDKITE_BUILD_NUMBER} \ + --label com.buildkite.job_id=${BUILDKITE_JOB_ID} \ + --label com.buildkite.job_label=${BUILDKITE_LABEL} \ + --label com.buildkite.step_key=${BUILDKITE_STEP_KEY} \ + --label com.buildkite.agent_name=${BUILDKITE_AGENT_NAME} \ + --label com.buildkite.agent_id=${BUILDKITE_AGENT_ID} \ + -T --rm myservice /bin/sh -e -c $'pwd' : echo ran myservice" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : echo myimage" \ + "meta-data get docker-compose-plugin-built-image-tag-myservice : echo myimage" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "ran myservice" + unstub docker-compose unstub buildkite-agent } @@ -1398,9 +1500,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_QUIET_PULL=true - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up --quiet-pull -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up --quiet-pull -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1411,7 +1513,7 @@ export BUILDKITE_JOB_ID=1111 refute_output --partial "Pulling" assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1426,9 +1528,9 @@ export BUILDKITE_JOB_ID=1111 export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false - stub docker \ - "compose -f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ - "compose -f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e VAR_A -e VAR_B -e VAR_C -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -e VAR_A -e VAR_B -e VAR_C -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" stub buildkite-agent \ "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" @@ -1437,7 +1539,7 @@ export BUILDKITE_JOB_ID=1111 assert_success assert_output --partial "ran myservice" - unstub docker + unstub docker-compose unstub buildkite-agent } @@ -1460,3 +1562,52 @@ export BUILDKITE_JOB_ID=1111 assert_output --partial "env-propagation-list desired, but LIST_OF_VARS is not defined!" unstub buildkite-agent } + +@test "Run with expanded run log group by default" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND="echo hello world" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "+++ :docker: Running /bin/sh -e -c 'echo hello world' in service myservice" + unstub docker-compose + unstub buildkite-agent +} + +@test "Run with collapsed run log group" { + export BUILDKITE_JOB_ID=1111 + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_RUN=myservice + export BUILDKITE_PIPELINE_SLUG=test + export BUILDKITE_BUILD_NUMBER=1 + export BUILDKITE_COMMAND="echo hello world" + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CHECK_LINKED_CONTAINERS=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_CLEANUP=false + export BUILDKITE_PLUGIN_DOCKER_COMPOSE_COLLAPSE_LOGS=true + + stub docker-compose \ + "-f docker-compose.yml -p buildkite1111 up -d --scale myservice=0 myservice : echo ran myservice dependencies" \ + "-f docker-compose.yml -p buildkite1111 run --name buildkite1111_myservice_build_1 -T --rm myservice /bin/sh -e -c 'echo hello world' : echo ran myservice" + + stub buildkite-agent \ + "meta-data exists docker-compose-plugin-built-image-tag-myservice : exit 1" + + run "$PWD"/hooks/command + + assert_success + assert_output --partial "--- :docker: Running /bin/sh -e -c 'echo hello world' in service myservice" + unstub docker-compose + unstub buildkite-agent +}