Commit Graph

242 Commits

Author SHA1 Message Date
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 4ab70bf61e
linting: fix incorrectly formatted errors (revive)
cli/compose/interpolation/interpolation.go:102:4: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
                "invalid interpolation format for %s: %#v. You may need to escape any $ with another $.",
                ^

    cli/command/stack/loader/loader.go:30:30: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
                return nil, errors.Errorf("Compose file contains unsupported options:\n\n%s\n",
                                          ^

    cli/command/formatter/formatter.go:76:30: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
            return tmpl, errors.Errorf("Template parsing error: %v\n", err)
                                       ^

    cli/command/formatter/formatter.go:97:24: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
            return errors.Errorf("Template parsing error: %v\n", err)
                                 ^

    cli/command/image/build.go:257:25: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
                return errors.Errorf("error checking context: '%s'.", err)
                                     ^

    cli/command/volume/create.go:35:27: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
                        return errors.Errorf("Conflicting options: either specify --name or provide positional arg, not both\n")
                                             ^

    cli/command/container/create.go:160:24: error-strings: error strings should not be capitalized or end with punctuation or a newline (revive)
            return errors.Errorf("failed to remove the CID file '%s': %s \n", cid.path, err)
                                 ^

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-03-28 10:37:25 +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 a9fd697737
cli/compose: add schema 3.10 (no changes with 3.9 yet)
Adding a copy of the 3.9 schema, with only the version-string changed.
This makes it easier to find changes since 3.9, which are added after
this.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-18 12:26:02 +01:00
Sebastiaan van Stijn d44eca129f
cli/compose/schema: Validate(): normalize version before validating
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2022-02-18 12:26:00 +01:00
Sebastiaan van Stijn 818564af51
cli/compose: use go1.16 native embed functionality for schemas
This allows us to drop the `//go:generate` and use of the github.com/mjibson/esc
utility.

worth noting that Go's native "embed" does not compress files. We could compress
these files as part of a build / validate step (which would add some complexity
when updating these files) if this is a concern, but not sure if the additional
complexity is warranted.

Comparing before/after sizes (see below);

    macOS: 54125840 - 54005264 = 120576 (+120.58 kB)
    Linux: 52393231 - 52277701 = 115530 (+115.53 kB)

Before:

    ls -l build/
    total 208736
    lrwxr-xr-x  1 sebastiaan  staff        19 Aug 15 09:36 docker@ -> docker-linux-amd64
    -rwxr-xr-x  1 sebastiaan  staff  54005264 Aug 15 09:35 docker-darwin-amd64*
    -rwxr-xr-x  1 sebastiaan  staff  52277701 Aug 15 09:36 docker-linux-amd64*

After:

    ls -l build/
    total 208960
    lrwxr-xr-x  1 sebastiaan  staff        18 Aug 15 09:32 docker@ -> docker-linux-amd64
    -rwxr-xr-x  1 sebastiaan  staff  54125840 Aug 15 09:31 docker-darwin-amd64*
    -rwxr-xr-x  1 sebastiaan  staff  52393231 Aug 15 09:32 docker-linux-amd64*

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-08-15 10:04:13 +02:00
Albin Kerouanton 940907951b
Support ulimits in docker stack deploy
This is related to moby/moby 40639.

Signed-off-by: Albin Kerouanton <albin@akerouanton.name>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-10 14:59:02 +02:00
Sebastiaan van Stijn 190c64b415
Service cap-add/cap-drop: improve handling of combinations and special "ALL" value
When creating and updating services, we need to avoid unneeded service churn.

The interaction of separate lists to "add" and "drop" capabilities, a special
("ALL") capability, as well as a "relaxed" format for accepted capabilities
(case-insensitive, `CAP_` prefix optional) make this rather involved.

This patch updates how we handle `--cap-add` / `--cap-drop` when  _creating_ as
well as _updating_, with the following rules/assumptions applied:

- both existing (service spec) and new (values passed through flags or in
  the compose-file) are normalized and de-duplicated before use.
- the special "ALL" capability is equivalent to "all capabilities" and taken
  into account when normalizing capabilities. Combining "ALL" capabilities
  and other capabilities is therefore equivalent to just specifying "ALL".
- adding capabilities takes precedence over dropping, which means that if
  a capability is both set to be "dropped" and to be "added", it is removed
  from the list to "drop".
- the final lists should be sorted and normalized to reduce service churn
- no validation of capabilities is handled by the client. Validation is
  delegated to the daemon/server.

When deploying a service using a docker-compose file, the docker-compose file
is *mostly* handled as being "declarative". However, many of the issues outlined
above also apply to compose-files, so similar handling is applied to compose
files as well to prevent service churn.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-09-08 14:38:35 +02:00
Olli Janatuinen 0db61ff6da
stack: Support cap_add and cap_drop on services
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
Signed-off-by: Albin Kerouanton <albin@akerouanton.name>
2020-09-08 14:24:52 +02: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 0d57a400b3
vendor: docker/docker aaf470eca7b588aa19e6681bff8bf08d17be1bf2
full diff: 41ac6bef8d...aaf470eca7

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-06-15 13:32:53 +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
Rob Gulewich 5ad1d4d4c8 docker run: specify cgroup namespace mode with --cgroupns
Signed-off-by: Rob Gulewich <rgulewich@netflix.com>
2020-01-29 22:50:37 +00:00
Sebastiaan van Stijn 97010520d4
bump mjibson/esc v0.2.0
full diff: https://github.com/mjibson/esc/compare/v0.1.0...v0.2.0

includes:

- mjibson/esc#51 Readdir Implementation - and covering with tests
- mjibson/esc#53 update go versions and golint import location
- mjibson/esc#58 Avoid unnecessary conversion and so pass with unconvert linter

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2020-01-27 17:40:56 +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 aafe3df8b3
cli/compose/template: Using the variable on range scope `tc` in function literal (scopelint)
```
cli/compose/template/template_test.go:279:31: Using the variable on range scope `tc` in function literal (scopelint)
			actual := ExtractVariables(tc.dict, defaultPattern)
			                           ^
cli/compose/template/template_test.go:280:41: Using the variable on range scope `tc` in function literal (scopelint)
			assert.Check(t, is.DeepEqual(actual, tc.expected))
			                                     ^
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22:38 +01:00
Sebastiaan van Stijn 612d83d6df
cli: remove unnecessary newlines (whitespace)
```
cli/config/config_test.go:465: unnecessary trailing newline (whitespace)

}
cli/compose/interpolation/interpolation.go:56: unnecessary leading newline (whitespace)
	switch value := value.(type) {

cli/compose/interpolation/interpolation.go:94: unnecessary trailing newline (whitespace)

	}
