Commit Graph

114 Commits

Author SHA1 Message Date
Sebastiaan van Stijn 3bed830a27
cli/compose: use strings.Cut
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-12-29 15:19:31 +01:00
Sebastiaan van Stijn 37dcee37b6
Merge pull request #3812 from mspiess/3293-fix-replicas-override-0
add ability to override ints in compose files with 0
2022-12-05 16:26:44 +01:00
Sebastiaan van Stijn 4d2fb68b93
cli/compose/loader: fix error messages, and various tests
Various fixes:

- Don't capitalize error messages
- Rename variables that collided with imports or types
- Prefer assert.Check over assert.Assert to prevent tests covering multiple
  cases from failing early
- Fix inconsistent order of expected <--> actual, which made it difficult to
  check which output was the expected output.
- Fix formatting of some comments

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-17 13:17:51 +01:00
Sebastiaan van Stijn c18dd2719e
cli/compose/loader: TestMarshallConfig: fix duplicate version
The version was originally added in 570ee9cb54,
at the time the `expected` config did not have a `version:` field. A later
refactor in 0cf2e6353a updated the `expected`
config to have a `version:` included. However, the test was not updated,
which now resulted in the test using a compose file with a duplicate version
field:

    version: '3.10'
    version: "3.10"
      services:
        foo:
          build:

This issue was masked by `yaml.Unmarshal()` from `gopkg.in/yaml.v2` which
silently ignores the duplicate, taking the value of the last occurrence. When
upgrading to `gopkg.in/yaml.v3`, the duplicate value resulted in an error:

    yaml: unmarshal errors:
        line 2: mapping key "version" already defined at line 1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-11-17 13:17:50 +01:00
Sebastiaan van Stijn 8a19043cc7
Merge pull request #3798 from thaJeztah/gofumpt_linting
Use gofumpt if available, and enable gofumpt linter
2022-11-04 19:04:51 +01:00
Drew Erny 02e7826923 Add compose support for cluster volumes
Signed-off-by: Drew Erny <derny@mirantis.com>
2022-11-02 11:27:06 -05:00
mspiess 68330e099a add ability to override ints in compose files with 0
Signed-off-by: Marco Spiess <marco.spiess@hotmail.de>
2022-10-12 20:57:46 +02:00
Sebastiaan van Stijn 616124525e
format go with gofumpt (with -lang=1.19)
Looks like the linter uses an explicit -lang, which (for go1.19)
results in some additional formatting for octal values.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-30 19:14:36 +02:00
Sebastiaan van Stijn 1da95ff6aa
format code with gofumpt
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-30 11:59:11 +02:00
Sebastiaan van Stijn a9ccb6552d
cli/compose: remove redundant reflection from tests
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-09-29 15:35:31 +02:00
Sebastiaan van Stijn 82427d1a07
format (GoDoc) comments with Go 1.19 to prepare for go updates
Older versions of Go do not format these comments, so we can already
reformat them ahead of time to prevent gofmt linting failing once
we update to Go 1.19 or up.

Result of:

    gofmt -s -w $(find . -type f -name '*.go' | grep -v "/vendor/")

With some manual adjusting.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-07-19 19:10:16 +02:00
Stoica-Marcu Floris-Andrei cff702d889
Add merge to ShellCommand properties in config
Signed-off-by: Stoica-Marcu Floris-Andrei <floris.sm@gmail.com>
2022-04-08 14:56:14 +02:00
Stoica-Marcu Floris-Andrei fbea85d472
Change merge strategy for service volumes
Signed-off-by: Stoica-Marcu Floris-Andrei <floris.sm@gmail.com>
2022-04-08 14:56:11 +02:00
Sebastiaan van Stijn 60c3836365
cli/compose/schema: make version: "3" equivalent to "3.x" (latest)
Previously, `version: "3"` was equivalent to `version: "3.0"`, which
caused confusion for many users, as they expected it to be "3.x".

