Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] docker compose config with --no-interpolate flag, doesn't correctly validate the file. #12292

Open
ChilloManiac opened this issue Nov 14, 2024 · 3 comments
Labels

Comments

@ChilloManiac
Copy link

ChilloManiac commented Nov 14, 2024

Description

docker compose config with --no-interpolate flag, stops validating the docker-compose file as it usually does without the flag.

Sample docker compose:

services:
  bad_service: {}

Current behaviour

Running with interpolation

$ docker compose config
service "bad_service" has neither an image nor a build context specified: invalid compose project

Running without interpolation

$ docker compose config --no-interpolation
name: env-var-compose-config
  networks:
    default:
      name: env-var-compose-config_default
services:
  bad_service:
    networks:
      default: null

Expected Behaviour

I would expect the docker compose config --no-interpolation to fail in the same way as docker compose config as the compose file has nothing to interpolate.

Compose Version

Docker Compose version v2.29.7-desktop.1

Docker Environment

Client:
 Version:    27.3.1
 Context:    desktop-linux
 Debug Mode: false
 Plugins:
  buildx: Docker Buildx (Docker Inc.)
    Version:  v0.17.1-desktop.1
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-buildx
  compose: Docker Compose (Docker Inc.)
    Version:  v2.29.7-desktop.1
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-compose
  debug: Get a shell into any image or container (Docker Inc.)
    Version:  0.0.37
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-debug
  desktop: Docker Desktop commands (Alpha) (Docker Inc.)
    Version:  v0.0.15
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-desktop
  dev: Docker Dev Environments (Docker Inc.)
    Version:  v0.1.2
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-dev
  extension: Manages Docker extensions (Docker Inc.)
    Version:  v0.2.27
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-extension
  feedback: Provide feedback, right in your terminal! (Docker Inc.)
    Version:  v1.0.5
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-feedback
  init: Creates Docker-related starter files for your project (Docker Inc.)
    Version:  v1.3.0
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-init
  sbom: View the packaged-based Software Bill Of Materials (SBOM) for an image (Anchore Inc.)
    Version:  0.6.0
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-sbom
  scout: Docker Scout (Docker Inc.)
    Version:  v1.14.0
    Path:     /Users/dkchrnor/.docker/cli-plugins/docker-scout

Server:
 Containers: 6
  Running: 3
  Paused: 0
  Stopped: 3
 Images: 11
 Server Version: 27.3.1
 Storage Driver: overlay2
  Backing Filesystem: extfs
  Supports d_type: true
  Using metacopy: false
  Native Overlay Diff: true
  userxattr: false
 Logging Driver: json-file
 Cgroup Driver: cgroupfs
 Cgroup Version: 2
 Plugins:
  Volume: local
  Network: bridge host ipvlan macvlan null overlay
  Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
 Swarm: active
  NodeID: 2myo2hofelr78iqjc7lr8ulc0
  Is Manager: true
  ClusterID: r2e2gwwh329ynglak1pxux593
  Managers: 1
  Nodes: 1
  Default Address Pool: 10.0.0.0/8  
  SubnetSize: 24
  Data Path Port: 4789
  Orchestration:
   Task History Retention Limit: 5
  Raft:
   Snapshot Interval: 10000
   Number of Old Snapshots to Retain: 0
   Heartbeat Tick: 1
   Election Tick: 10
  Dispatcher:
   Heartbeat Period: 5 seconds
  CA Configuration:
   Expiry Duration: 3 months
   Force Rotate: 0
  Autolock Managers: false
  Root Rotation In Progress: false
  Node Address: 192.168.65.3
  Manager Addresses:
   192.168.65.3:2377
 Runtimes: runc io.containerd.runc.v2
 Default Runtime: runc
 Init Binary: docker-init
 containerd version: 472731909fa34bd7bc9c087e4c27943f9835f111
 runc version: v1.1.13-0-g58aa920
 init version: de40ad0
 Security Options:
  seccomp
   Profile: unconfined
  cgroupns
 Kernel Version: 6.10.11-linuxkit
 Operating System: Docker Desktop
 OSType: linux
 Architecture: aarch64
 CPUs: 8
 Total Memory: 7.654GiB
 Name: docker-desktop
 ID: a5b7b132-3745-495f-baa7-eba6bce87834
 Docker Root Dir: /var/lib/docker
 Debug Mode: false
 HTTP Proxy: http.docker.internal:3128
 HTTPS Proxy: http.docker.internal:3128
 No Proxy: hubproxy.docker.internal
 Labels:
  com.docker.desktop.address=unix:///Users/dkchrnor/Library/Containers/com.docker.docker/Data/docker-cli.sock
 Experimental: false
 Insecure Registries:
  hubproxy.docker.internal:5555
  127.0.0.0/8
 Live Restore Enabled: false

Anything else?

No response

@ndeloof
Copy link
Contributor

ndeloof commented Nov 14, 2024

The error you got reported by docker compose config is not about compose-spec schema validation (which is ran even with --no-interpolate) but by consistency check, which takes place after yaml has been converted into internal go-struct model. There's a few such consistency checks we run at this later stage as those hardly can get introduced in json schema.

Generally speaking, you can't expect validation to be the same when running without interpolation, as some attribute are unresolved and we just can't test they are valid.

@ChilloManiac
Copy link
Author

I see, thanks for your reply.

I've taken a look around the compose-go project and i can see why consistency checks won't do.

My use-case is that we store compose files as part of a service. When we store them we'd like to validate them in some way. We used docker compose config in order to do so, but if a docker compose had declared env-vars etc, then they would not be present in the service that stores them. I see for a lot of the consistency checks there's no way to always be able to do them if there's no interpolation. But it would still be nice to check concistency for those that didn't have interpolation values. Anyway i can see why it might be too big of a task to be worth it, or be the concern of the docker compose project.

By chance, do you know any other way to validate a compose file, as i've yet to find another tool for the job.

Thanks for you time 😊

@ndeloof
Copy link
Contributor

ndeloof commented Nov 15, 2024

I'm not aware of any alternative tool for compose file validation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants