compose/internal/projectloader/projectloader.go
Nicolas De Loof 6698708752 refactor(projectloader): move project loading and generation to internal/projectloader
LoadProject and Generate (the api.ProjectLoader operations) need two things
from the engine: the Docker API, to read the containers a project is
generated from, and the Docker CLI, which resolves remote Compose files.

They now live in internal/projectloader, along with the unsupported
attributes detection only the loader uses, behind a Backend interface that
composeService implements in a new file of pkg/compose, like internal/inspect.
The tests move with the code; their assertions are unchanged, only the way
the service is built differs.

The canonical container name, which both this package and internal/inspect
need, moves to a tiny internal/naming package instead of being copied a
third time. pkg/compose keeps its own copy until the shared kernel is
extracted.

Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
2026-10-13 10:03:53 +02:00

43 lines
1.4 KiB
Go

/*
Copyright 2020 Docker Compose CLI authors
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
// Package projectloader obtains a Compose project: either by loading and
// validating the Compose files (LoadProject), or by generating one from
// existing containers (Generate).
package projectloader
import (
"github.com/docker/cli/cli/command"
"github.com/moby/moby/client"
)
// Backend is what loading or generating a project needs from the engine.
type Backend interface {
// APIClient talks to the Docker daemon, to read the containers to generate a project from.
APIClient() client.APIClient
// CLI is the Docker CLI, which resolves the remote (Git, OCI) Compose files.
CLI() command.Cli
}
// Service loads and generates projects on a Backend.
type Service struct {
backend Backend
}
// New creates a Service working with the given Backend.
func New(backend Backend) *Service {
return &Service{backend: backend}
}