docker-compose and docker compose (v2) have adopted the compose-spec
(https://compose-spec.io), which no longer has a version field in
the compose file, and always picks the "latest" supported version.

This changes how `docker stack` interprets "major" version numbers
specified in compose-files:

When only the major version ("3") is specified, it is now equivalent
to "3.x" (latest supported v3 schema).

Compose-files that specify both major and minor version (e.g. "3.0"
or "3.1") continue to use the existing behavior; validation is down-
graded to the specified version and will produce an error if options
are used that are not supported in that schema version. This allows
users to locally verify that a composse-file does not use options
that are not supported in the intended deployment environment (for
example if the deploy environment only supports older versions of
the schema).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-01 09:40:33 +01:00
Sebastiaan van Stijn 6c75b75aaa
Merge pull request #3257 from thaJeztah/compose_remove_required_version
cli/compose: add schema 3.10, with optional version field (default to "latest")
2022-02-25 19:47:55 +01:00
Sebastiaan van Stijn b9f0340b68
cli/compose: remove deprecated io/ioutil
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-25 15:42:15 +01:00
Sebastiaan van Stijn a7778806a0
cli/compose/schema: make version optional, default to "latest"
The compose spec (https://compose-spec.io) defines the version to be optional,
and implementations of the spec to check for supported attributes instead.

While this change does not switch the `docker stack` implementation to use the
compose-spec, it makes it function more similar. Previously, omitting a version
number would either produce an error (as the field was required), or switched
the handling to assume it was version 1.0 (which is deprecated).

With this change, compose files without a version number will be handled as
the latest version supported by `docker stack` (currently 3.10). This allows
users that work with docker-compose or docker compose (v2) to deploy their
compose file, without having to re-add a version number. Fields that are
not supported by stackes (schema 3.10) will still produce an error.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-18 12:26:04 +01:00
Sebastiaan van Stijn 251861237a
Replace mattn/go-shellwords with google/shlex
Both libaries provide similar functionality. We're currently using
Google Shlex in more places, so prefering that one for now, but we
could decide to switch to mattn/go-shellwords in future if that
library is considered better (it looks to be more actively maintained,
but that may be related to it providing "more features").

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-07-20 10:20:42 +02:00
Sebastiaan van Stijn 851eeb9639
Add support for pids limit in stacks (swarm)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-06-18 21:25:08 +02:00
Sebastiaan van Stijn 0c5f97ed72
compose: add build.extra_hosts to v3.9 schema
This is not currently used by the CLI, but can be used by
docker compose to bring parity on this feature with the
compose v2.4 schema.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-05-10 20:01:03 +02:00
Sebastiaan van Stijn f88ae74135
Add "host-gateway" to tests for extra_hosts / --add-host
67ebcd6dcf added an exception for
the "host-gateway" magic value to the validation rules, but didn't
add thise value to any of the tests.

This patch adds the magic value to tests, to verify the validation
is skipped for this magic value.

Note that validation on the client side is "optional" and mostly
done to provide a more user-friendly error message for regular
values (IP-addresses).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-04-15 09:52:55 +02:00
Silvin Lubecki 30d6ee997b
Merge pull request #2357 from thaJeztah/gofmt_test
gofmt compose loader test
2020-02-26 15:23:57 +01:00
Sebastiaan van Stijn 2c0e93063b
bump gotest.tools v3.0.1 for compatibility with Go 1.14
full diff: https://github.com/gotestyourself/gotest.tools/compare/v2.3.0...v3.0.1

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-23 00:28:55 +01:00
Sebastiaan van Stijn 5ef0fa10de
gofmt compose loader test
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-22 18:22:27 +01:00
Sebastiaan van Stijn 11869fa42a
fix panic on single-character volumes
Before this change, this would cause a panic:

    docker run -it --rm -v 1:/1 alpine
    panic: runtime error: index out of range

    goroutine 1 [running]:
    github.com/docker/cli/cli/compose/loader.isFilePath(0xc42027e058, 0x1, 0x557dcb978c20)
    ...

After this change, a correct error is returned:

    docker run -it --rm -v 1:/1 alpine
    docker: Error response from daemon: create 1: volume name is too short, names should be at least two alphanumeric characters.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-02-21 01:38:52 +01:00
Nick Adcock 4006c42e13 Added transforms for compose overrides
Added transforms for when merging compose overrides to preserve the
functionality that was broken by bumping mergo to v1.3.8

This includes:
- Special transform for ulimits so single overrides both soft/hard and
the reverse
- Special transform for service network configs so the override replaces
all aliases

Signed-off-by: Nick Adcock <nick.adcock@docker.com>
2020-01-24 15:52:36 +00:00
Djordje Lukic cb29ef6c6d Add interpolation type cast for max_replicas_per_node
Fixes https://github.com/docker/app/issues/688

Signed-off-by: Djordje Lukic <djordje.lukic@docker.com>
2019-11-05 08:31:36 +01:00
Sebastiaan van Stijn 96ec7299d8
cli/compose/loader: Using a reference for the variable on range scope `overrideService` (scopelint)
```
cli/compose/loader/merge.go:64:41: Using a reference for the variable on range scope `overrideService` (scopelint)
			if err := mergo.Merge(&baseService, &overrideService, mergo.WithAppendSlice, mergo.WithOverride, mergo.WithTransformers(specials)); err != nil {
			                                     ^
cli/compose/loader/loader_test.go:1587:28: Using the variable on range scope `testcase` in function literal (scopelint)
			config, err := loadYAML(testcase.yaml)
			                        ^
cli/compose/loader/loader_test.go:1590:58: Using the variable on range scope `testcase` in function literal (scopelint)
			assert.Check(t, is.DeepEqual(config.Services[0].Init, testcase.init))
			                                                      ^
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22:34 +01:00
Sebastiaan van Stijn 9118b2b2b8
compose/loader: define type for transformer-functions
Also explicitly type transformer-functions

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22:21 +01:00
Silvin Lubecki 6eb0c9c613
disable unparam linter on these functions, as we need an error in these function signatures
cli/compose/loader/loader.go:756:66: transformServiceNetworkMap - result 1 (error) is always nil (unparam)
cli/compose/loader/loader.go:767:67: transformStringOrNumberList - result 1 (error) is always nil (unparam)

Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22:21 +01:00
Sebastiaan van Stijn 0a21de05d2
compose/loader: fix TestIsAbs not testing all combinations
This test was intending to run all tests, but didn't, which was
caught by golangci-lint;

    cli/compose/loader/windows_path_test.go:46:17: SA4010: this result of append is never used, except maybe in other appends (staticcheck)
    	tests := append(isabstests, winisabstests...)
    	               ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-29 15:02:23 +01:00
Ulysses Souza 821f5ecf53 Add option remove `env_file` entry after merged
This avoids having a redundant `env_file` entry
output when rendering the compose file

Signed-off-by: Ulysses Souza <ulysses.souza@docker.com>
2019-09-23 17:40:45 +02:00
Sebastiaan van Stijn 5bc1f24dfd
Add docker-compose schema v3.9
This is currently just a copy of the v3.8 schema, in preparation
of new features to be added in the new schema.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-08-30 10:58:05 +02:00
Sebastiaan van Stijn d6dd08d568
Detect Windows absolute paths on non-Windows CLI
When deploying a stack using a relative path as bind-mount
source in the compose file, the CLI converts the relative
path to an absolute path, relative to the location of the
docker-compose file.

This causes a problem when deploying a stack that uses
an absolute Windows path, because a non-Windows client will
fail to detect that the path (e.g. `C:\somedir`) is an absolute
path (and not a relative directory named `C:\`).

The existing code did already take Windows clients deploying
a Linux stack into account (by checking if the path had a leading
slash). This patch adds the reverse, and adds detection for Windows
absolute paths on non-Windows clients.

The code used to detect Windows absolute paths is copied from the
Golang filepath package;
1d0e94b1e1/src/path/filepath/path_windows.go (L12-L65)

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-07-10 21:25:03 +02:00
Silvin Lubecki efdf36fa81 Rollback config type interpolation on fields "parallelism" and "max_failure_ratio" were missing, as it uses the same type as update_config.
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
2019-07-03 17:23:33 +02:00
Sebastiaan van Stijn 6511da877f Add support for using Configs as CredentialSpecs in services
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-04-12 11:17:29 -05:00
Sune Keller ed838bff1f Add test case
Signed-off-by: Sune Keller <absukl@almbrand.dk>
2019-04-05 12:01:21 +02:00
Sune Keller c662ba03de Make use of driver and driver_opts fields in secrets
Signed-off-by: Sune Keller <absukl@almbrand.dk>
2019-04-05 12:01:21 +02:00
Sebastiaan van Stijn f620349837
Add systctl support for services
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-19 13:33:32 +01:00
Vincent Demeester 7764101a54
Add support for `template_driver` in composefiles
This maps the `--template-driver` flag on secret and config creation.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-18 23:49:30 +01:00
Sebastiaan van Stijn cfe12f4135
Merge pull request #1410 from olljanat/replicas-max-per-node
Add maximum replicas per node support to stack version 3.8
2019-02-20 13:22:18 +01:00
Olli Janatuinen 6347ab315b Add maximum replicas per node support to stack version 3.8
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
2019-02-19 11:25:12 +02:00
Sebastiaan van Stijn 1e99ed3ca3
Disallow additional properties in credential_spec
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-02-02 18:27:50 +01:00
Mindaugas Rukas 83fd688fa2 Allow to transform any source type into the target struct
Signed-off-by: Mindaugas Rukas <momomg@gmail.com>
2018-10-02 16:06:08 +03:00
Joffrey F e7788d6f9a Allow marshalling of Compose config to JSON
Signed-off-by: Joffrey F <joffrey@docker.com>
2018-09-10 11:16:05 -07:00
Vincent Demeester 0246bc1b3b
Exposes compose `loader.Transform` function…
This should make it easier for people to write custom composefile
parser without duplicating too much code. It takes the default
transformers and any additional number of transformer for any
types. That way it's possible to transform a `cli/compose` map into a
custom type that would use some of `cli/compose` types and its own.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-07-31 09:37:09 +02:00
Arash Deshmeh 71d650ee17 refactored cli/compose and cli/command/trust to use sort.Slice and removed custom types used for sorting
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-07-08 15:08:17 -04:00
Vincent Demeester 9fdd14f399
Add options to the compose loader
- Add the possibility to skip interpolation
- Add the possibility to skip schema validation
- Allow customizing the substitution function, to add special cases.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-25 17:15:26 +02:00
Silvin Lubecki 38056740d6 Refactor tests
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
2018-06-25 11:13:32 +02:00
Vincent Demeester cc26da94ed Add `init` support in 3.7 schema
> Run an init inside the container that forwards signals and reaps
  processes

This is supported on `run` and now on Swarm services too, so it's also
possible to have in on a composefile :).

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-25 11:13:32 +02:00