cli/command/image/build/context.go:348: unnecessary trailing newline (whitespace)

		}
internal/licenseutils/client_test.go:98: unnecessary leading newline (whitespace)
func (c *fakeLicensingClient) LoadLocalLicense(ctx context.Context, dclnt licensing.WrappedDockerClient) (*model.Subscription, error) {

cli/registry/client/fetcher.go:211: unnecessary leading newline (whitespace)
	for _, endpoint := range endpoints {
```

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22: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 34f595975d
cli/compose/convert: driverObjectConfig - result 1 (error) is always nil (unparam)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-31 19:22:26 +01:00
Silvin Lubecki c237379167
cli/compose/convert/service_test.go:274:72: unnecessary conversion (unconvert)
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
2019-10-31 19:22:24 +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
Silvin Lubecki d640f44df3
cli/compose/convert: result 1 (error) is always nil (unparam)
cli/compose/convert/service.go:592:76: convertDNSConfig - result 1 (error) is always nil (unparam)
cli/compose/convert/service.go:538:110: convertEndpointSpec - 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:20 +01:00
Silvin Lubecki 1bfe81318d
cli/compose/types/types.go:106:2: structtag: struct field tag `yaml:",inline", json:"-"` not compatible with reflect.StructTag.Get: key:"value" pairs not separated by spaces (govet)
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
2019-10-31 19:22:14 +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
Sebastiaan van Stijn 06f34ba507
bump github.com/xeipuuv/gojsonschema v1.1.0
full diff: 93e72a773f...f971f3cd73

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-10-10 23:00:43 +02: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
Drew Erny 42ec51e1ae add support for config credentialspecs to compose
Signed-off-by: Drew Erny <drew.erny@docker.com>
2019-04-12 11:17:34 -05: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
Sune Keller 89f9d806ff Add driver and driver_opts to secret in compose schema 3.8
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 70846619a9
Update compose 3.8 to disallow additional properties
This was added in other schemas in 1e99ed3ca3,
but not coppied to version 3.8

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-18 12:56:16 +01:00
Sebastiaan van Stijn 0fc0015173
bump docker/docker to 8aca18d631f3f72d4c6e3dc01b6e5d468ad941b8
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2019-03-02 13:41:42 +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
Olli Janatuinen 1b8d1e23c5 Add compose schema version 3.8
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
2019-01-14 18:18:17 +02:00
JoeWrightss 9c9ce7f4c2 Fix some spelling errors
Signed-off-by: zhoulin xie <zhoulin.xie@daocloud.io>
2019-01-11 15:49:02 +08: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
Sebastiaan van Stijn 3e4e232e0d
Merge pull request #1195 from olljanat/34795-npipe-mount-type
Allow npipe volume type on stack file
2018-09-28 10:57:09 +02:00
Olli Janatuinen 0704d9a031 Allow npipe volume type on stack file
Signed-off-by: Olli Janatuinen <olli.janatuinen@gmail.com>
2018-09-27 18:47:20 +03:00
Sebastiaan van Stijn ec3daea021
Fix substitution with non-empty env-var
Due to a typo, substitution would not work if the given
environment-variable was set.

Given the following docker compose file;

```yaml
version: "3.7"

services:
  app:
    image: nginx:${version:-latest}
```

Deploying a stack with `$version` set would ignore the `$version`
environment variable, and use the default value instead;

```bash
version=alpine docker stack deploy -c docker-compose.yml foobar

Creating network foobar_default
Creating service foobar_app

docker service ls

ID                  NAME                MODE                REPLICAS            IMAGE               PORTS
rskkjxe6sm0w        foobar_app          replicated          1/1                 nginx:latest
```

This patch also fixes "soft default" not detecting empty environment variables,
only non-set environment variables.

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-09-25 22:20:25 +02: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 9cd7c1361c
Migrate `TestExtractVariables` to subtests…
… as suggested in previous PR comment.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-08-07 16:06:13 +02:00
Vincent Demeester 4c87725c35
Allow custom pattern when extracting variable…
… as it is possible to do it when interpolating. It also fixes when
there is 2 variables on the same *value* (in the composefile, on the
same line)

Finaly, renaming the default, used in cli, pattern to `defaultPattern`
to not be shadowed unintentionally.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-08-02 16:50:40 +02:00
Vincent Demeester afb87e42f2
Add a new `ExtractVariables` function to `compose/template` package
It allows to get easily all the variables defined in a
composefile (the `map[string]interface{}` representation that
`loader.ParseYAML` returns at least) and their default value too.

This commit also does some small function extract on substitution
funcs to reduce a tiny bit duplication.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-08-01 16:12:49 +02: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
Vincent Demeester d13e2df65b
Add missing fields in compose/types
Even though those fields are not supported by `docker stack deploy`
they are defined in versions `3.x` of compose schema, so the `compose`
package should be able to marshal/unmarshal them.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-07-26 17:04:22 +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
Silvin 18091ea7e2
Merge pull request #1170 from vdemeester/omit-silvin
Add omitempty on compose config top-level types
2018-07-02 14:16:53 +02:00
Vincent Demeester f05ab2b1fb
Add omitempty on compose config top-level types
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-07-02 12:04:09 +02:00
Silvin Lubecki 3a8ef767f8 Add a doc.go file so the compose/schema/data directory can be vendored in another project, without being pruned.
Signed-off-by: Silvin Lubecki <silvin.lubecki@docker.com>
2018-07-02 10:08:25 +02: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
Vincent Demeester 80c26f618e
Add an `Extras` field on the compose config types.
That field is automaticaly populated with any `x-*` field in the yaml.
And marshalling the compose config struct put them back into place.

This make it possible to get those extra fields without re-inventing
the wheel (i.e. reimplementing 80% of the `cli/compose/*` packages.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-25 10:51:56 +02:00
Vincent Demeester 2c4de4fb5e
Update tests to use gotest.tools 👼
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-08 18:24:26 +02:00
Sebastiaan van Stijn 90f8ce8a5d
Merge pull request #1104 from vdemeester/show-me-your-secret
Add more example to the full-example tests
2018-06-05 16:44:06 +02:00
Vincent Demeester 55426d9396
Add more example to the full-example tests
Configs and Secrets were note present, some labels on volumes and
networks too.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-06-01 14:16:18 +02:00
Vincent Demeester 6bcfa8806c
Allow `x-*` extension on 3rd level objects
As for top-level key, any 3rd-level key which starts with `x-` will be
ignored by compose. This allows for users to:
* include additional metadata in their compose files
* create YAML anchor objects that can be re-used in other parts of the config

This matches a similar feature in the swagger spec definition:
https://swagger.io/specification/#specificationExtensions

This means a composefile like the following is valid

```
verison: "3.7"
services:
  foo:
    image: foo/bar
    x-foo: bar
network:
  bar:
    x-bar: baz
```

It concerns services, volumes, networks, configs and secrets.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-05-31 13:38:58 +02:00
Vincent Demeester 4e6e5d583c
Support for rollback config in compose 3.7
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-05-29 11:37:51 +02:00
Vincent Demeester df6e38b81a
Add composefile schema 3.7
Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-05-29 11:37:12 +02:00
Kir Kolyshkin 6f8070deb2 Switch from x/net/context to context
Since go 1.7, "context" is a standard package. Since go 1.9,
x/net/context merely provides some types aliased to those in
the standard context package.

The changes were performed by the following script:

for f in $(git ls-files \*.go | grep -v ^vendor/); do
	sed -i 's|golang.org/x/net/context|context|' $f
	goimports -w $f
	for i in 1 2; do
		awk '/^$/ {e=1; next;}
			/\t"context"$/ {e=0;}
			{if (e) {print ""; e=0}; print;}' < $f > $f.new && \
				mv $f.new $f
		goimports -w $f
	done
done

[v2: do awk/goimports fixup twice]
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>
2018-05-11 16:49:43 -07:00
Vincent Demeester 0122730faf
Fix error with merge composefile with networks…
… and other cases too. Updating mergo fixes the bugs (but introduced a
slight behaviour change that had to be fixed too)

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-04-05 10:37:35 +02:00
Daniel Nephin b4c108a385 Fix named network in compose file
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-12 15:15:27 -04:00
Vincent Demeester 0cf2e6353a
Fixes some unit tests to be able to run them on windows
Some of them are skipped for now (because the feature is not supported
or needs more work), some of them are fixed.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-03-07 18:18:13 +01:00
Daniel Nephin e15b208e96 Convert assert.Check(t, is.Error()) to assert.Error
git grep -l -P '^\s+assert\.Check\(t, is\.Error\(' | \
    xargs perl -pi -e 's/^(\s+assert\.)Check\(t, is\.Error\((.*)\)$/\1Error(t, \2/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-06 16:00:28 -05:00
Daniel Nephin 078cbc9c4b Convert assert.Check with
git grep -l -P '^\s+assert\.Check\(t, ' | \
    xargs perl -pi -e 's/^(\s+assert)\.Check(\(t, (?!is).*(\.Execute\(|\.Set\(|\.Write\(|\.Close\(|\.Untar\(|\.WriteFile\(|Validate\().*\)$)/\1.NilError\2/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-06 15:43:53 -05:00
Daniel Nephin baf65a5502 Convert to assert.NilError
Using:

  git grep -l '^\s\+assert\.Check(t, err)$' | \
    xargs sed -i -e 's/^\(\s\+assert\)\.Check(t, err)$/\1.NilError(t, err)/'

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-06 15:27:34 -05:00
Daniel Nephin 681c921528 Remove testutil
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-06 14:38:35 -05:00
Daniel Nephin 5155cda716 Post migration fixes
Fix tests that failed when using cmp.Compare()
internal/test/testutil/assert
InDelta
Fix DeepEqual with kube metav1.Time
Convert some ErrorContains to assert

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-05 19:41:17 -05:00
Daniel Nephin 39c2ca57c1 Automated migration
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-05 19:41:17 -05:00
Daniel Nephin 93615dd967 Update some assertions.
and fix some tests

Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-03-05 17:15:24 -05:00
Arash Deshmeh 5d8ce59a25 fix the error message in Substitute function
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-02-26 15:29:17 -05:00
Arash Deshmeh e33bc48752 Added error message check to TestMandatoryVariableErrors test
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-02-26 15:29:17 -05:00
Daniel Nephin ce544823b6 Refactor substitute to reduce cyclo complexity
Signed-off-by: Daniel Nephin <dnephin@docker.com>
2018-02-26 15:29:17 -05:00
Arash Deshmeh 99ecf57c6c added support for mandatory variables to cli/compose
Signed-off-by: Arash Deshmeh <adeshmeh@ca.ibm.com>
2018-02-26 15:29:17 -05:00
Joffrey F 56f26d1134
Fix typo in 3.6 schema ID
Signed-off-by: Joffrey F <joffrey@docker.com>
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2018-02-21 19:55:12 +01:00
Daniel Nephin cea4d37bca
Merge pull request #824 from ethan-haynes/820-bind-mount-source-missing-error
added check for empty source in bind mount
2018-02-21 13:33:24 -05:00
Vincent Demeester cf86a4d922
Simplify the marshaling of compose types.Config
- Add `Version` to `types.Config`
- Add a new `Services` types (that is just `[]ServiceConfig`) and add
  `MarshalYAML` method on it.
- Clean other top-level custom marshaling as `Services` is the only one
  required.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-02-21 18:47:10 +01:00
Daniel Nephin 939938b976
Merge pull request #891 from vdemeester/k8s-loader-make-sure-version
Make sure we marshall version too…
2018-02-21 11:45:14 -05:00
Vincent Demeester 9f9f1c8515
Make sure we marshall version too…
… otherwise the k8s controller might fail to parse the file as it will
think it's version 1.

Signed-off-by: Vincent Demeester <vincent@sbr.pm>
2018-02-21 15:36:51 +01:00
Brian Goff 5730ef8ea0
Merge pull request #874 from dnephin/replace-go-bindata
Replace go-bindata with esc
2018-02-20 17:00:22 -05:00